forked from rponeawa/thermalmonitordDisabler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_app.py
320 lines (264 loc) · 13.7 KB
/
gui_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import platform
import plistlib
import traceback
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtSvg import QSvgWidget
from PyQt5.QtCore import QLocale
import qdarktheme
from pymobiledevice3 import usbmux
from pymobiledevice3.lockdown import create_using_usbmux
import resources_rc
from Sparserestore.restore import restore_files, FileToRestore
from devicemanagement.constants import Device
class App(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.device = None
locale = QLocale.system().name()
self.language = "zh" if locale.startswith("zh") else "en"
self.thermalmonitord = False
self.disable_ota = False
self.disable_usage_tracking_agent = False
self.skip_setup = True
self.language_pack = {
"en": {
"title": "thermalmonitordDisabler",
"modified_by": "Modified by rponeawa from LeminLimez's Nugget.\nFree tool. If you purchased it, please report the seller.",
"backup_warning": "Please back up your device before using!",
"connect_prompt": "Please connect your device and try again!",
"connected": "Connected to",
"ios_version": "iOS",
"apply_changes": "Applying changes to disabled.plist...",
"applying_changes": "Applying changes...",
"success": "Changes applied successfully!",
"error": "An error occurred while applying changes to disabled.plist:",
"error_connecting": "Error connecting to device",
"goodbye": "Goodbye!",
"input_prompt": "Enter a number: ",
"menu_options": [
"Disable thermalmonitord",
"Disable OTA",
"Disable UsageTrackingAgent",
"Apply changes",
"切换到简体中文",
"Refresh"
]
},
"zh": {
"title": "温控禁用工具",
"modified_by": "由 rponeawa 基于 LeminLimez 的 Nugget 修改。\n免费工具,若您是购买而来,请举报卖家。",
"backup_warning": "使用前请备份您的设备!",
"connect_prompt": "请连接设备并重试!",
"connected": "已连接到",
"ios_version": "iOS",
"apply_changes": "正在应用更改到 disabled.plist...",
"applying_changes": "正在应用修改...",
"success": "更改已成功应用!",
"error": "应用更改时发生错误:",
"error_connecting": "连接设备时发生错误",
"goodbye": "再见!",
"input_prompt": "请输入选项: ",
"menu_options": [
"禁用温控",
"禁用系统更新",
"禁用使用情况日志",
"应用更改",
"Switch to English",
"刷新"
]
}
}
self.init_ui()
self.get_device_info()
def set_font(self):
if platform.system() == "Windows":
font = QtGui.QFont("Microsoft YaHei")
QtWidgets.QApplication.setFont(font)
def init_ui(self):
self.setWindowTitle(self.language_pack[self.language]["title"])
self.set_font()
self.layout = QtWidgets.QVBoxLayout()
self.modified_by_label = QtWidgets.QLabel(self.language_pack[self.language]["modified_by"])
self.layout.addWidget(self.modified_by_label)
self.icon_layout = QtWidgets.QHBoxLayout()
self.icon_layout.setAlignment(QtCore.Qt.AlignLeft)
self.icon_layout.setSpacing(10)
self.github_icon = QSvgWidget(":/brand-github.svg")
self.github_icon.setFixedSize(24, 24)
self.github_icon.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.github_icon.mouseReleaseEvent = lambda event: self.open_link("https://github.com/rponeawa/thermalmonitordDisabler")
self.bilibili_icon = QSvgWidget(":/brand-bilibili.svg")
self.bilibili_icon.setFixedSize(24, 24)
self.bilibili_icon.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.bilibili_icon.mouseReleaseEvent = lambda event: self.open_link("https://space.bilibili.com/332095459")
self.icon_layout.addWidget(self.github_icon)
self.icon_layout.addWidget(self.bilibili_icon)
self.layout.addLayout(self.icon_layout)
self.device_info = QtWidgets.QLabel(self.language_pack[self.language]["backup_warning"])
self.layout.addWidget(self.device_info)
self.thermalmonitord_checkbox = QtWidgets.QCheckBox(self.language_pack[self.language]["menu_options"][0])
self.layout.addWidget(self.thermalmonitord_checkbox)
self.disable_ota_checkbox = QtWidgets.QCheckBox(self.language_pack[self.language]["menu_options"][1])
self.layout.addWidget(self.disable_ota_checkbox)
self.disable_usage_tracking_checkbox = QtWidgets.QCheckBox(self.language_pack[self.language]["menu_options"][2])
self.layout.addWidget(self.disable_usage_tracking_checkbox)
self.apply_button = QtWidgets.QPushButton(self.language_pack[self.language]["menu_options"][3])
self.apply_button.clicked.connect(self.apply_changes)
self.layout.addWidget(self.apply_button)
self.refresh_button = QtWidgets.QPushButton(self.language_pack[self.language]["menu_options"][5])
self.refresh_button.clicked.connect(self.get_device_info)
self.layout.addWidget(self.refresh_button)
self.switch_language_button = QtWidgets.QPushButton(self.language_pack[self.language]["menu_options"][4])
self.switch_language_button.clicked.connect(self.switch_language)
self.layout.addWidget(self.switch_language_button)
self.setLayout(self.layout)
self.show()
def open_link(self, url):
try:
QtGui.QDesktopServices.openUrl(QtCore.QUrl(url))
except Exception as e:
print(f"Error opening link {url}: {str(e)}")
def get_device_info(self):
connected_devices = usbmux.list_devices()
if not connected_devices:
self.device = None
self.device_info.setText(self.language_pack[self.language]["connect_prompt"])
self.disable_controls(True)
return
for current_device in connected_devices:
if current_device.is_usb:
try:
ld = create_using_usbmux(serial=current_device.serial)
vals = ld.all_values
print(vals)
self.device = Device(
uuid=current_device.serial,
name=vals['DeviceName'],
version=vals['ProductVersion'],
build=vals['BuildVersion'],
model=vals['ProductType'],
locale=ld.locale,
ld=ld
)
self.update_device_info()
self.disable_controls(False)
return
except Exception as e:
self.device_info.setText(self.language_pack[self.language]["error_connecting"] + str(e))
print(traceback.format_exc())
return
self.device = None
self.device_info.setText(self.language_pack[self.language]["connect_prompt"])
self.disable_controls(True)
def disable_controls(self, disable):
self.thermalmonitord_checkbox.setEnabled(not disable)
self.disable_ota_checkbox.setEnabled(not disable)
self.disable_usage_tracking_checkbox.setEnabled(not disable)
self.apply_button.setEnabled(not disable)
def update_device_info(self):
if self.device:
self.device_info.setText(f"{self.language_pack[self.language]['connected']} {self.device.name}\n{self.language_pack[self.language]['ios_version']} {self.device.version}")
else:
self.device_info.setText(self.language_pack[self.language]["connect_prompt"])
self.disable_controls(True)
def modify_disabled_plist(self):
default_disabled_plist = {
"com.apple.magicswitchd.companion": True,
"com.apple.security.otpaird": True,
"com.apple.dhcp6d": True,
"com.apple.bootpd": True,
"com.apple.ftp-proxy-embedded": False,
"com.apple.relevanced": True
}
plist = default_disabled_plist.copy()
if self.thermalmonitord_checkbox.isChecked():
plist["com.apple.thermalmonitord"] = True
else:
plist.pop("com.apple.thermalmonitord", None)
if self.disable_ota_checkbox.isChecked():
plist["com.apple.mobile.softwareupdated"] = True
plist["com.apple.OTATaskingAgent"] = True
plist["com.apple.softwareupdateservicesd"] = True
else:
plist.pop("com.apple.mobile.softwareupdated", None)
plist.pop("com.apple.OTATaskingAgent", None)
plist.pop("com.apple.softwareupdateservicesd", None)
if self.disable_usage_tracking_checkbox.isChecked():
plist["com.apple.UsageTrackingAgent"] = True
else:
plist.pop("com.apple.UsageTrackingAgent", None)
return plistlib.dumps(plist, fmt=plistlib.FMT_XML)
def apply_changes(self):
self.apply_button.setText(self.language_pack[self.language]["applying_changes"])
self.apply_button.setEnabled(False)
QtWidgets.QApplication.processEvents()
QtCore.QTimer.singleShot(100, self._execute_changes)
def add_skip_setup(self, files_to_restore):
if self.skip_setup:
cloud_config_plist: dict = {
"SkipSetup": ["WiFi", "Location", "Restore", "SIMSetup", "Android", "AppleID", "IntendedUser", "TOS", "Siri", "ScreenTime", "Diagnostics", "SoftwareUpdate", "Passcode", "Biometric", "Payment", "Zoom", "DisplayTone", "MessagingActivationUsingPhoneNumber", "HomeButtonSensitivity", "CloudStorage", "ScreenSaver", "TapToSetup", "Keyboard", "PreferredLanguage", "SpokenLanguage", "WatchMigration", "OnBoarding", "TVProviderSignIn", "TVHomeScreenSync", "Privacy", "TVRoom", "iMessageAndFaceTime", "AppStore", "Safety", "Multitasking", "ActionButton", "TermsOfAddress", "AccessibilityAppearance", "Welcome", "Appearance", "RestoreCompleted", "UpdateCompleted"],
"AllowPairing": True,
"ConfigurationWasApplied": True,
"CloudConfigurationUIComplete": True,
"ConfigurationSource": 0,
"PostSetupProfileWasInstalled": True,
"IsSupervised": False,
}
files_to_restore.append(FileToRestore(
contents=plistlib.dumps(cloud_config_plist),
restore_path="systemgroup.com.apple.configurationprofiles/Library/ConfigurationProfiles/CloudConfigurationDetails.plist",
domain="SysSharedContainerDomain-."
))
purplebuddy_plist = {
"SetupDone": True,
"SetupFinishedAllSteps": True,
"UserChoseLanguage": True
}
files_to_restore.append(FileToRestore(
contents=plistlib.dumps(purplebuddy_plist),
restore_path="mobile/com.apple.purplebuddy.plist",
domain="ManagedPreferencesDomain"
))
def _execute_changes(self):
try:
files_to_restore = []
print("\n" + self.language_pack[self.language]["apply_changes"])
plist_data = self.modify_disabled_plist()
files_to_restore.append(FileToRestore(
contents=plist_data,
restore_path="com.apple.xpc.launchd/disabled.plist",
domain="DatabaseDomain",
owner=0,
group=0
))
self.add_skip_setup(files_to_restore)
print(files_to_restore)
restore_files(files=files_to_restore, reboot=True, lockdown_client=self.device.ld)
QtWidgets.QMessageBox.information(self, "Success", self.language_pack[self.language]["success"])
except Exception as e:
QtWidgets.QMessageBox.critical(self, "Error", self.language_pack[self.language]["error"] + str(e))
print(traceback.format_exc())
finally:
self.apply_button.setText(self.language_pack[self.language]["menu_options"][3])
self.apply_button.setEnabled(True)
def switch_language(self):
self.language = "zh" if self.language == "en" else "en"
self.setWindowTitle(self.language_pack[self.language]["title"])
self.modified_by_label.setText(self.language_pack[self.language]["modified_by"])
if self.device:
self.update_device_info()
else:
self.device_info.setText(self.language_pack[self.language]["connect_prompt"])
self.thermalmonitord_checkbox.setText(self.language_pack[self.language]["menu_options"][0])
self.disable_ota_checkbox.setText(self.language_pack[self.language]["menu_options"][1])
self.disable_usage_tracking_checkbox.setText(self.language_pack[self.language]["menu_options"][2])
self.apply_button.setText(self.language_pack[self.language]["menu_options"][3])
self.switch_language_button.setText(self.language_pack[self.language]["menu_options"][4])
self.refresh_button.setText(self.language_pack[self.language]["menu_options"][5])
if __name__ == "__main__":
import sys
qdarktheme.enable_hi_dpi()
app = QtWidgets.QApplication(sys.argv)
qdarktheme.setup_theme()
gui = App()
sys.exit(app.exec_())