Skip to content

Commit 4e71010

Browse files
1. add function
2. get unsandbox permission 3. add i18n
1 parent 842c6fd commit 4e71010

7 files changed

Lines changed: 127 additions & 19 deletions

File tree

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
TARGET = iOS
2+
ARCHS := arm64
13
TARGET = iphone:clang:latest:14.0
24
INSTALL_TARGET_PROCESSES = RebootTools
35

@@ -10,6 +12,9 @@ RebootTools_FRAMEWORKS = UIKit CoreGraphics
1012
RebootTools_RESOURCES = Resources/Assets.xcassets
1113

1214
include $(THEOS_MAKE_PATH)/application.mk
15+
16+
$(APPLICATION_NAME)_CODESIGN_FLAGS = -Sentitlements.plist
17+
1318
SUBPROJECTS += RebootRootHelper
1419
include $(THEOS_MAKE_PATH)/aggregate.mk
1520

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"CFBundleDisplayName" = "RebootTools";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"CFBundleDisplayName" = "RebootTools";
2+
"Install_With_TrollStore_text" = "Already installed via TrollStore";
3+
"Need_Install_With_TrollStore_text" = "Requires TrollStore installation";
4+
"Reboot_Device_text" = "Reboot Device";
5+
"Show_Alert_Before_Starting_text" = "Show alert before starting";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"CFBundleDisplayName" = "重启工具";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"CFBundleDisplayName" = "重启工具";
2+
"Install_With_TrollStore_text" = "已经通过TrollStore安装";
3+
"Need_Install_With_TrollStore_text" = "需要使用TrollStore安装";
4+
"Reboot_Device_text" = "重启设备";
5+
"Show_Alert_Before_Starting_text" = "开始操作前显示提醒";

RootViewController.swift

