Updated Launcher, made ShellFM Settings more generic

This commit is contained in:
2023-02-21 13:16:53 -06:00
parent 3ad9e1c7bb
commit f5dd0e9ff0
8 changed files with 122 additions and 58 deletions

View File

@@ -76,6 +76,10 @@ class FileSystemActions(HandlerMixin, CRUDMixin):
file_name = state.uris[0].split("/")[-1]
event_system.emit("set_clipboard_data", (file_name,))
def copy_path(self):
state = event_system.emit_and_await("get_current_state")
dir = state.tab.get_current_directory()
event_system.emit("set_clipboard_data", (file_name,))
def open_files(self):
state = event_system.emit_and_await("get_current_state")

View File

@@ -7,6 +7,9 @@ import subprocess
# Apoplication imports
class ShellFMLauncherException(Exception):
...
class Launcher:
@@ -15,12 +18,7 @@ class Launcher:
command = []
if lowerName.endswith(self.fvideos):
command = [self.media_app]
if "mplayer" in self.media_app:
command += self.mplayer_options
command += [file]
command = [self.media_app, file]
elif lowerName.endswith(self.fimages):
command = [self.image_app, file]
elif lowerName.endswith(self.fmusic):
@@ -42,13 +40,22 @@ class Launcher:
def execute(self, command, start_dir=os.getenv("HOME"), use_shell=False):
self.logger.debug(command)
subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=True, stdout=None, stderr=None, close_fds=True)
try:
self.logger.debug(command)
subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=True, stdout=None, stderr=None, close_fds=True)
except ShellFMLauncherException as e:
self.logger.error(f"Couldn't execute: {command}")
self.logger.error(e)
# TODO: Return stdout and in handlers along with subprocess instead of sinking to null
# TODO: Return std(out/in/err) handlers along with subprocess instead of sinking to null
def execute_and_return_thread_handler(self, command, start_dir=os.getenv("HOME"), use_shell=False):
DEVNULL = open(os.devnull, 'w')
return subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=False, stdout=DEVNULL, stderr=DEVNULL, close_fds=False)
try:
DEVNULL = open(os.devnull, 'w')
return subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=False, stdout=DEVNULL, stderr=DEVNULL, close_fds=False)
except ShellFMLauncherException as e:
self.logger.error(f"Couldn't execute and return thread: {command}")
self.logger.error(e)
return None
@threaded
def app_chooser_exec(self, app_info, uris):
@@ -75,9 +82,9 @@ class Launcher:
try:
proc = subprocess.Popen(command)
proc.wait()
except Exception as e:
self.logger.debug(message)
self.logger.debug(e)
except ShellFMLauncherException as e:
self.logger.error(message)
self.logger.error(e)
return False
return True
@@ -86,7 +93,7 @@ class Launcher:
limit = self.remux_folder_max_disk_usage
try:
limit = int(limit)
except Exception as e:
except ShellFMLauncherException as e:
self.logger.debug(e)
return

View File

@@ -8,34 +8,43 @@ from os import path
# Apoplication imports
class ShellFMSettingsException(Exception):
...
class Settings:
logger = None
USR_SOLARFM = "/usr/share/solarfm"
SHIM_PATH = "/dev/shm/solarfm"
# NOTE: app_name should be defined using python 'builtins'
app_name_exists = False
try:
app_name
app_name_exists = True
except Exception as e:
...
APP_CONTEXT = f"{app_name.lower()}" if app_name_exists else "shellfm"
USR_APP_CONTEXT = f"/usr/share/{APP_CONTEXT}"
USER_HOME = path.expanduser('~')
CONFIG_PATH = f"{USER_HOME}/.config/solarfm"
CONFIG_PATH = f"{USER_HOME}/.config/{APP_CONTEXT}"
CONFIG_FILE = f"{CONFIG_PATH}/settings.json"
HIDE_HIDDEN_FILES = True
GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
DEFAULT_ICONS = f"{CONFIG_PATH}/icons"
DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png"
FFMPG_THUMBNLR = f"{CONFIG_PATH}/ffmpegthumbnailer" # Thumbnail generator binary
BLENDER_THUMBNLR = f"{CONFIG_PATH}/blender-thumbnailer" # Blender thumbnail generator binary
# REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder
REMUX_FOLDER = f"{SHIM_PATH}/.remuxs" # Remuxed files folder
REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder
ICON_DIRS = ["/usr/share/icons", f"{USER_HOME}/.icons" "/usr/share/pixmaps"]
# BASE_THUMBS_PTH = f"{USER_HOME}/.thumbnails" # Used for thumbnail generation
BASE_THUMBS_PTH = f"{SHIM_PATH}/.thumbnails" # Used for thumbnail generation
ABS_THUMBS_PTH = f"{BASE_THUMBS_PTH}/normal" # Used for thumbnail generation
BASE_THUMBS_PTH = f"{USER_HOME}/.thumbnails"
ABS_THUMBS_PTH = f"{BASE_THUMBS_PTH}/normal"
STEAM_ICONS_PTH = f"{BASE_THUMBS_PTH}/steam_icons"
# Dir structure check
if not path.isdir(SHIM_PATH):
os.mkdir(SHIM_PATH)
if not os.path.exists(CONFIG_PATH) or not os.path.exists(CONFIG_FILE):
msg = f"No config file located! Aborting loading ShellFM library...\nExpected: {CONFIG_FILE}"
raise ShellFMSettingsException(msg)
if not path.isdir(REMUX_FOLDER):
os.mkdir(REMUX_FOLDER)
@@ -50,7 +59,7 @@ class Settings:
os.mkdir(STEAM_ICONS_PTH)
if not os.path.exists(DEFAULT_ICONS):
DEFAULT_ICONS = f"{USR_SOLARFM}/icons"
DEFAULT_ICONS = f"{USR_APP_CONTEXT}/icons"
DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png"
with open(CONFIG_FILE) as f: