feat: removed sharing the anonymous stats with the server

feat: removed checking the app signature via server
This commit is contained in:
Serhiy Mytrovtsiy
2022-02-28 17:17:17 +01:00
parent e99ef2cfa7
commit 916d157ad6
5 changed files with 2 additions and 120 deletions

View File

@@ -1,102 +0,0 @@
//
// Server.swift
// Kit
//
// Created by Serhiy Mytrovtsiy on 04/07/2021.
// Using Swift 5.0.
// Running on macOS 10.15.
//
// Copyright © 2021 Serhiy Mytrovtsiy. All rights reserved.
//
import Foundation
struct event: Codable {
var ID: String
var version: String
var build: String
var modules: [String]
var device: String
var os: String
var language: String
var omit: Bool
}
public class Server {
public static let shared = Server(url: URL(string: "https://api.serhiy.io/v1/stats")!)
public var ID: String {
get {
return Store.shared.string(key: "id", defaultValue: UUID().uuidString)
}
}
private let url: URL
public init(url: URL) {
self.url = url
if !Store.shared.exist(key: "id") {
Store.shared.set(key: "id", value: self.ID)
}
}
public func sendEvent(modules: [String], omit: Bool = false) {
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String
let systemVersion = ProcessInfo().operatingSystemVersion
let e = event(
ID: self.ID,
version: version ?? "unknown",
build: build ?? "unknown",
modules: modules,
device: SystemKit.shared.modelName() ?? "unknown",
os: systemVersion.getFullVersion(),
language: Locale.current.languageCode ?? "unknown",
omit: omit
)
var request = URLRequest(url: self.url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
do {
request.httpBody = try JSONEncoder().encode(e)
} catch let err {
error("failed to encode json: \(err)")
}
let task = URLSession.shared.dataTask(with: request) { (_, _, err) in
if err != nil {
error("send report \(String(describing: err))")
}
}
task.resume()
}
public func getTeamID(completionHandler: @escaping (_ result: String?, _ error: Error?) -> Void) {
guard let url = URL(string: "\(self.url)/team-id") else {
completionHandler(nil, "prepare url")
return
}
var request = URLRequest(url: url)
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { (data, _, err) in
guard let data = data, err == nil else {
completionHandler(nil, "no data or error \(String(describing: err))")
return
}
let str = String(decoding: data, as: UTF8.self)
if str == "fatal" {
fatalError("have a good day")
}
completionHandler(str, nil)
}
task.resume()
}
}

View File

@@ -47,12 +47,6 @@ public class Updater {
public init(github: String, url: String) {
self.github = URL(string: "https://api.github.com/repos/\(github)/releases/latest")!
self.server = URL(string: url)!
Server.shared.getTeamID { (val, err) in
if let teamID = val, err == nil {
self.teamID = teamID
}
}
}
deinit {
@@ -65,9 +59,9 @@ public class Updater {
return
}
self.fetchRelease(uri: self.github) { (result, err) in
self.fetchRelease(uri: self.server) { (result, err) in
guard let result = result, err == nil else {
self.fetchRelease(uri: self.server) { (result, err) in
self.fetchRelease(uri: self.github) { (result, err) in
guard let result = result, err == nil else {
completion(nil, err)
return

View File

@@ -76,7 +76,6 @@
9A81C75E2449A41400825D92 /* RAM.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9A81C7562449A41400825D92 /* RAM.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9A81C7692449A43600825D92 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A81C7672449A43600825D92 /* main.swift */; };
9A81C76A2449A43600825D92 /* readers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A81C7682449A43600825D92 /* readers.swift */; };
9A8AE0A326921A2A00B13054 /* Server.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A8AE0A226921A2A00B13054 /* Server.swift */; };
9A8B923D2696445C00FD6D83 /* settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A8B923C2696445C00FD6D83 /* settings.swift */; };
9A90E19024EAD2BB00471E9A /* GPU.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A90E18924EAD2BB00471E9A /* GPU.framework */; };
9A90E19124EAD2BB00471E9A /* GPU.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9A90E18924EAD2BB00471E9A /* GPU.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -382,7 +381,6 @@
9A81C7592449A41400825D92 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9A81C7672449A43600825D92 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
9A81C7682449A43600825D92 /* readers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = readers.swift; sourceTree = "<group>"; };
9A8AE0A226921A2A00B13054 /* Server.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Server.swift; sourceTree = "<group>"; };
9A8B923C2696445C00FD6D83 /* settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = settings.swift; sourceTree = "<group>"; };
9A90E18924EAD2BB00471E9A /* GPU.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GPU.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9A90E18C24EAD2BB00471E9A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -773,7 +771,6 @@
9A2848032666AB2F00EC1F6D /* SystemKit.swift */,
9A2848072666AB3000EC1F6D /* Updater.swift */,
9A6EEBBD2685259500897371 /* Logger.swift */,
9A8AE0A226921A2A00B13054 /* Server.swift */,
9A5A8446271895B700BC40A4 /* Reachability.swift */,
);
path = plugins;
@@ -1440,7 +1437,6 @@
9A2847622666AA2700EC1F6D /* Label.swift in Sources */,
9A28477C2666AA5000EC1F6D /* reader.swift in Sources */,
9A9B8C9D27149A3700218374 /* Tachometer.swift in Sources */,
9A8AE0A326921A2A00B13054 /* Server.swift in Sources */,
9A2847652666AA2700EC1F6D /* Memory.swift in Sources */,
9A2847642666AA2700EC1F6D /* Battery.swift in Sources */,
9A28480B2666AB3000EC1F6D /* Charts.swift in Sources */,

View File

@@ -58,11 +58,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
self.defaultValues()
info("Stats started in \((startingPoint.timeIntervalSinceNow * -1).rounded(toPlaces: 4)) seconds")
Server.shared.sendEvent(
modules: modules.filter({ $0.enabled != false && $0.available != false }).map({ $0.config.name }),
omit: CommandLine.arguments.contains("--omit")
)
}
func applicationWillTerminate(_ aNotification: Notification) {

View File

@@ -96,7 +96,6 @@ class ApplicationSettings: NSScrollView {
statsName.font = NSFont.systemFont(ofSize: 20, weight: .regular)
statsName.stringValue = "Stats"
statsName.isSelectable = true
statsName.toolTip = Server.shared.ID
let versionNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
let buildNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String