mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added an error window when the update failed
This commit is contained in:
@@ -1372,3 +1372,14 @@ public func iconFromSymbol(name: String, scale: NSImage.SymbolScale) -> NSImage?
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
public func showAlert(_ message: String, _ information: String? = nil, _ style: NSAlert.Style = .informational) {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = message
|
||||
if let information = information {
|
||||
alert.informativeText = information
|
||||
}
|
||||
alert.addButton(withTitle: "OK")
|
||||
alert.alertStyle = style
|
||||
alert.runModal()
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public class Updater {
|
||||
downloadTask.resume()
|
||||
}
|
||||
|
||||
public func install(path: String) {
|
||||
public func install(path: String, completion: @escaping (_ error: String?) -> Void) {
|
||||
let pwd = Bundle.main.bundleURL.absoluteString
|
||||
.replacingOccurrences(of: "file://", with: "")
|
||||
.replacingOccurrences(of: "Stats.app", with: "")
|
||||
@@ -173,13 +173,13 @@ public class Updater {
|
||||
let dmg = path.replacingOccurrences(of: "file://", with: "")
|
||||
|
||||
if !FileManager.default.isWritableFile(atPath: pwd) {
|
||||
print("has no write permission on \(pwd)")
|
||||
completion("has no write permission on \(pwd)")
|
||||
return
|
||||
}
|
||||
|
||||
let diff = (Int(Date().timeIntervalSince1970) - self.lastInstallTS) / 60
|
||||
if diff <= 3 {
|
||||
print("last install was \(diff) minutes ago, stopping...")
|
||||
completion("last install was \(diff) minutes ago, stopping...")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
||||
debug("Downloading new version of app...")
|
||||
if let url = URL(string: uri) {
|
||||
updater.download(url, completion: { path in
|
||||
updater.install(path: path)
|
||||
updater.install(path: path) { error in
|
||||
if let error {
|
||||
showAlert("Error update Stats", error, .critical)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,6 +284,10 @@ private class UpdateView: NSView {
|
||||
}
|
||||
|
||||
@objc private func install(_ sender: Any) {
|
||||
updater.install(path: self.path)
|
||||
updater.install(path: self.path) { error in
|
||||
if let error {
|
||||
showAlert("Error update Stats", error, .critical)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,11 @@ extension AppDelegate {
|
||||
if silent {
|
||||
if let url = URL(string: version.url) {
|
||||
updater.download(url, completion: { path in
|
||||
updater.install(path: path)
|
||||
updater.install(path: path) { error in
|
||||
if let error {
|
||||
showAlert("Error update Stats", error, .critical)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user