Lines changed: 96 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,108 @@ class RootViewController: UIViewController {
55
override func viewDidLoad() {
66
super.viewDidLoad()
77

8-
self.title = "RootViewController"
9-
// 设置背景颜色以区分
8+
self.title = NSLocalizedString("CFBundleDisplayName", comment: "")
9+
10+
// 设置ViewController的背景颜色
1011
self.view.backgroundColor = UIColor.systemBackground
11-
12-
let appIcon = UIImage(named: "AppIcon")
13-
// let imageView = UIImageView(image: appIcon)
14-
let imageView = UIImageView()
15-
imageView.image = UIImage(systemName: "power.circle.fill")
16-
imageView.tintColor = UIColor(hex: "#32a5e7")
12+
13+
// icon
14+
let iconImageView = UIImageView()
15+
16+
if #available(iOS 15.0, *) {
17+
iconImageView.image = UIImage(systemName: "power.circle.fill")
18+
iconImageView.tintColor = UIColor(hex: "#32A5E7")
19+
} else {
20+
let appIcon = UIImage(named: "AppIcon")
21+
iconImageView.image = appIcon
22+
}
23+
1724
// 禁用自动调整大小
18-
imageView.translatesAutoresizingMaskIntoConstraints = false
25+
iconImageView.translatesAutoresizingMaskIntoConstraints = false
1926
// 设置图片适应方式
20-
imageView.contentMode = .scaleAspectFit
21-
22-
self.view.addSubview(imageView)
23-
24-
// AutoLaout
27+
iconImageView.contentMode = .scaleAspectFit
28+
29+
// 检查权限
30+
let checkPermissionLabel = UILabel()
31+
checkPermissionLabel.translatesAutoresizingMaskIntoConstraints = false
32+
checkPermissionLabel.textAlignment = .center // 设置文本居中
33+
34+
var enable = self.checkInstallPermission()
35+
36+
if(enable) {
37+
checkPermissionLabel.text = NSLocalizedString("Install_With_TrollStore_text", comment: "")
38+
checkPermissionLabel.textColor = UIColor.green
39+
} else {
40+
checkPermissionLabel.text = NSLocalizedString("Need_Install_With_TrollStore_text", comment: "")
41+
checkPermissionLabel.textColor = UIColor.red
42+
}
43+
44+
// 重启按钮
45+
let rebootButton = UIButton()
46+
rebootButton.setTitle(NSLocalizedString("Reboot_Device_text", comment: ""), for: .normal)
47+
rebootButton.translatesAutoresizingMaskIntoConstraints = false
48+
49+
// 添加设置项
50+
let showAlertSwitch = UISwitch()
51+
showAlertSwitch.translatesAutoresizingMaskIntoConstraints = false
52+
53+
let showAlertLabel = UILabel()
54+
showAlertLabel.text = NSLocalizedString("Show_Alert_Before_Starting_text", comment: "")
55+
showAlertLabel.textColor = UIColor.label
56+
showAlertLabel.translatesAutoresizingMaskIntoConstraints = false
57+
58+
// 添加子视图
59+
let showAlertSubView = UIView()
60+
showAlertSubView.translatesAutoresizingMaskIntoConstraints = false
61+
// 将开关和标签添加到子视图中
62+
showAlertSubView.addSubview(showAlertLabel)
63+
showAlertSubView.addSubview(showAlertSwitch)
64+
65+
// 向View中添加控件
66+
self.view.addSubview(iconImageView)
67+
self.view.addSubview(checkPermissionLabel)
68+
self.view.addSubview(rebootButton)
69+
self.view.addSubview(showAlertSubView)
70+
71+
72+
// AutoLayout
2573
NSLayoutConstraint.activate([
26-
imageView.widthAnchor.constraint(equalToConstant: 100), // 设置宽度
27-
imageView.heightAnchor.constraint(equalToConstant: 100), // 设置高度
28-
imageView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), // 水平居中
29-
imageView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 100)
30-
74+
iconImageView.widthAnchor.constraint(equalToConstant: 100), // 设置宽度
75+
iconImageView.heightAnchor.constraint(equalToConstant: 100), // 设置高度
76+
iconImageView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), // 水平居中
77+
iconImageView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 100),
78+
79+
checkPermissionLabel.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), // 水平居中
80+
checkPermissionLabel.topAnchor.constraint(equalTo: iconImageView.bottomAnchor, constant: 30), // 在 iconImageView 底部,间隔 20 点
81+
checkPermissionLabel.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 20), // 左侧边距
82+
checkPermissionLabel.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -20), // 右侧边距
83+
84+
rebootButton.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), // 水平居中
85+
rebootButton.topAnchor.constraint(equalTo: checkPermissionLabel.bottomAnchor, constant: 30),
86+
rebootButton.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 20), // 左侧边距
87+
rebootButton.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -20), // 右侧边距
88+
89+
showAlertSubView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
90+
showAlertSubView.topAnchor.constraint(equalTo: rebootButton.bottomAnchor, constant: 30),
91+
// 动态设置容器的宽度和高度
92+
showAlertSubView.leadingAnchor.constraint(equalTo: showAlertLabel.leadingAnchor),
93+
showAlertSubView.trailingAnchor.constraint(equalTo: showAlertSwitch.trailingAnchor),
94+
showAlertSubView.heightAnchor.constraint(equalTo: showAlertSwitch.heightAnchor),
95+
// 标签和开关在容器中水平排列
96+
showAlertLabel.leadingAnchor.constraint(equalTo: showAlertSubView.leadingAnchor),
97+
showAlertLabel.centerYAnchor.constraint(equalTo: showAlertSubView.centerYAnchor),
98+
99+
showAlertSwitch.leadingAnchor.constraint(equalTo: showAlertLabel.trailingAnchor, constant: 10),
100+
showAlertSwitch.centerYAnchor.constraint(equalTo: showAlertSubView.centerYAnchor),
101+
showAlertSwitch.trailingAnchor.constraint(equalTo: showAlertSubView.trailingAnchor)
31102
])
32103
}
104+
105+
func checkInstallPermission() -> Bool {
106+
let path = "/var/mobile/Library/Preferences"
107+
let writeable = access(path, W_OK) == 0
108+
return writeable
109+
}
33110
}
34111

35112
extension UIColor {

entitlements.plist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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>get-task-allow</key>
6+
<true/>
7+
<key>platform-application</key>
8+
<true/>
9+
<key>com.apple.private.security.no-sandbox</key>
10+
<true/>
11+
<key>com.apple.private.persona-mgmt</key>
12+
<true/>
13+
</dict>
14+
</plist>

0 commit comments

Comments
 (0)