mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
fix: reverted 3753ca92cd
This code makes app unuseful for users who ddos the server from what Stats takes the information about new version. So more useful from my side is to not have this code.
This commit is contained in:
@@ -43,23 +43,6 @@ public class Updater {
|
||||
|
||||
private var observation: NSKeyValueObservation?
|
||||
|
||||
private var lastCheckTS: Int {
|
||||
get {
|
||||
return Store.shared.int(key: "updater_check_ts", defaultValue: -1)
|
||||
}
|
||||
set {
|
||||
Store.shared.set(key: "updater_check_ts", value: newValue)
|
||||
}
|
||||
}
|
||||
private var lastInstallTS: Int {
|
||||
get {
|
||||
return Store.shared.int(key: "updater_install_ts", defaultValue: -1)
|
||||
}
|
||||
set {
|
||||
Store.shared.set(key: "updater_install_ts", value: newValue)
|
||||
}
|
||||
}
|
||||
|
||||
public init(github: String, url: String) {
|
||||
self.github = URL(string: "https://api.github.com/repos/\(github)/releases/latest")!
|
||||
self.server = URL(string: url)!
|
||||
@@ -69,22 +52,12 @@ public class Updater {
|
||||
observation?.invalidate()
|
||||
}
|
||||
|
||||
public func check(force: Bool = false, completion: @escaping (_ result: version_s?, _ error: Error?) -> Void) {
|
||||
let diff = (Int(Date().timeIntervalSince1970) - self.lastCheckTS) / 60
|
||||
if !force && diff <= 10 {
|
||||
completion(nil, "last check was \(diff) minutes ago, stopping...")
|
||||
return
|
||||
}
|
||||
|
||||
public func check(completion: @escaping (_ result: version_s?, _ error: Error?) -> Void) {
|
||||
if !isConnectedToNetwork() {
|
||||
completion(nil, "No internet connection")
|
||||
return
|
||||
}
|
||||
|
||||
defer {
|
||||
self.lastCheckTS = Int(Date().timeIntervalSince1970)
|
||||
}
|
||||
|
||||
self.fetchRelease(uri: self.server) { (result, err) in
|
||||
guard let result = result, err == nil else {
|
||||
self.fetchRelease(uri: self.github) { (result, err) in
|
||||
@@ -166,16 +139,6 @@ public class Updater {
|
||||
}
|
||||
|
||||
public func install(path: String) {
|
||||
let diff = (Int(Date().timeIntervalSince1970) - self.lastInstallTS) / 60
|
||||
if diff <= 3 {
|
||||
print("last install was \(diff) minutes ago, stopping...")
|
||||
return
|
||||
}
|
||||
|
||||
defer {
|
||||
self.lastInstallTS = Int(Date().timeIntervalSince1970)
|
||||
}
|
||||
|
||||
print("Started new version installation...")
|
||||
|
||||
_ = syncShell("mkdir /tmp/Stats") // make sure that directory exist
|
||||
|
||||
@@ -203,7 +203,7 @@ class ApplicationSettings: NSStackView {
|
||||
// MARK: - actions
|
||||
|
||||
@objc func updateAction(_ sender: NSObject) {
|
||||
updater.check(force: true, completion: { result, error in
|
||||
updater.check(completion: { result, error in
|
||||
if error != nil {
|
||||
debug("error updater.check(): \(error!.localizedDescription)")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user