mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added silent app update option (default from now)
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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
|
||||
))
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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, *) {
|
||||
|
||||
Reference in New Issue
Block a user