-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🔍 Show the dock icon when the browser window is open (#66)
This change toggles the application policy from 'accessory' to 'regular' whenever one or more browser windows are open. This means that whenever a window is visible, the app should appear in the application switcher (Cmd+Tab). There are also a couple of drive-by fixes, cleaning up the build script a little, and extracting the update view and model into their own files.
- Loading branch information
Showing
9 changed files
with
169 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.build | ||
.swiftpm | ||
/archives | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Reconnect -- Psion connectivity for macOS | ||
// | ||
// Copyright (C) 2024 Jason Morley | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation; either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
|
||
import SwiftUI | ||
|
||
import Sparkle | ||
|
||
// This view model class publishes when new updates can be checked by the user | ||
final class CheckForUpdatesViewModel: ObservableObject { | ||
@Published var canCheckForUpdates = false | ||
|
||
init(updater: SPUUpdater) { | ||
updater.publisher(for: \.canCheckForUpdates) | ||
.assign(to: &$canCheckForUpdates) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Reconnect -- Psion connectivity for macOS | ||
// | ||
// Copyright (C) 2024 Jason Morley | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation; either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
|
||
import SwiftUI | ||
|
||
fileprivate class DockIconManager { | ||
|
||
static var shared: DockIconManager = { | ||
return DockIconManager() | ||
}() | ||
|
||
@MainActor var activeRequests: Int = 0 { | ||
didSet { | ||
if activeRequests > 0 { | ||
NSApp.setActivationPolicy(.regular) | ||
} else { | ||
NSApp.setActivationPolicy(.accessory) | ||
} | ||
} | ||
} | ||
|
||
func requestDockIcon() async { | ||
await MainActor.run { | ||
activeRequests = activeRequests + 1 | ||
} | ||
defer { | ||
Task { @MainActor in | ||
activeRequests = activeRequests - 1 | ||
} | ||
} | ||
while !Task.isCancelled { | ||
try? await Task.sleep(for: .seconds(60*60*24)) | ||
} | ||
} | ||
|
||
} | ||
|
||
extension View { | ||
|
||
func showsDockIcon() -> some View { | ||
self | ||
.task { | ||
await DockIconManager.shared.requestDockIcon() | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Reconnect -- Psion connectivity for macOS | ||
// | ||
// Copyright (C) 2024 Jason Morley | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation; either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
|
||
import SwiftUI | ||
|
||
import Sparkle | ||
|
||
// This is the view for the Check for Updates menu item | ||
// Note this intermediate view is necessary for the disabled state on the menu item to work properly before Monterey. | ||
// See https://stackoverflow.com/questions/68553092/menu-not-updating-swiftui-bug for more info | ||
struct CheckForUpdatesView: View { | ||
@ObservedObject private var checkForUpdatesViewModel: CheckForUpdatesViewModel | ||
private let updater: SPUUpdater | ||
|
||
init(updater: SPUUpdater) { | ||
self.updater = updater | ||
|
||
// Create our view model for our CheckForUpdatesView | ||
self.checkForUpdatesViewModel = CheckForUpdatesViewModel(updater: updater) | ||
} | ||
|
||
var body: some View { | ||
Button("Check for Updates…", action: updater.checkForUpdates) | ||
.disabled(!checkForUpdatesViewModel.canCheckForUpdates) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters