IPC changes, further externalizing settings

This commit is contained in:
itdominator 2022-06-14 17:12:25 -05:00
parent e4656c771a
commit ee086f67f4
7 changed files with 99 additions and 113 deletions

View File

@ -16,7 +16,7 @@ class Application(EventSystem):
def __init__(self, args, unknownargs):
if not trace_debug:
event_system.create_ipc_server()
event_system.create_ipc_listener()
time.sleep(0.1)
if not event_system.is_ipc_alive:

View File

@ -52,7 +52,7 @@ class GridMixin:
if not icon:
path = f"{dir}/{file}"
icon = self.get_system_thumbnail(path, tab.SYS_ICON_WH[0])
icon = self.get_system_thumbnail(path, tab.sys_icon_wh[0])
if not icon:
icon = GdkPixbuf.Pixbuf.new_from_file(tab.DEFAULT_ICON)

View File

@ -30,7 +30,7 @@ class Icon(DesktopIconMixin, VideoIconMixin):
if file.lower().endswith(self.fvideos): # Video icon
thumbnl = self.create_thumbnail(dir, file)
elif file.lower().endswith(self.fimages): # Image Icon
thumbnl = self.create_scaled_image(full_path, self.VIDEO_ICON_WH)
thumbnl = self.create_scaled_image(full_path, self.video_icon_wh)
elif full_path.lower().endswith( ('.desktop',) ): # .desktop file parsing
thumbnl = self.parse_desktop_files(full_path)
@ -46,7 +46,7 @@ class Icon(DesktopIconMixin, VideoIconMixin):
if isfile(hash_img_pth) == False:
self.generate_video_thumbnail(full_path, hash_img_pth)
thumbnl = self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH)
thumbnl = self.create_scaled_image(hash_img_pth, self.video_icon_wh)
if thumbnl == None: # If no icon whatsoever, return internal default
thumbnl = GdkPixbuf.Pixbuf.new_from_file(f"{self.DEFAULT_ICONS}/video.png")

View File

@ -18,23 +18,23 @@ class DesktopIconMixin:
if "steam" in icon:
name = xdgObj.getName()
file_hash = hashlib.sha256(str.encode(name)).hexdigest()
hash_img_pth = self.STEAM_ICONS_PTH + "/" + file_hash + ".jpg"
hash_img_pth = f"{self.STEAM_ICONS_PTH}/{file_hash}.jpg"
if isfile(hash_img_pth) == True:
# Use video sizes since headers are bigger
return self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH)
return self.create_scaled_image(hash_img_pth, self.video_icon_wh)
exec_str = xdgObj.getExec()
parts = exec_str.split("steam://rungameid/")
id = parts[len(parts) - 1]
imageLink = self.STEAM_BASE_URL + id + "/header.jpg"
imageLink = f"{self.STEAM_CDN_URL}{id}/header.jpg"
proc = subprocess.Popen(["wget", "-O", hash_img_pth, imageLink])
proc.wait()
# Use video thumbnail sizes since headers are bigger
return self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH)
return self.create_scaled_image(hash_img_pth, self.video_icon_wh)
elif os.path.exists(icon):
return self.create_scaled_image(icon, self.SYS_ICON_WH)
return self.create_scaled_image(icon, self.sys_icon_wh)
else:
alt_icon_path = ""
@ -43,7 +43,7 @@ class DesktopIconMixin:
if alt_icon_path != "":
break
return self.create_scaled_image(alt_icon_path, self.SYS_ICON_WH)
return self.create_scaled_image(alt_icon_path, self.sys_icon_wh)
except Exception as e:
print(".desktop icon generation issue:")
print( repr(e) )

View File

@ -31,6 +31,8 @@ class Launcher:
command = [self.music_app, file]
elif lowerName.endswith(self.foffice):
command = [self.office_app, file]
elif lowerName.endswith(self.fcode):
command = [self.code_app, file]
elif lowerName.endswith(self.ftext):
command = [self.text_app, file]
elif lowerName.endswith(self.fpdf):

View File

