Skip to content

Commit

Permalink
Merge pull request #102 from Bishoy-at-pieces/add-on-boarding
Browse files Browse the repository at this point in the history
Add onboarding
  • Loading branch information
bishoy-at-pieces authored Jul 3, 2024
2 parents fad161d + b74119e commit 702b35a
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"command": "pieces_create_asset",
},
{
"caption": "Generate Shareable link",
"caption": "Generate Shareable Link",
"command": "pieces_generate_shareable_link",
},
{
Expand Down
4 changes: 4 additions & 0 deletions Pieces.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"caption": "Pieces: Reload Plugin",
"command": "pieces_reload"
},
{
"caption": "Pieces: Launch Onboarding",
"command": "pieces_onboarding"
},
{
"caption": "Pieces: Copilot",
"command": "pieces_ask_stream"
Expand Down
6 changes: 3 additions & 3 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ def version_check():
print("Please update your Pieces Sublime Package is up-to-date. It is not compatible with the current Pieces OS version")
print()
print_version_details(pieces_os_version, __version__)
return False
return False,"the Pieces Sublime Package"
elif os_version_parsed < min_version_parsed:
print("Please update your Pieces OS. It is not compatible with the current package version")
print()
print_version_details(pieces_os_version, __version__)
return False
return True
return False,"Pieces OS"
return True,None

def print_version_details(pieces_os_version, __version__):
print(f"Pieces os version: {pieces_os_version}\nPlugin version: {__version__}")
1 change: 0 additions & 1 deletion ask/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* Many thanks to gitgutter! */
html.dark {
--popup-background: color(var(--background) blend(white 95%));
--pieces-toolbar-bg: color(var(--popup-background) blend(white 95%));
Expand Down
2 changes: 1 addition & 1 deletion copilot/ask_websocket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .._pieces_lib.pieces_os_client import QGPTStreamOutput,QGPTStreamInput
from websocket import WebSocketConnectionClosedException
from .._pieces_lib.websocket import WebSocketConnectionClosedException

from ..settings import PiecesSettings
from ..base_websocket import BaseWebsocket
Expand Down
25 changes: 23 additions & 2 deletions event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,35 @@

from .assets.list_assets import PiecesListAssetsCommand
from .settings import PiecesSettings
from .misc import PiecesOnboardingCommand
from .copilot.ask_command import copilot


class PiecesEventListener(sublime_plugin.EventListener):
commands_to_exclude = ["pieces_handle_markdown","pieces_reload","pieces_support"]
commands_to_exclude = ["pieces_onboarding","pieces_reload","pieces_support"]

onboarding_commands_dict = {
"pieces_create_asset":"create",
"pieces_list_assets":"open",
"pieces_ask_question":"ask",
"pieces_search":"search",
"pieces_ask_stream":"copilot",
"pieces_share_asset":"share"
}

def on_window_command(self, window, command_name, args):
self.check(command_name)
self.check_onboarding(command_name)

def on_text_command(self,view,command_name,args):
self.check(command_name)

self.check_onboarding(command_name)

if command_name == "paste": # To avoid pasting in the middle of the view of the copilot
self.on_query_context(view,"pieces_copilot_add",True,sublime.OP_EQUAL,True)


def check(self,command_name):
if command_name.startswith("pieces_") and command_name not in PiecesEventListener.commands_to_exclude: # Check any command
health = PiecesSettings.get_health()
Expand All @@ -26,6 +41,10 @@ def check(self,command_name):
return False
return None

def check_onboarding(self,command_name):
if command_name not in self.onboarding_commands_dict:
return
PiecesOnboardingCommand.add_onboarding_settings(**{self.onboarding_commands_dict[command_name] : True})

def on_pre_close(self,view):
sheet_id = view.settings().get("pieces_sheet_id")
Expand All @@ -42,7 +61,9 @@ def on_pre_close(self,view):
del view.settings()["pieces_sheet_id"]
return
sublime.active_window().run_command("pieces_list_assets",{"pieces_asset_id":asset_id})




def on_query_context(self,view,key, operator, operand, match_all):
if key == "save_pieces_asset":
return view.settings().get("pieces_sheet_id")
Expand Down
10 changes: 6 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,28 @@ def startup(settings_model):
if not pieces_version:
print("Couldn't start pieces os\nPlease run pieces os and restart the editor to ensure everything is running properly")
else:
if version_check():
if version_check()[0]:
PiecesSettings.is_loaded = True
PiecesSettings.get_application()
print_version_details(pieces_version, __version__)


PiecesSettings.models_init(settings_model) # Intilize the models


# WEBSOCKETS:
# Assets Identifiers Websocket
AssetsIdentifiersWS(AssetSnapshot.streamed_identifiers_callback).start() # Load the assets ws at the startup

# User Weboscket
PiecesSettings.create_auth_output_panel()

AuthWebsocket(AuthUser.on_user_callback).start() # Load the stream user websocket

# Conversation Websocket
ConversationWS(ConversationsSnapshot.streamed_identifiers_callback).start()

# Lunch Onboarding if it is the first time
if not PiecesOnboardingCommand.get_onboarding_settings().get("lunch_onboarding",False):
sublime.active_window().run_command("pieces_onboarding")
PiecesOnboardingCommand.add_onboarding_settings(lunch_onboarding=True)

def plugin_loaded():
global settings # Set it to global to use
Expand Down
1 change: 1 addition & 0 deletions misc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .reload_command import PiecesReloadCommand
from .open_pieces_command import PiecesOpenPiecesCommand
from .about_command import PiecesOpenNotesCommand,PiecesAboutCommand
from .onboarding_command import PiecesOnboardingCommand,PiecesOnboardingCommandsCommand,PiecesResetOnboardingCommand
Loading

0 comments on commit 702b35a

Please sign in to comment.