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:
Serhiy Mytrovtsiy
2022-06-07 17:08:10 +02:00
parent 72f616cdf6
commit f8c9eb987d
2 changed files with 2 additions and 39 deletions

View File

@@ -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

View File

@@ -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