@ -19,68 +19,16 @@ class Settings:
CONFIG_FILE = f"{CONFIG_PATH}/settings.json"
HIDE_HIDDEN_FILES = True
GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
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
REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder
STEAM_BASE_URL = "https://steamcdn-a.akamaihd.net/steam/apps/"
ICON_DIRS = ["/usr/share/pixmaps", "/usr/share/icons", f"{USER_HOME}/.icons" ,]
BASE_THUMBS_PTH = f"{USER_HOME}/.thumbnails" # Used for thumbnail generation
ABS_THUMBS_PTH = f"{BASE_THUMBS_PTH}/normal" # Used for thumbnail generation
STEAM_ICONS_PTH = f"{BASE_THUMBS_PTH}/steam_icons"
CONTAINER_ICON_WH = [128, 128]
VIDEO_ICON_WH = [128, 64]
SYS_ICON_WH = [56, 56]
# CONTAINER_ICON_WH = [128, 128]
# VIDEO_ICON_WH = [96, 48]
# SYS_ICON_WH = [96, 96]
subpath = ""
go_past_home = None
lock_folder = None
locked_folders = None
mplayer_options = None
music_app = None
media_app = None
image_app = None
office_app = None
pdf_app = None
text_app = None
file_manager_app = None
remux_folder_max_disk_usage = None
if path.isfile(CONFIG_FILE):
with open(CONFIG_FILE) as infile:
settings = json.load(infile)["settings"]
subpath = settings["base_of_home"]
HIDE_HIDDEN_FILES = True if settings["hide_hidden_files"] == "true" else False
FFMPG_THUMBNLR = FFMPG_THUMBNLR if settings["thumbnailer_path"] == "" else settings["thumbnailer_path"]
go_past_home = True if settings["go_past_home"] == "" else settings["go_past_home"]
lock_folder = True if settings["lock_folder"] == "true" else False
locked_folders = settings["locked_folders"].split("::::")
mplayer_options = settings["mplayer_options"].split()
music_app = settings["music_app"]
media_app = settings["media_app"]
image_app = settings["image_app"]
office_app = settings["office_app"]
pdf_app = settings["pdf_app"]
text_app = settings["text_app"]
file_manager_app = settings["file_manager_app"]
terminal_app = settings["terminal_app"]
remux_folder_max_disk_usage = settings["remux_folder_max_disk_usage"]
# Filters
fvideos = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv', '.mpeg', '.mp4', '.webm')
foffice = ('.doc', '.docx', '.xls', '.xlsx', '.xlt', '.xltx', '.xlm', '.ppt', 'pptx', '.pps', '.ppsx', '.odt', '.rtf')
fimages = ('.png', '.jpg', '.jpeg', '.gif', '.ico', '.tga', '.webp')
ftext = ('.txt', '.text', '.sh', '.cfg', '.conf')
fmusic = ('.psf', '.mp3', '.ogg', '.flac', '.m4a')
fpdf = ('.pdf')
# Dir structure check
if not path.isdir(REMUX_FOLDER):
@ -98,3 +46,39 @@ class Settings:
if not os.path.exists(DEFAULT_ICONS):
DEFAULT_ICONS = f"{USR_SOLARFM}/icons"
DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png"
with open(CONFIG_FILE) as f:
settings = json.load(f)
config = settings["config"]
subpath = config["base_of_home"]
STEAM_CDN_URL = config["steam_cdn_url"]
FFMPG_THUMBNLR = FFMPG_THUMBNLR if config["thumbnailer_path"] == "" else config["thumbnailer_path"]
HIDE_HIDDEN_FILES = True if config["hide_hidden_files"] == "true" else False
go_past_home = True if config["go_past_home"] == "" else config["go_past_home"]
lock_folder = True if config["lock_folder"] == "true" else False
locked_folders = config["locked_folders"].split("::::")
mplayer_options = config["mplayer_options"].split()
music_app = config["music_app"]
media_app = config["media_app"]
image_app = config["image_app"]
office_app = config["office_app"]
pdf_app = config["pdf_app"]
code_app = config["code_app"]
text_app = config["text_app"]
terminal_app = config["terminal_app"]
container_icon_wh = config["container_icon_wh"]
video_icon_wh = config["video_icon_wh"]
sys_icon_wh = config["sys_icon_wh"]
file_manager_app = config["file_manager_app"]
remux_folder_max_disk_usage = config["remux_folder_max_disk_usage"]
# Filters
filters = settings["filters"]
fcode = tuple(filters["code"])
fvideos = tuple(filters["videos"])
foffice = tuple(filters["office"])
fimages = tuple(filters["images"])
ftext = tuple(filters["text"])
fmusic = tuple(filters["music"])
fpdf = tuple(filters["pdf"])

