|
1 | 1 | import inspect |
2 | 2 | from pathlib import Path |
3 | 3 | import re |
| 4 | +import shutil |
4 | 5 | import subprocess |
5 | 6 | import threading |
6 | 7 | import time |
@@ -138,7 +139,6 @@ def startup_init(self, include_wifi=True): |
138 | 139 | self.start_wifi_services() |
139 | 140 |
|
140 | 141 | self.init_bluetooth() |
141 | | - self.apply_timezone(self.system_config.get_timezone()) |
142 | 142 |
|
143 | 143 | def init_bluetooth(self): |
144 | 144 | if(self.system_config.is_bluetooth_enabled()): |
@@ -360,11 +360,32 @@ def prompt_timezone_update(self): |
360 | 360 | self.system_config.set_timezone(tz) |
361 | 361 | self.apply_timezone(tz) |
362 | 362 |
|
| 363 | + |
363 | 364 | def apply_timezone(self, timezone): |
364 | | - os.environ['TZ'] = timezone |
365 | | - time.tzset() |
366 | | - #If we set the time be sure to |
367 | | - #export TZ='{timezone}' |
| 365 | + zoneinfo_path = f"/usr/share/zoneinfo/{timezone}" |
| 366 | + localtime_path = "/userdata/localtime" |
| 367 | + timezone_path = "/userdata/timezone" |
| 368 | + |
| 369 | + if not os.path.isfile(zoneinfo_path): |
| 370 | + Display.write_message_multiline([f"Error getting timezone file", |
| 371 | + f"Does not appear to be a file",f"{timezone}" |
| 372 | + ],3_000) |
| 373 | + return |
| 374 | + |
| 375 | + def safe_delete(path): |
| 376 | + if os.path.lexists(path): |
| 377 | + if os.path.isdir(path) and not os.path.islink(path): |
| 378 | + shutil.rmtree(path) |
| 379 | + else: |
| 380 | + os.remove(path) |
| 381 | + |
| 382 | + safe_delete(localtime_path) |
| 383 | + safe_delete(timezone_path) |
| 384 | + |
| 385 | + shutil.copyfile(zoneinfo_path, localtime_path) |
| 386 | + shutil.copyfile(localtime_path, timezone_path) |
| 387 | + |
| 388 | + Display.display_message("May need to reboot to apply timezone setting",3_000) |
368 | 389 |
|
369 | 390 | def set_theme(self, theme_path: str): |
370 | 391 | MiyooTrimCommon.set_theme(MiyooFlip.MIYOO_STOCK_CONFIG_LOCATION, theme_path) |
|
0 commit comments