summaryrefslogtreecommitdiff
path: root/backend/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'backend/main.py')
-rw-r--r--backend/main.py41
1 files changed, 28 insertions, 13 deletions
diff --git a/backend/main.py b/backend/main.py
index a2ac008a..de06e633 100644
--- a/backend/main.py
+++ b/backend/main.py
@@ -1,14 +1,15 @@
# Change PyInstaller files permissions
import sys
-from subprocess import call
+from localplatform import chmod, chown, service_stop, service_start, ON_WINDOWS
if hasattr(sys, '_MEIPASS'):
- call(['chmod', '-R', '755', sys._MEIPASS])
+ chmod(sys._MEIPASS, 755)
# Full imports
from asyncio import new_event_loop, set_event_loop, sleep
from json import dumps, loads
from logging import DEBUG, INFO, basicConfig, getLogger
-from os import getenv, chmod, path
+from os import getenv, path
from traceback import format_exc
+import multiprocessing
import aiohttp_cors
# Partial imports
@@ -19,16 +20,15 @@ from aiohttp_jinja2 import setup as jinja_setup
# local modules
from browser import PluginBrowser
from helpers import (REMOTE_DEBUGGER_UNIT, csrf_middleware, get_csrf_token,
- get_home_path, get_homebrew_path, get_user, get_user_group,
- stop_systemd_unit, start_systemd_unit)
+ get_homebrew_path, mkdir_as_user, get_system_pythonpaths)
+
from injector import get_gamepadui_tab, Tab, get_tabs, close_old_tabs
from loader import Loader
from settings import SettingsManager
from updater import Updater
from utilities import Utilities
+from customtypes import UserType
-USER = get_user()
-GROUP = get_user_group()
HOMEBREW_PATH = get_homebrew_path()
CONFIG = {
"plugin_path": getenv("PLUGIN_PATH", path.join(HOMEBREW_PATH, "plugins")),
@@ -49,10 +49,11 @@ basicConfig(
logger = getLogger("Main")
def chown_plugin_dir():
- code_chown = call(["chown", "-R", USER+":"+GROUP, CONFIG["plugin_path"]])
- code_chmod = call(["chmod", "-R", "555", CONFIG["plugin_path"]])
- if code_chown != 0 or code_chmod != 0:
- logger.error(f"chown/chmod exited with a non-zero exit code (chown: {code_chown}, chmod: {code_chmod})")
+ if not path.exists(CONFIG["plugin_path"]): # For safety, create the folder before attempting to do anything with it
+ mkdir_as_user(CONFIG["plugin_path"])
+
+ if not chown(CONFIG["plugin_path"], UserType.HOST_USER) or not chmod(CONFIG["plugin_path"], 555):
+ logger.error(f"chown/chmod exited with a non-zero exit code")
if CONFIG["chown_plugin_path"] == True:
chown_plugin_dir()
@@ -79,9 +80,9 @@ class PluginManager:
async def startup(_):
if self.settings.getSetting("cef_forward", False):
- self.loop.create_task(start_systemd_unit(REMOTE_DEBUGGER_UNIT))
+ self.loop.create_task(service_start(REMOTE_DEBUGGER_UNIT))
else:
- self.loop.create_task(stop_systemd_unit(REMOTE_DEBUGGER_UNIT))
+ self.loop.create_task(service_stop(REMOTE_DEBUGGER_UNIT))
self.loop.create_task(self.loader_reinjector())
self.loop.create_task(self.load_plugins())
@@ -173,6 +174,20 @@ class PluginManager:
return run_app(self.web_app, host=CONFIG["server_host"], port=CONFIG["server_port"], loop=self.loop, access_log=None)
if __name__ == "__main__":
+ if ON_WINDOWS:
+ # Fix windows/flask not recognising that .js means 'application/javascript'
+ import mimetypes
+ mimetypes.add_type('application/javascript', '.js')
+
+ # Required for multiprocessing support in frozen files
+ multiprocessing.freeze_support()
+
+ # Append the loader's plugin path to the recognized python paths
+ sys.path.append(path.join(path.dirname(__file__), "plugin"))
+
+ # Append the system and user python paths
+ sys.path.extend(get_system_pythonpaths())
+
loop = new_event_loop()
set_event_loop(loop)
PluginManager(loop).run()