Skip to content

Commit

Permalink
added some missing pieces for macos screenshare
Browse files Browse the repository at this point in the history
  • Loading branch information
maxxfrazer committed Nov 21, 2023
1 parent e78b564 commit 8887cc8
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 3 deletions.
106 changes: 103 additions & 3 deletions product-workflow/ScreenShareAndVolumeView+macOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import AgoraRtcKit
import CoreGraphics
import SwiftUI

#if os(macOS)
extension ScreenShareVolumeManager {
Expand Down Expand Up @@ -90,9 +91,6 @@ extension ScreenShareAndVolumeView {
self.showPopup = true
}

@State private var popupWidth: CGFloat = 0
@State private var popupHeight: CGFloat = 0

func startScreenshare(with source: AgoraScreenCaptureSourceInfo) {
self.screenSharingActive = true
self.agoraManager.startScreenShare(with: source.sourceId, isDisplay: source.sourceName.contains("Screens"))
Expand All @@ -102,4 +100,106 @@ extension ScreenShareAndVolumeView {
self.agoraManager.stopScreenShare()
}
}

struct ScreenShareModal: View {

@Binding var displayed: Bool
@State var screens: [String: [AgoraScreenCaptureSourceInfo]]
@State var selectedScreen: AgoraScreenCaptureSourceInfo?
@State var selectedGroup: String = ""
var startScreenShare: (AgoraScreenCaptureSourceInfo) -> Void
var body: some View {
VStack {
ScrollView(.horizontal) {
LazyHGrid(rows: [GridItem(.flexible())]) {
ForEach(
screens.keys.sorted(), id: \.self
) { name in
if let screenSources = screens[name] {
ScreenGroupButton(
selectedScreen: $selectedScreen,
screenSources: screenSources,
groupName: name,
selectedGroup: $selectedGroup
)
}
}
}.padding()
}.frame(height: 75)
if let selectedScreens = screens[selectedGroup] {
ScrollView {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 100))]) {
ForEach(selectedScreens, id: \.sourceId) { screen in
Button(action: {
self.selectedScreen = screen
}, label: {
Image(nsImage: screen.thumbImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 90, height: 90) // Adjust size as needed
}).background(
selectedScreen?.sourceId == screen.sourceId ?
Color.green : Color.secondary
)
}
}.padding()
}
} else {
Spacer()
}
Button(action: {
guard let selectedScreen else { return }
self.displayed = false
self.startScreenShare(selectedScreen)
}, label: {
Text("Start Screenshare")
}).disabled(selectedScreen == nil).padding()

}.onAppear {
self.selectedGroup = screens.keys.sorted().first ?? ""
}
}
}

struct ScreenGroupButton: View {
@Binding var selectedScreen: AgoraScreenCaptureSourceInfo?
@State var screenSources: [AgoraScreenCaptureSourceInfo]
@State var groupName: String
@Binding var selectedGroup: String
var body: some View {
Button(action: {
selectedScreen = nil
selectedGroup = groupName
}, label: {
VStack {
if let firstScreen = screenSources.first,
let appIcon = firstScreen.iconImage {
Image(nsImage: appIcon)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 25, height: 25)
} else {
Image(systemName: "rectangle.on.rectangle.angled")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 25, height: 25)
}
Text(groupName.replacingOccurrences(of: "00", with: ""))
}.buttonStyle(NoHighlightButtonStyle())
.foregroundStyle(
selectedGroup == groupName ?
Color.green : Color.secondary
).padding(3)
})

}
}

struct NoHighlightButtonStyle: PrimitiveButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.focusable(false)
}
}

#endif
3 changes: 3 additions & 0 deletions product-workflow/ScreenShareAndVolumeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ struct ScreenShareAndVolumeView: View {
@State var selectedScreenName: String = ""
@State var selectedScreen: CGWindowID?
@State var screenSharingActive = false

@State internal var popupWidth: CGFloat = 0
@State internal var popupHeight: CGFloat = 0
#endif

var body: some View {
Expand Down

0 comments on commit 8887cc8

Please sign in to comment.