Skip to content

Commit 914b509

Browse files
committed
Launch window from tray menu
1 parent 1b2ed12 commit 914b509

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

SupportCompanion/AppDelegate.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
2424
private var cancellables: Set<AnyCancellable> = []
2525
@AppStorage("isDarkMode") private var isDarkMode: Bool = false
2626

27-
2827
func application(_ application: NSApplication, open urls: [URL]) {
2928
guard let url = urls.first else { return }
3029
switch url.host?.lowercased() {
@@ -62,6 +61,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
6261
.environmentObject(AppStateManager.shared)
6362
)
6463
configureAppUpdateNotificationCommand(mode: appStateManager.preferences.mode)
64+
65+
appStateManager.showWindowCallback = { [weak self] in
66+
self?.showWindow()
67+
}
6568

6669
if appStateManager.preferences.showDesktopInfo {
6770
// Initialize transparent window
@@ -161,20 +164,20 @@ class AppDelegate: NSObject, NSApplicationDelegate {
161164
}
162165
}
163166

164-
@objc private func showWindow() {
167+
@objc func showWindow() {
165168
if windowController == nil {
166169
NSApp.setActivationPolicy(.regular)
167170
let contentView = ContentView()
168171
.environmentObject(AppStateManager.shared)
169172
.environmentObject(Preferences())
170-
.frame(minWidth: 1500, minHeight: 900)
173+
.frame(minWidth: 1500, minHeight: 950)
171174

172175
let hostingController = NSHostingController(rootView: contentView)
173176

174177
let window = NSWindow(contentViewController: hostingController)
175-
window.setContentSize(NSSize(width: 1500, height: 900))
178+
window.setContentSize(NSSize(width: 1500, height: 950))
176179
window.styleMask = [.titled, .closable, .resizable]
177-
window.minSize = NSSize(width: 1500, height: 900)
180+
window.minSize = NSSize(width: 1500, height: 950)
178181
window.title = ""
179182
window.isReleasedWhenClosed = false
180183
window.backgroundColor = .clear

SupportCompanion/ViewModels/AppStateManager.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class AppStateManager: ObservableObject {
3838
@Published var catalogs: [String] = []
3939

4040
private var cancellables = Set<AnyCancellable>()
41-
41+
var showWindowCallback: (() -> Void)?
42+
4243
func startBackgroundTasks() {
4344
if preferences.mode == Constants.modes.munki {
4445
pendingMunkiUpdatesManager.startUpdateCheckTimer()

SupportCompanion/Views/TrayMenu.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ struct ButtonSection: View {
137137
var body: some View {
138138
let visibleButtons = [
139139
ScButton(Constants.TrayMenu.openApp, fontSize: 12, action: {
140-
Task {
141-
_ = try await ExecutionService.executeShellCommand("open \(url)home")
140+
DispatchQueue.main.async {
141+
appState.showWindowCallback?()
142142
}
143143
}),
144144
viewModel.isButtonVisible("ChangePassword") ? viewModel.createChangePasswordButton(fontSize: 12) : nil,

0 commit comments

Comments
 (0)