-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
71 lines (54 loc) · 2.3 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from . import __version__
from .settings import PiecesSettings
from .copilot.ask_command import copilot
import sublime
from ._pieces_lib.pieces_os_client.wrapper.version_compatibility import UpdateEnum
from ._pieces_lib.pieces_os_client.wrapper.websockets import (
BaseWebsocket,
AuthWS,HealthWS,
ConversationWS,
AssetsIdentifiersWS)
from .startup_utils import check_compatiblity
# load the commands
from .assets import *
from .ask import *
from .auth import *
from .search import *
from .misc import *
from .copilot import *
def startup():
version_check = check_compatiblity()
if not version_check.compatible:
plugin_name = "Pieces OS" if version_check.update == UpdateEnum.PiecesOS else "Pieces for Sublime"
print(f"'{plugin_name}' is out of date. Please update to the latest version to ensure full functionality.")
BaseWebsocket.close_all()
return
print(f"Pieces OS version: {PiecesSettings.api_client.version}\nPlugin version: {__version__}")
PiecesSettings.models_init(PiecesSettings.get_settings().get('model')) # Intilize the models
ConversationWS(PiecesSettings.api_client)
AssetsIdentifiersWS(PiecesSettings.api_client)
AuthWS(PiecesSettings.api_client,PiecesSettings.api_client.user.on_user_callback)
BaseWebsocket.start_all()
# 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():
# Use the auth callback instead of the default one in the client
PiecesSettings.api_client.user.on_user_callback = AuthUser.on_user_callback
settings = PiecesSettings.get_settings()
host = settings.get("host")
PiecesSettings.host_init(host) # Intilize the hosts url
# callbacks needed onchange settings
PiecesSettings.on_model_change_callbacks.append(copilot.update_status_bar)
health_ws = HealthWS(PiecesSettings.api_client, lambda x:startup())
health = PiecesSettings.api_client.is_pieces_running()
if PiecesSettings.get_settings().get("auto_start_pieces_os"):
health = PiecesSettings.api_client.open_pieces_os()
if health:
health_ws.start()
else:
print("Please make sure Pieces OS is running")
BaseWebsocket.close_all()
def plugin_unloaded():
BaseWebsocket.close_all()