mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-04-18 05:22:11 +00:00
Relaunch
This commit is contained in:
parent
a3ed59a78c
commit
049194f5d2
@ -28,21 +28,16 @@ struct Secretive: App {
|
|||||||
.onAppear {
|
.onAppear {
|
||||||
if !hasRunSetup {
|
if !hasRunSetup {
|
||||||
showingSetup = true
|
showingSetup = true
|
||||||
} else {
|
|
||||||
if agentStatusChecker.running && justUpdatedChecker.justUpdated {
|
|
||||||
// Relaunch the agent, since it'll be running from earlier update still
|
|
||||||
_ = LaunchAgentController().install()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onReceive(NotificationCenter.default.publisher(for: NSApplication.willBecomeActiveNotification)) { _ in
|
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
|
||||||
|
guard hasRunSetup else { return }
|
||||||
agentStatusChecker.check()
|
agentStatusChecker.check()
|
||||||
if hasRunSetup && !agentStatusChecker.running {
|
if agentStatusChecker.running && justUpdatedChecker.justUpdated {
|
||||||
// We've run setup, we didn't just update, launchd is just not doing it's thing.
|
// Relaunch the agent, since it'll be running from earlier update still
|
||||||
// Force a launch directly.
|
reinstallAgent()
|
||||||
LaunchAgentController().forceLaunch { _ in
|
} else if !agentStatusChecker.running {
|
||||||
agentStatusChecker.check()
|
forceLaunchAgent()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,6 +64,31 @@ struct Secretive: App {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Secretive {
|
||||||
|
|
||||||
|
private func reinstallAgent() {
|
||||||
|
justUpdatedChecker.check()
|
||||||
|
LaunchAgentController().install {
|
||||||
|
// Wait a second for launchd to kick in (next runloop isn't enough).
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||||
|
agentStatusChecker.check()
|
||||||
|
if !agentStatusChecker.running {
|
||||||
|
forceLaunchAgent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func forceLaunchAgent() {
|
||||||
|
// We've run setup, we didn't just update, launchd is just not doing it's thing.
|
||||||
|
// Force a launch directly.
|
||||||
|
LaunchAgentController().forceLaunch { _ in
|
||||||
|
agentStatusChecker.check()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private enum Constants {
|
private enum Constants {
|
||||||
static let helpURL = URL(string: "https://github.com/maxgoedjen/secretive/blob/main/FAQ.md")!
|
static let helpURL = URL(string: "https://github.com/maxgoedjen/secretive/blob/main/FAQ.md")!
|
||||||
|
@ -18,9 +18,7 @@ class JustUpdatedChecker: ObservableObject, JustUpdatedCheckerProtocol {
|
|||||||
let lastBuild = UserDefaults.standard.object(forKey: Constants.previousVersionUserDefaultsKey) as? String ?? "None"
|
let lastBuild = UserDefaults.standard.object(forKey: Constants.previousVersionUserDefaultsKey) as? String ?? "None"
|
||||||
let currentBuild = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
|
let currentBuild = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
|
||||||
UserDefaults.standard.set(currentBuild, forKey: Constants.previousVersionUserDefaultsKey)
|
UserDefaults.standard.set(currentBuild, forKey: Constants.previousVersionUserDefaultsKey)
|
||||||
if lastBuild != currentBuild {
|
justUpdated = lastBuild != currentBuild
|
||||||
justUpdated = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,10 +5,17 @@ import OSLog
|
|||||||
|
|
||||||
struct LaunchAgentController {
|
struct LaunchAgentController {
|
||||||
|
|
||||||
func install() -> Bool {
|
func install(completion: (() -> Void)? = nil) {
|
||||||
Logger().debug("Installing agent")
|
Logger().debug("Installing agent")
|
||||||
_ = setEnabled(false)
|
_ = setEnabled(false)
|
||||||
return setEnabled(true)
|
// This is definitely a bit of a "seems to work better" thing but:
|
||||||
|
// Seems to more reliably hit if these are on separate runloops, otherwise it seems like it sometimes doesn't kill old
|
||||||
|
// and start new?
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||||
|
_ = setEnabled(true)
|
||||||
|
completion?()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func forceLaunch(completion: ((Bool) -> Void)?) {
|
func forceLaunch(completion: ((Bool) -> Void)?) {
|
||||||
|
@ -157,7 +157,7 @@ struct SecretAgentSetupView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func install() {
|
func install() {
|
||||||
_ = LaunchAgentController().install()
|
LaunchAgentController().install()
|
||||||
buttonAction()
|
buttonAction()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user