refactor: reogranize code structure for better styling

This commit is contained in:
sankalp committed 2026-07-21 14:40:23 +05:45
1 parent e095e88715
commit 0e805d24ec
2 files changed
+104 -94

No files matched your search

+45 -39
View File
@@ -1,66 +1,72 @@
import os
import sys
# Ensure the 'src' directory is in the python path
# This allows 'import main' and other src-relative imports to work from the root
src_path = os.path.join(os.path.dirname(__file__), "src")
if src_path not in sys.path:
sys.path.insert(0, src_path)
# App-capture library paths (built via meson in src/window/switcher/app-capture/builddir)
_app_capture_builddir = os.path.join(
src_path, "window", "switcher", "app-capture", "builddir"
)
if os.path.isdir(_app_capture_builddir):
for env_var in ("GI_TYPELIB_PATH", "LD_LIBRARY_PATH"):
current = os.environ.get(env_var, "")
if _app_capture_builddir not in current.split(os.pathsep):
os.environ[env_var] = (
f"{_app_capture_builddir}{os.pathsep}{current}"
if current
else _app_capture_builddir
)
def setup_environment():
"""Ensure the src directory is in sys.path and configure C library paths."""
src_path = os.path.join(os.path.dirname(__file__), "src")
if src_path not in sys.path:
sys.path.insert(0, src_path)
# App-capture library paths (built via meson in src/window/switcher/app-capture/builddir)
app_capture_builddir = os.path.join(
src_path, "window", "switcher", "app-capture", "builddir"
)
if os.path.isdir(app_capture_builddir):
for env_var in ("GI_TYPELIB_PATH", "LD_LIBRARY_PATH"):
current = os.environ.get(env_var, "")
if app_capture_builddir not in current.split(os.pathsep):
os.environ[env_var] = (
f"{app_capture_builddir}{os.pathsep}{current}"
if current
else app_capture_builddir
)
# Apply monkey patch for hyprland lua dispatcher
def run_app():
"""Start the main Modus application."""
from main import main as app_main
app_main()
def run_lock():
"""Start the lock screen."""
from window.lock import main as lock_main
lock_main()
def run_spotlight(argv):
"""Start the spotlight search interface."""
from window.spotlight.app import main as spotlight_main
command = ""
text = ""
external = False
external = "--external" in argv
positional = [arg for arg in argv if arg != "--external"]
positional = []
for arg in argv:
if arg == "--external":
external = True
else:
positional.append(arg)
if positional:
command = positional[0]
if len(positional) > 1:
text = " ".join(positional[1:])
command = positional[0] if positional else ""
text = " ".join(positional[1:]) if len(positional) > 1 else ""
spotlight_main(command=command, text=text, external=external)
def main():
setup_environment()
# Route the command based on arguments
if len(sys.argv) > 1:
command = sys.argv[1]
if command == "lock":
run_lock()
return
elif command == "spotlight":
run_spotlight(sys.argv[2:])
return
# Default to running the main app
run_app()
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "lock":
run_lock()
elif len(sys.argv) > 1 and sys.argv[1] == "spotlight":
run_spotlight(sys.argv[2:])
else:
run_app()
main()