Skip to content

Commit

Permalink
get yin_yang launching on flatpak
Browse files Browse the repository at this point in the history
Firefox is still not working correctly and I've currently just commented
out the assertion in firefox.py
  • Loading branch information
chase9 committed Jun 24, 2023
1 parent 1002ae6 commit 530e296
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 24 deletions.
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension-pkg-whitelist=PyQt5
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"name": "Python: Main",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/main.py",
"console": "integratedTerminal",
"module": "yin_yang",
"justMyCode": true
}
]
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
"python.linting.enabled": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
2 changes: 1 addition & 1 deletion runner.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
python3 /app/__main__.py
python3 -m yin_yang
7 changes: 6 additions & 1 deletion sh.oskar.yin-yang.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
"command": "runner.sh",
"finish-args": [
"--socket=wayland",
"--filesystem=host:rw"
"--socket=system-bus",
"--socket=session-bus",
"--share=ipc",
"--device=dri",
"--filesystem=host:rw",
"--filesystem=~/.mozilla:rw"
],
"modules": [
"python3-numpy.json",
Expand Down
6 changes: 4 additions & 2 deletions yin_yang/daemon_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from enum import Enum, auto
from pathlib import Path

from yin_yang import helpers

from .config import ConfigWatcher, config
from .meta import ConfigEvent, Modes

Expand All @@ -24,7 +26,7 @@ def create_files():


def run_command(command, **kwargs):
return subprocess.run(['systemctl', '--user', command, 'yin_yang.timer'], **kwargs)
return helpers.run(['systemctl', '--user', command, 'yin_yang.timer'], **kwargs)


def update_times():
Expand All @@ -48,7 +50,7 @@ def update_times():
with TIMER_PATH.open('w') as file:
file.writelines(lines)

subprocess.run(['systemctl', '--user', 'daemon-reload'])
helpers.run(['systemctl', '--user', 'daemon-reload'])
run_command('start')


Expand Down
47 changes: 40 additions & 7 deletions yin_yang/helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
import subprocess

# This is a helper method which will change how we check output depending on if
# The application is running in a flatpak or not.

"""Check output of a command.
This is a helper method which will change how we check output depending on if
The application is running in a flatpak or not.
"""


def check_output(args, universal_newlines=False) -> bytes:
try:
return subprocess.check_output(args, universal_newlines)
except FileNotFoundError:
flatpak_args = ['flatpak-spawn', '--host'] + args
return subprocess.check_output(flatpak_args, universal_newlines)
try:
output = subprocess.check_output(
args=args, universal_newlines=universal_newlines
)
return output
except FileNotFoundError:
flatpak_args = ["flatpak-spawn", "--host"] + args
return subprocess.check_output(
args=flatpak_args, universal_newlines=universal_newlines
)


def check_call(command, stdout=None) -> int:
try:
return subprocess.check_call(command, stdout=stdout)
except FileNotFoundError:
flatpak_args = ["flatpak-spawn", "--host"] + command
return subprocess.check_call(flatpak_args, stdout=stdout)


def run(command: list[str], kwargs: list[str] = []) -> subprocess.CompletedProcess[str]:
try:
if len(kwargs) == 0:
return subprocess.run(command)
else:
return subprocess.run(command, **kwargs)
except FileNotFoundError:
flatpak_args = ["flatpak-spawn", "--host"] + command
if len(kwargs) == 0:
return subprocess.run(flatpak_args)
else:
return subprocess.run(flatpak_args, **kwargs)
6 changes: 4 additions & 2 deletions yin_yang/plugins/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from PySide6.QtGui import QColor, QRgba64
from PySide6.QtWidgets import QGroupBox, QHBoxLayout, QLineEdit, QComboBox

from yin_yang import helpers

from ..meta import UnsupportedDesktopError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -134,7 +136,7 @@ def set_theme(self, theme: str):

# insert theme in command and run it
command = self.insert_theme(theme)
subprocess.check_call(command)
helpers.check_call(command)

def insert_theme(self, theme: str) -> list:
command = self.command.copy()
Expand All @@ -148,7 +150,7 @@ def insert_theme(self, theme: str) -> list:
def check_command(command) -> bool:
# Returns true if command execution succeeds
try:
subprocess.check_call(command, stdout=subprocess.DEVNULL)
helpers.check_call(command, stdout=subprocess.DEVNULL)
return True
except FileNotFoundError:
# if no such command is available, the plugin is not available
Expand Down
1 change: 0 additions & 1 deletion yin_yang/plugins/colors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import subprocess
import re
from yin_yang import helpers

Expand Down
12 changes: 6 additions & 6 deletions yin_yang/plugins/custom.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import subprocess

from PySide6.QtWidgets import QLineEdit

from yin_yang import helpers

from ._plugin import PluginCommandline


Expand All @@ -18,18 +18,18 @@ def available(self) -> bool:

def get_input(self, widget):
inputs: list[QLineEdit | QLineEdit] = super().get_input(widget)
inputs[0].setPlaceholderText('Light script')
inputs[1].setPlaceholderText('Dark script')
inputs[0].setPlaceholderText("Light script")
inputs[1].setPlaceholderText("Dark script")
return inputs

def set_theme(self, theme: str):
if not theme:
raise ValueError(f'Theme \"{theme}\" is invalid')
raise ValueError(f'Theme "{theme}" is invalid')

if not (self.available and self.enabled):
return

# insert theme in command and run it
command = self.insert_theme(theme)
# set shell=True to avoid having to separate between arguments
subprocess.check_call(command, shell=True)
helpers.check_call(command, shell=True)
2 changes: 1 addition & 1 deletion yin_yang/plugins/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def available_themes(self) -> dict:
logger.warning(f'Firefox profile has no extensions installed: {path}')
continue

assert themes != {}, 'No themes found!'
# assert themes != {}, 'No themes found!'
return themes

@property
Expand Down
1 change: 0 additions & 1 deletion yin_yang/plugins/system.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import logging
import subprocess
import pwd
import os
from configparser import ConfigParser
Expand Down

0 comments on commit 530e296

Please sign in to comment.