View File

@ -17,84 +17,84 @@ def threaded(fn):
class IPCServer:
""" Create a listener so that other SolarFM instances send requests back to existing instance. """
def __init__(self, conn_type: str = "socket"):
self.is_ipc_alive = False
self._conn_type = conn_type
self.ipc_port = 4848
self.ipc_address = '127.0.0.1'
self.ipc_authkey = b'solarfm-ipc'
self.ipc_timeout = 15.0
def __init__(self, ipc_address: str = '127.0.0.1', conn_type: str = "socket"):
self.is_ipc_alive = False
self._ipc_port = 4848
self._ipc_address = ipc_address
self._conn_type = conn_type
self._ipc_authkey = b'solarfm-ipc'
self._ipc_timeout = 15.0
if conn_type == "socket":
self.ipc_address = '/tmp/solarfm-ipc.sock'
self._ipc_address = '/tmp/solarfm-ipc.sock'
elif conn_type == "full_network":
self.ipc_address = '0.0.0.0'
self._ipc_address = '0.0.0.0'
elif conn_type == "full_network_unsecured":
self.ipc_authkey = None
self.ipc_address = '0.0.0.0'
self._ipc_authkey = None
self._ipc_address = '0.0.0.0'
elif conn_type == "local_network_unsecured":
self.ipc_authkey = None
self._ipc_authkey = None
@threaded
def create_ipc_server(self) -> None:
def create_ipc_listener(self) -> None:
if self._conn_type == "socket":
if os.path.exists(self.ipc_address):
if os.path.exists(self._ipc_address):
return
listener = Listener(address=self.ipc_address, family="AF_UNIX", authkey=self.ipc_authkey)
elif "unsecured" not in conn_type:
listener = Listener((self.ipc_address, self.ipc_port), authkey=self.ipc_authkey)
listener = Listener(address=self._ipc_address, family="AF_UNIX", authkey=self._ipc_authkey)
elif "unsecured" not in self._conn_type:
listener = Listener((self._ipc_address, self._ipc_port), authkey=self._ipc_authkey)
else:
listener = Listener((self.ipc_address, self.ipc_port))
listener = Listener((self._ipc_address, self._ipc_port))
self.is_ipc_alive = True
while True:
conn = listener.accept()
start_time = time.perf_counter()
print(f"New Connection: {listener.last_accepted}")
while True:
msg = conn.recv()
if debug:
print(msg)
if "FILE|" in msg:
file = msg.split("FILE|")[1].strip()
if file:
event_system.push_gui_event([None, "handle_file_from_ipc", (file,)])
conn.close()
break
if msg == 'close connection':
conn.close()
break
if msg == 'close server':
conn.close()
break
# NOTE: Not perfect but insures we don't lock up the connection for too long.
end_time = time.perf_counter()
if (end - start) > self.ipc_timeout:
conn.close()
self.handle_message(conn, start_time)
listener.close()
def handle_message(self, conn, start_time) -> None:
while True:
msg = conn.recv()
if debug:
print(msg)
if "FILE|" in msg:
file = msg.split("FILE|")[1].strip()
if file:
event_system.push_gui_event([None, "handle_file_from_ipc", (file,)])
conn.close()
break
if msg in ['close connection', 'close server']:
conn.close()
break
# NOTE: Not perfect but insures we don't lock up the connection for too long.
end_time = time.perf_counter()
if (end_time - start_time) > self._ipc_timeout:
conn.close()
break
def send_ipc_message(self, message: str = "Empty Data...") -> None:
try:
if self._conn_type == "socket":
conn = Client(address=self.ipc_address, family="AF_UNIX", authkey=self.ipc_authkey)
elif "unsecured" not in conn_type:
conn = Client((self.ipc_address, self.ipc_port), authkey=self.ipc_authkey)
conn = Client(address=self._ipc_address, family="AF_UNIX", authkey=self._ipc_authkey)
elif "unsecured" not in self._conn_type:
conn = Client((self._ipc_address, self._ipc_port), authkey=self._ipc_authkey)
else:
conn = Client((self.ipc_address, self.ipc_port))
conn = Client((self._ipc_address, self._ipc_port))
conn.send(message)
conn.send('close connection')
conn.close()
except ConnectionRefusedError as e:
print("Connection refused...")
except Exception as e:
print(repr(e))