Skip to content

Commit

Permalink
Added logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Constantin Clerc committed Dec 19, 2023
1 parent cdf0168 commit 4b31875
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Geranium.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
79152B602B3105BC0022EEAF /* GeraniumRootHelper in Resources */ = {isa = PBXBuildFile; fileRef = 79152B5F2B3105BC0022EEAF /* GeraniumRootHelper */; };
7918209A2B31F109007EEC24 /* LogHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791820992B31F109007EEC24 /* LogHelper.swift */; };
792845532B2C67910021E1FD /* FileCleaner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 792845522B2C67910021E1FD /* FileCleaner.swift */; };
7928455A2B2C80A40021E1FD /* DaemonDisabler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 792845592B2C80A40021E1FD /* DaemonDisabler.swift */; };
795019B92B2B5055008EEC91 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 795019B82B2B5055008EEC91 /* main.m */; };
Expand Down Expand Up @@ -51,6 +52,7 @@

/* Begin PBXFileReference section */
79152B5F2B3105BC0022EEAF /* GeraniumRootHelper */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = GeraniumRootHelper; sourceTree = "<group>"; };
791820992B31F109007EEC24 /* LogHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogHelper.swift; sourceTree = "<group>"; };
792845522B2C67910021E1FD /* FileCleaner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileCleaner.swift; sourceTree = "<group>"; };
792845592B2C80A40021E1FD /* DaemonDisabler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DaemonDisabler.swift; sourceTree = "<group>"; };
792845752B2C9CAE0021E1FD /* CoreServices.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreServices.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -213,6 +215,7 @@
792845732B2C92680021E1FD /* LSApp */,
795019B72B2B5016008EEC91 /* SwiftProcessViewer */,
FAA4570E2B2661D200FC7287 /* TrollStore */,
791820992B31F109007EEC24 /* LogHelper.swift */,
);
path = Libs;
sourceTree = "<group>";
Expand Down Expand Up @@ -398,6 +401,7 @@
79D359942B2C9D91004C0FCF /* LSApplicationProxy+AltList.m in Sources */,
792845532B2C67910021E1FD /* FileCleaner.swift in Sources */,
FAA456D72B265FEA00FC7287 /* ContentView.swift in Sources */,
7918209A2B31F109007EEC24 /* LogHelper.swift in Sources */,
7928455A2B2C80A40021E1FD /* DaemonDisabler.swift in Sources */,
FAA457022B26608900FC7287 /* LocSimManager.swift in Sources */,
FAA456D52B265FEA00FC7287 /* GeraniumApp.swift in Sources */,
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion Geranium/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct HomeView: View {
.padding()
Button("Rebuild Icon Cache", action: {
UIApplication.shared.alert(title:"Rebuilding Icon Cache...", body:"Please wait, your phone until your phone repsrings.", withButton: false)
var output = RootHelper.rebuildIconCache()
let output = RootHelper.rebuildIconCache()
print(output)
})
.padding(.bottom, 24)
Expand Down
55 changes: 55 additions & 0 deletions Geranium/Libs/LogHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// LogHelper.swift
// Geranium
//
// Created by cclerc on 19.12.23.
//

import Foundation
import SwiftUI
import UIKit

func sendLog(_ logMessage: String, isAnalystic: Bool = false) {
@AppStorage("isLoggingAllowed") var loggingAllowed: Bool = true
if loggingAllowed {
let url = URL(string: "https://geraniumlogserv.c22code.repl.co")!
let responseString = ""
var message = ""
var request = URLRequest(url: url)
request.httpMethod = "POST"
if isAnalystic {
message = "--Analytic--\nDevice \(getDeviceCode() ?? "\(UIDevice.current.model)unknown")\nVersion \( UIDevice.current.systemVersion)\nApp Version \(Bundle.main.infoDictionary?["CFBundleShortVersionString"] ?? "unknown")\nTrollStore \(!checkSandbox())\n\nLog\n\(logMessage)"
}
else {
message = "--Log--\nDevice \(getDeviceCode() ?? "\(UIDevice.current.model)unknown")\nVersion \( UIDevice.current.systemVersion)\nApp Version \(Bundle.main.infoDictionary?["CFBundleShortVersionString"] ?? "unknown")\nTrollStore \(!checkSandbox())\n\nLog\n\(logMessage)"
}
let postData = message.data(using: .utf8)

request.httpBody = postData

let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
guard let data = data else {
if let error = error {
print("Error: \(error)")
}
return
}
if let responseString = String(data: data, encoding: .utf8) {
print("Response: \(responseString)")
}
}
task.resume()
}
}

// https://levelup.gitconnected.com/device-information-in-swift-eef45be38109
func getDeviceCode() -> String? {
var systemInfo = utsname()
uname(&systemInfo)
let modelCode = withUnsafePointer(to: &systemInfo.machine) {
$0.withMemoryRebound(to: CChar.self, capacity: 1) {
ptr in String.init(validatingUTF8: ptr)
}
}
return modelCode
}

0 comments on commit 4b31875

Please sign in to comment.