Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Sync Update - 173295d
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakr233 committed Mar 11, 2022
1 parent 0937e0a commit 464e37a
Show file tree
Hide file tree
Showing 49 changed files with 840 additions and 562 deletions.
6 changes: 3 additions & 3 deletions App.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions Application/Rayon/Extension/Store/RayonStore+SwiftUI.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Application/Rayon/Extension/UIBridge/PresentError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension UIBridge {
}
}

static func presentError(with message: String, delay: Double = 0.5) {
static func presentError(with message: String, delay: Double = 0) {
debugPrint("<InterfaceError> \(message)")
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
let alert = NSAlert()
Expand Down
70 changes: 67 additions & 3 deletions Application/Rayon/Extension/Utils/Generic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import RayonModule
import SwiftUI

enum RayonUtil {
static func findWindow() -> NSWindow? {
if let key = NSApp.keyWindow {
return key
}
for window in NSApp.windows where window.isVisible {
return window
}
return nil
}

static func selectIdentity() -> RDIdentity.ID? {
assert(!Thread.isMainThread, "select identity must be called from background thread")

Expand All @@ -20,10 +30,17 @@ enum RayonUtil {

mainActor {
var panelRef: NSPanel?
var windowRef: NSWindow?
let controller = NSHostingController(rootView: Group {
IdentityPickerSheetView {
selection = $0
if let panel = panelRef { panel.close() }
if let panel = panelRef {
if let windowRef = windowRef {
windowRef.endSheet(panel)
} else {
panel.close()
}
}
sem.signal()
}
.environmentObject(RayonStore.shared)
Expand All @@ -34,13 +51,60 @@ enum RayonUtil {
panel.title = ""
panel.titleVisibility = .hidden

if let keyWindow = NSApp.keyWindow {
if let keyWindow = findWindow() {
windowRef = keyWindow
keyWindow.beginSheet(panel) { _ in }
} else {
sem.signal()
}
}
sem.wait()
return selection
}

static func selectMachine(allowMany: Bool = true) -> [RDMachine.ID] {
assert(!Thread.isMainThread, "select identity must be called from background thread")

var selection = [RDMachine.ID]()
let sem = DispatchSemaphore(value: 0)

debugPrint("Picking Machine")

mainActor {
var panelRef: NSPanel?
var windowRef: NSWindow?
let controller = NSHostingController(rootView: Group {
MachinePickerView(onComplete: {
selection = $0
if let panel = panelRef {
if let windowRef = windowRef {
windowRef.endSheet(panel)
} else {
panel.close()
}
}
sem.signal()
}, allowSelectMany: allowMany)
.environmentObject(RayonStore.shared)
.frame(width: 700, height: 400)
})
let panel = NSPanel(contentViewController: controller)
panelRef = panel
panel.title = ""
panel.titleVisibility = .hidden

if let keyWindow = findWindow() {
windowRef = keyWindow
keyWindow.beginSheet(panel) { _ in }
} else {
panel.makeKeyAndOrderFront(nil)
sem.signal()
}
}
sem.wait()
return selection
}

static func selectOneMachine() -> RDMachine.ID? {
selectMachine(allowMany: false).first
}
}
55 changes: 0 additions & 55 deletions Application/Rayon/Extension/Window/CreateWindow.swift

This file was deleted.

71 changes: 0 additions & 71 deletions Application/Rayon/Extension/Window/HostWindow.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ private var isBootstrapCompleted = false
struct MainView: View {
@EnvironmentObject var store: RayonStore

@StateObject
var windowObserver: WindowObserver = .init()

@State var openLicenseAgreementView: Bool = false

var body: some View {
Expand Down Expand Up @@ -45,33 +42,6 @@ struct MainView: View {
.ignoresSafeArea()
.animation(.easeInOut(duration: 0.5), value: store.globalProgressInPresent)
)
.background(
HostingWindowFinder { [weak windowObserver] window in
windowObserver?.window = window
guard let window = window else {
return
}
guard !isBootstrapCompleted else {
return
}
isBootstrapCompleted = true

window.tabbingMode = .disallowed
let windows = NSApplication
.shared
.windows
var notKeyWindow = windows
.filter { !$0.isKeyWindow }
if notKeyWindow.count > 0,
notKeyWindow.count == windows.count
{
// don't close them all
notKeyWindow.removeFirst()
}
notKeyWindow.forEach { $0.close() }
window.tabbingMode = .automatic
}
)
.toolbar {
ToolbarItem(placement: .navigation) {
Button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ struct SidebarView: View {
}
.sheet(isPresented: $openServerSelector, onDismiss: nil, content: {
MachinePickerView(onComplete: { machines in
if machines.isEmpty { return }
for machine in machines {
terminalManager.createSession(withMachineID: machine)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ struct IdentityPickerSheetView: View {
defer {
presentationMode.wrappedValue.dismiss()
}
if !confirmed {
if confirmed {
onComplete(currentSelection)
} else {
onComplete(nil)
return
}
onComplete(currentSelection)
}
.sheet(isPresented: $openCreateSheet, onDismiss: nil) {
EditIdentityManager(selection: .constant(nil)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ struct MachinePickerView: View {
) { confirmed in
var shouldDismiss = false
defer { if shouldDismiss { presentationMode.wrappedValue.dismiss() } }
if !confirmed {
shouldDismiss = true
return
if confirmed {
onComplete([RDIdentity.ID](currentSelection))
} else {
onComplete([])
}
onComplete([RDIdentity.ID](currentSelection))
shouldDismiss = true
}
}
Expand Down Expand Up @@ -65,6 +65,7 @@ struct MachinePickerView: View {
}
}
}
.frame(maxHeight: 500)
.requiresSheetFrame()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct MachineView: View {

@State var openEditSheet: Bool = false

let redactedColor: Color = .green
let redactedColor: Color = .accentColor

var body: some View {
contentView
Expand Down
Loading

0 comments on commit 464e37a

Please sign in to comment.