X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/blobdiff_plain/ebec96db064b3cddf99db3727fd3f96327066ccf..dd038eddd7ec11c6fbe37f9082b6215291e0537f:/tools/services/user_manager.py diff --git a/tools/services/user_manager.py b/tools/services/user_manager.py index 5616035..9ab546a 100644 --- a/tools/services/user_manager.py +++ b/tools/services/user_manager.py @@ -4,6 +4,7 @@ import logging import os import threading import tools.config +import tools.helpers.net from tools.interfaces import IUserMonitor from tools.interfaces import IPlatform @@ -28,57 +29,63 @@ def start(args, session, unlocked_cb=None): desktop_file_path = apps_dir + "/waydroid." + packageName + ".desktop" if not os.path.exists(desktop_file_path): - lines = ["[Desktop Entry]", "Type=Application"] - lines.append("Name=" + appInfo["name"]) - lines.append("Exec=waydroid app launch " + packageName) - lines.append("Icon=" + waydroid_data + "/icons/" + packageName + ".png") - lines.append("Categories=X-WayDroid-App;") - lines.append("X-Purism-FormFactor=Workstation;Mobile;") - lines.append("Actions=app_settings;") - lines.append("[Desktop Action app_settings]") - lines.append("Name=App Settings") - lines.append("Exec=waydroid app intent android.settings.APPLICATION_DETAILS_SETTINGS package:" + packageName) - desktop_file = open(desktop_file_path, "w") - for line in lines: - desktop_file.write(line + "\n") - desktop_file.close() - os.chmod(desktop_file_path, 0o644) + with open(desktop_file_path, "w") as desktop_file: + desktop_file.write(f"""\ +[Desktop Entry] +Type=Application +Name={appInfo["name"]} +Exec=waydroid app launch {packageName} +Icon={waydroid_data}/icons/{packageName}.png +Categories=X-WayDroid-App; +X-Purism-FormFactor=Workstation;Mobile; +Actions=app_settings; + +[Desktop Action app_settings] +Name=App Settings +Exec=waydroid app intent android.settings.APPLICATION_DETAILS_SETTINGS package:{packageName} +Icon={waydroid_data}/icons/com.android.settings.png +""") return 0 def makeWaydroidDesktopFile(hide): desktop_file_path = apps_dir + "/Waydroid.desktop" - if os.path.isfile(desktop_file_path): - os.remove(desktop_file_path) - lines = ["[Desktop Entry]", "Type=Application"] - lines.append("Name=Waydroid") - lines.append("Exec=waydroid show-full-ui") - lines.append("Categories=X-WayDroid-App;") - lines.append("X-Purism-FormFactor=Workstation;Mobile;") - if hide: - lines.append("NoDisplay=true") - lines.append("Icon=waydroid") - desktop_file = open(desktop_file_path, "w") - for line in lines: - desktop_file.write(line + "\n") - desktop_file.close() - os.chmod(desktop_file_path, 0o644) + # If the user has set the desktop file as read-only, we won't replace it + if os.path.isfile(desktop_file_path) and not os.access(desktop_file_path, os.W_OK): + logging.info(f"Desktop file '{desktop_file_path}' is not writeable, not updating it") + else: + if os.path.isfile(desktop_file_path): + os.remove(desktop_file_path) + with open(desktop_file_path, "w") as desktop_file: + desktop_file.write(f"""\ +[Desktop Entry] +Type=Application +Name=Waydroid +Exec=waydroid show-full-ui +Categories=X-WayDroid-App;Utility; +X-Purism-FormFactor=Workstation;Mobile; +Icon=waydroid +NoDisplay={str(hide).lower()} +""") def userUnlocked(uid): + cfg = tools.config.load(args) logging.info("Android with user {} is ready".format(uid)) + if cfg["waydroid"]["auto_adb"] == "True": + try: + tools.helpers.net.adb_connect(args) + except: + pass + platformService = IPlatform.get_service(args) if platformService: if not os.path.exists(apps_dir): - os.mkdir(apps_dir) - os.chmod(apps_dir, 0o700) + os.mkdir(apps_dir, 0o700) appsList = platformService.getAppsInfo() for app in appsList: makeDesktopFile(app) multiwin = platformService.getprop("persist.waydroid.multi_windows", "false") - if multiwin == "false": - makeWaydroidDesktopFile(False) - else: - makeWaydroidDesktopFile(True) + makeWaydroidDesktopFile(multiwin == "true") if unlocked_cb: unlocked_cb()