Skip to content

Commit ef81bb0

Browse files
2.0
1 parent 20ff850 commit ef81bb0

26 files changed

+904
-498
lines changed

TrollTools.xcodeproj/project.pbxproj

Lines changed: 160 additions & 33 deletions
Large diffs are not rendered by default.

TrollTools.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TrollTools.xcodeproj/xcuserdata/exerhythm.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@
44
<dict>
55
<key>SchemeUserState</key>
66
<dict>
7+
<key>RootHelper.xcscheme_^#shared#^_</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>2</integer>
11+
</dict>
712
<key>TrollTools.xcscheme_^#shared#^_</key>
813
<dict>
914
<key>orderHint</key>
10-
<integer>0</integer>
15+
<integer>1</integer>
16+
</dict>
17+
</dict>
18+
<key>SuppressBuildableAutocreation</key>
19+
<dict>
20+
<key>CE2BF7B62902DFF300AD10BE</key>
21+
<dict>
22+
<key>primary</key>
23+
<true/>
1124
</dict>
1225
</dict>
1326
</dict>

TrollTools/Info.plist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>TSRootBinaries</key>
6+
<array>
7+
<string>trolltoolsroothelper</string>
8+
</array>
9+
</dict>
10+
</plist>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// TrollToolsApp.swift
3+
// TrollTools
4+
//
5+
// Created by exerhythm on 21.10.2022.
6+
//
7+
8+
import SwiftUI
9+
10+
@main
11+
struct TrollToolsApp: App {
12+
var body: some Scene {
13+
WindowGroup {
14+
RootView()
15+
.onAppear {
16+
if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String, let url = URL(string: "https://api.github.com/repos/sourcelocation/TrollTools/releases/latest") {
17+
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
18+
guard let data = data else { return }
19+
20+
if let json = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any] {
21+
if json["tag_name"] as? String != version {
22+
UIApplication.shared.confirmAlert(title: "Update available", body: "A new TrollTools update is available, do you want to visit releases page?", onOK: {
23+
UIApplication.shared.open(URL(string: "https://github.com/sourcelocation/TrollTools/releases/latest")!)
24+
}, noCancel: false)
25+
}
26+
}
27+
}
28+
task.resume()
29+
}
30+
}
31+
}
32+
}
33+
}
34+
35+
var currentUIAlertController: UIAlertController?
36+
37+
extension UIApplication {
38+
func dismissAlert(animated: Bool) {
39+
DispatchQueue.main.async {
40+
currentUIAlertController?.dismiss(animated: animated)
41+
}
42+
}
43+
func alert(title: String = "Error", body: String, animated: Bool = true, withButton: Bool = true) {
44+
DispatchQueue.main.async {
45+
currentUIAlertController = UIAlertController(title: title, message: body, preferredStyle: .alert)
46+
if withButton { currentUIAlertController?.addAction(.init(title: "OK", style: .cancel)) }
47+
self.present(alert: currentUIAlertController!)
48+
}
49+
}
50+
func confirmAlert(title: String = "Error", body: String, onOK: @escaping () -> (), noCancel: Bool) {
51+
DispatchQueue.main.async {
52+
currentUIAlertController = UIAlertController(title: title, message: body, preferredStyle: .alert)
53+
if !noCancel {
54+
currentUIAlertController?.addAction(.init(title: "Cancel", style: .cancel))
55+
}
56+
currentUIAlertController?.addAction(.init(title: "OK", style: noCancel ? .cancel : .default, handler: { _ in
57+
onOK()
58+
}))
59+
self.present(alert: currentUIAlertController!)
60+
}
61+
}
62+
func change(title: String = "Error", body: String) {
63+
DispatchQueue.main.async {
64+
currentUIAlertController?.title = title
65+
currentUIAlertController?.message = body
66+
}
67+
}
68+
69+
func present(alert: UIAlertController) {
70+
if var topController = self.windows[0].rootViewController {
71+
while let presentedViewController = topController.presentedViewController {
72+
topController = presentedViewController
73+
}
74+
75+
topController.present(alert, animated: true)
76+
// topController should now be your topmost view controller
77+
}
78+
}
79+
}

TrollTools/Private APIs/BadgeChanger.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ extension UIImage {
4141
}
4242
}
4343

44-
extension String: Error {}
44+
extension String: LocalizedError {
45+
public var errorDescription: String? { return self }
46+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// RootHelper.swift
3+
// TrollTools
4+
//
5+
// Created by exerhythm on 23.10.2022.
6+
//
7+
8+
import UIKit
9+
import NSTaskBridge
10+
11+
class RootHelper {
12+
static let rootHelperPath = Bundle.main.url(forAuxiliaryExecutable: "trolltoolsroothelper")!.path
13+
14+
static func move(from sourceURL: URL, to destURL: URL) throws {
15+
let code = spawnRoot(rootHelperPath, ["filemove", sourceURL.path, destURL.path], nil, nil)
16+
guard code == 0 else { throw "Helper.move: returned non-zero code \(code)" }
17+
}
18+
static func copy(from sourceURL: URL, to destURL: URL) throws {
19+
let code = spawnRoot(rootHelperPath, ["filecopy", sourceURL.path, destURL.path], nil, nil)
20+
guard code == 0 else { throw "Helper.move: returned non-zero code \(code)" }
21+
}
22+
static func createDirectory(at url: URL) throws {
23+
let code = spawnRoot(rootHelperPath, ["makedirectory", url.path, ""], nil, nil)
24+
guard code == 0 else { throw "Helper.move: returned non-zero code \(code)" }
25+
}
26+
static func removeItem(at url: URL) throws {
27+
let code = spawnRoot(rootHelperPath, ["removeitem", url.path, ""], nil, nil)
28+
guard code == 0 else { throw "Helper.move: returned non-zero code \(code)" }
29+
}
30+
static func permissionset(url: URL) throws {
31+
let code = spawnRoot(rootHelperPath, ["permissionset", url.path, ""], nil, nil)
32+
guard code == 0 else { throw "Helper.move: returned non-zero code \(code)" }
33+
}
34+
}

TrollTools/Private APIs/ThemeManager.swift

Lines changed: 0 additions & 160 deletions
This file was deleted.

0 commit comments

Comments
 (0)