diff --git a/Kit/types.swift b/Kit/types.swift index bc29ab59..1a05bb1d 100644 --- a/Kit/types.swift +++ b/Kit/types.swift @@ -27,6 +27,7 @@ public struct ColorValue: Equatable { } public enum AppUpdateInterval: String { + case silent = "Silent" case atStart = "At start" case separator1 = "separator_1" case oncePerDay = "Once per day" @@ -36,6 +37,7 @@ public enum AppUpdateInterval: String { case never = "Never" } public let AppUpdateIntervals: [KeyValue_t] = [ + KeyValue_t(key: "Silent", value: AppUpdateInterval.silent.rawValue), KeyValue_t(key: "At start", value: AppUpdateInterval.atStart.rawValue), KeyValue_t(key: "separator_1", value: "separator_1"), KeyValue_t(key: "Once per day", value: AppUpdateInterval.oncePerDay.rawValue), diff --git a/Modules/Net/settings.swift b/Modules/Net/settings.swift index 3081ff5f..ea257469 100644 --- a/Modules/Net/settings.swift +++ b/Modules/Net/settings.swift @@ -79,7 +79,7 @@ internal class Settings: NSStackView, Settings_v { self.addArrangedSubview(selectSettingsRow( title: localizedString("Reset data usage"), action: #selector(toggleUsageReset), - items: AppUpdateIntervals.dropLast(2), + items: AppUpdateIntervals.dropLast(2).filter({ $0.key != "Silent" }), selected: self.usageReset )) diff --git a/Stats/Views/AppSettings.swift b/Stats/Views/AppSettings.swift index 488ee72a..35a9129e 100644 --- a/Stats/Views/AppSettings.swift +++ b/Stats/Views/AppSettings.swift @@ -15,7 +15,7 @@ import Kit class ApplicationSettings: NSScrollView { private var updateIntervalValue: String { get { - return Store.shared.string(key: "update-interval", defaultValue: AppUpdateInterval.atStart.rawValue) + return Store.shared.string(key: "update-interval", defaultValue: AppUpdateInterval.silent.rawValue) } } diff --git a/Stats/helpers.swift b/Stats/helpers.swift index 49b3c936..5b16979b 100644 --- a/Stats/helpers.swift +++ b/Stats/helpers.swift @@ -101,7 +101,7 @@ extension AppDelegate { NSApp.setActivationPolicy(dockIconStatus) } - if let updateInterval = AppUpdateInterval(rawValue: Store.shared.string(key: "update-interval", defaultValue: AppUpdateInterval.atStart.rawValue)) { + if let updateInterval = AppUpdateInterval(rawValue: Store.shared.string(key: "update-interval", defaultValue: AppUpdateInterval.silent.rawValue)) { self.updateActivity.invalidate() self.updateActivity.repeats = true @@ -114,6 +114,9 @@ extension AppDelegate { case .atStart: self.checkForNewVersion() return + case .silent: + self.checkForNewVersion(silent: true) + return default: return } @@ -124,7 +127,7 @@ extension AppDelegate { } } - internal func checkForNewVersion() { + internal func checkForNewVersion(silent: Bool = false) { updater.check { result, error in if error != nil { debug("error updater.check(): \(error!.localizedDescription)") @@ -140,6 +143,15 @@ extension AppDelegate { return } + if silent { + if let url = URL(string: version.url) { + updater.download(url, doneHandler: { path in + updater.install(path: path) + }) + } + return + } + debug("show update view because new version of app found: \(version.latest)") if #available(OSX 10.14, *) {