]> glassweightruler.freedombox.rocks Git - waydroid.git/blobdiff - tools/services/user_manager.py
session: Move waydroid user data to XDG_DATA_HOME
[waydroid.git] / tools / services / user_manager.py
index 4e7455b5996e1f73f456e5a46a061dae238c3b32..09b6bab0a240a0a96952275699c1ea13c593c526 100644 (file)
@@ -8,7 +8,8 @@ from tools.interfaces import IUserMonitor
 from tools.interfaces import IPlatform
 
 
-def start(args):
+def start(args, unlocked_cb=None):
+
     def makeDesktopFile(appInfo):
         showApp = False
         for cat in appInfo["categories"]:
@@ -19,8 +20,17 @@ def start(args):
         
         packageName = appInfo["packageName"]
 
-        desktop_file_path = args.host_user + \
-            "/.local/share/applications/" + packageName + ".desktop"
+        desktop_file_path = args.apps_dir + "/waydroid." + packageName + ".desktop"
+        #TODO: Drop me
+        if os.path.exists(desktop_file_path):
+            with open(desktop_file_path) as file:
+                filedata = file.read()
+            filedata = filedata.replace(
+                "Icon=" + args.old_waydroid_data, "Icon=" + args.waydroid_data)
+            with open(desktop_file_path, 'w') as file:
+                file.write(filedata)
+            os.chmod(desktop_file_path, 0o755)
+
         if not os.path.exists(desktop_file_path):
             lines = ["[Desktop Entry]", "Type=Application"]
             lines.append("Name=" + appInfo["name"])
@@ -34,8 +44,7 @@ def start(args):
             return 0
 
     def makeWaydroidDesktopFile(hide):
-        desktop_file_path = args.host_user + \
-            "/.local/share/applications/Waydroid.desktop"
+        desktop_file_path = args.apps_dir + "/Waydroid.desktop"
         if os.path.isfile(desktop_file_path):
             os.remove(desktop_file_path)
         lines = ["[Desktop Entry]", "Type=Application"]
@@ -54,10 +63,17 @@ def start(args):
         logging.info("Android with user {} is ready".format(uid))
         session_cfg = tools.config.load_session()
         args.waydroid_data = session_cfg["session"]["waydroid_data"]
-        args.host_user = session_cfg["session"]["host_user"]
+        #TODO: Drop me
+        args.old_waydroid_data = session_cfg["session"]["host_user"] + \
+            "/waydroid/data"
+        args.apps_dir = session_cfg["session"]["xdg_data_home"] + \
+            "/applications/"
 
         platformService = IPlatform.get_service(args)
         if platformService:
+            if not os.path.exists(args.apps_dir):
+                os.mkdir(args.apps_dir)
+                os.chmod(args.apps_dir, 0o700)
             appsList = platformService.getAppsInfo()
             for app in appsList:
                 makeDesktopFile(app)
@@ -66,13 +82,14 @@ def start(args):
                 makeWaydroidDesktopFile(False)
             else:
                 makeWaydroidDesktopFile(True)
+        if unlocked_cb:
+            unlocked_cb(args)
 
     def packageStateChanged(mode, packageName, uid):
         platformService = IPlatform.get_service(args)
         if platformService:
             appInfo = platformService.getAppInfo(packageName)
-            desktop_file_path = args.host_user + \
-                "/.local/share/applications/" + packageName + ".desktop"
+            desktop_file_path = args.apps_dir + "/" + packageName + ".desktop"
             if mode == 0:
                 # Package added
                 makeDesktopFile(appInfo)