From a7d56bae10dee21ac6e28de2fa5ad797b2b7d7d4 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Tue, 27 Jul 2021 17:46:56 -0500 Subject: [PATCH] Updated view logic --- src/core/routes/Routes.py | 14 ++++++++++++-- src/core/utils/shellfm/windows/View.py | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/core/routes/Routes.py b/src/core/routes/Routes.py index 7eb6589..f0e917b 100644 --- a/src/core/routes/Routes.py +++ b/src/core/routes/Routes.py @@ -17,7 +17,10 @@ window_controllers = {} def get_window_controller(): - if session.get('win_controller_id') is None: + controller = None + try: + controller = window_controllers[ session["win_controller_id"] ] + except Exception as e: id = secrets.token_hex(16) controller = WindowController() view = controller.get_window(1).get_view(0) @@ -28,8 +31,9 @@ def get_window_controller(): session['win_controller_id'] = id window_controllers.update( {id: controller } ) + controller = window_controllers[ session["win_controller_id"] ] - return window_controllers[ session["win_controller_id"] ] + return controller @app.route('/', methods=['GET', 'POST']) @@ -68,6 +72,12 @@ def listFiles(_hash = None): path = view.get_path_part_from_hash(_hash) view.push_to_path(path) + error_msg = view.get_error_message() + if error_msg != None: + view.unset_error_message() + return msgHandler.createMessageJSON("danger", error_msg) + + sub_path = view.get_current_sub_path() files = view.get_files_formatted() fave = db.session.query(Favorites).filter_by(link = sub_path).first() diff --git a/src/core/utils/shellfm/windows/View.py b/src/core/utils/shellfm/windows/View.py index 9ed9b7d..2a37a5f 100644 --- a/src/core/utils/shellfm/windows/View.py +++ b/src/core/utils/shellfm/windows/View.py @@ -9,8 +9,8 @@ from os.path import isdir, isfile, join # Application imports -from . import Path, Settings, Launcher - +from .utils import Settings, Launcher +from . import Path class View(Settings, Launcher, Path): def __init__(self): @@ -20,6 +20,7 @@ class View(Settings, Launcher, Path): self.images = [] self.desktop = [] self.ungrouped = [] + self.error_message = None self.set_to_home() @@ -33,7 +34,7 @@ class View(Settings, Launcher, Path): self.files = [] if not isdir(path): - self.set_to_home() + self._set_error_message("Path can not be accessed.") return "" for f in listdir(path): @@ -120,6 +121,15 @@ class View(Settings, Launcher, Path): return False + def _set_error_message(self, text): + self.error_message = text + + def unset_error_message(self): + self.error_message = None + + def get_error_message(self): + return self.error_message + def get_current_directory(self): return self.get_path()