Skip to content

Commit

Permalink
Merge pull request #248 from pieces-app/add-command-runner
Browse files Browse the repository at this point in the history
Add command runner
  • Loading branch information
bishoy-at-pieces authored Jan 16, 2025
2 parents b6ba0b4 + c826c54 commit 35cb069
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
13 changes: 9 additions & 4 deletions misc/open_pieces_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ def run(self):
sublime.set_timeout_async(self.run_async)

@staticmethod
def run_async():
def run_async() -> bool:
if PiecesSettings.api_client.is_pieces_running():
return sublime.status_message("PiecesOS is already running")
sublime.status_message("PiecesOS is already running")
return False
view = sublime.active_window().active_view()
view.set_status("OPEN_STATUS","Opening PiecesOS") if view else None
if PiecesSettings.api_client.open_pieces_os():
view.erase_status("OPEN_STATUS") if view else None
sublime.status_message("PiecesOS launched successfully")
sublime.run_command("pieces_reload")
else:
return True
else:
view.erase_status("OPEN_STATUS") if view else None
sublime.status_message("Unable to launch PiecesOS")
sublime.status_message("Unable to launch PiecesOS")
if sublime.ok_cancel_dialog("PiecesOS could not be launched. Would you like to install it?"):
sublime.active_window().run_command("pieces_install_pieces_os")
return False
1 change: 1 addition & 0 deletions misc/reload_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def run(self):
def reload_async(self):
if PiecesSettings.api_client.is_pieces_running():
try:
PiecesSettings.api_client._startup() # Running the startup command
PiecesSettings.on_settings_change(all = True)
sublime.status_message(f"Reloading [completed]")
except Exception as e:
Expand Down
8 changes: 7 additions & 1 deletion startup_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ._pieces_lib.pieces_os_client.wrapper.version_compatibility import UpdateEnum, VersionChecker
from ._pieces_lib.pieces_os_client.wrapper.websockets.health_ws import HealthWS
from .settings import PiecesSettings
from .misc import PiecesOpenPiecesCommand
import sublime
from functools import wraps

Expand Down Expand Up @@ -71,9 +72,14 @@ def run_async():
if r == sublime.DIALOG_NO:
return sublime.run_command("pieces_support",args={"support":"https://docs.pieces.app/support"})
elif r == sublime.DIALOG_YES:
return sublime.run_command("pieces_open_pieces")
return sublime.set_timeout_async(lambda:open_pieces_async(func=func,*args,**kwargs))
print("Make sure PiecesOS is running")

return wrapper
return decorator

def open_pieces_async(func, *args, **kwargs):
running = PiecesOpenPiecesCommand.run_async()
if running:
func(*args, **kwargs)

0 comments on commit 35cb069

Please sign in to comment.