21
21
import queue
22
22
import requests
23
23
import threading
24
- from ctypes import windll , c_int
24
+ import asyncio
25
+ from ctypes import c_int
25
26
from babble_model_loader import *
26
27
from camera_widget import CameraWidget
27
28
from config import BabbleConfig
28
- from tab import CamInfo , Tab
29
+ from tab import Tab
29
30
from osc import VRChatOSCReceiver , VRChatOSC
30
31
from general_settings_widget import SettingsWidget
31
32
from algo_settings_widget import AlgoSettingsWidget
32
33
from calib_settings_widget import CalibSettingsWidget
34
+ from notification_manager import NotificationManager
33
35
from utils .misc_utils import EnsurePath , is_nt , bg_color_highlight , bg_color_clear
34
36
from lang_manager import LocaleStringManager as lang
35
37
36
38
winmm = None
37
39
38
40
if is_nt :
39
- from winotify import Notification
40
41
try :
42
+ from ctypes import windll
41
43
winmm = windll .winmm
42
44
except OSError :
43
45
print (f'\033 [91m[{ lang ._instance .get_string ("log.error" )} ] { lang ._instance .get_string ("error.winmm" )} .\033 [0m' )
57
59
ALGO_SETTINGS_RADIO_NAME = "-ALGOSETTINGSRADIO-"
58
60
CALIB_SETTINGS_RADIO_NAME = "-CALIBSETTINGSRADIO-"
59
61
60
- page_url = "https://github.com/SummerSigh /ProjectBabble/releases/latest"
62
+ page_url = "https://github.com/Project-Babble /ProjectBabble/releases/latest"
61
63
appversion = "Babble v2.0.7"
62
64
63
65
def timerResolution (toggle ):
@@ -70,69 +72,53 @@ def timerResolution(toggle):
70
72
else :
71
73
winmm .timeEndPeriod (1 )
72
74
73
- def main ():
74
- EnsurePath ()
75
-
76
- # Get Configuration
77
- config : BabbleConfig = BabbleConfig .load ()
78
-
79
- # Init locale manager
80
- lang ("Locale" , config .settings .gui_language )
81
-
82
- config .save ()
83
-
84
- cancellation_event = threading .Event ()
85
- ROSC = False
86
- # Check to see if we can connect to our video source first. If not, bring up camera finding
87
- # dialog.
88
-
75
+ async def check_for_updates (config , notification_manager ):
89
76
if config .settings .gui_update_check :
90
77
try :
91
78
response = requests .get (
92
- "https://api.github.com/repos/SummerSigh /ProjectBabble/releases/latest"
79
+ "https://api.github.com/repos/Project-Babble /ProjectBabble/releases/latest"
93
80
)
94
81
latestversion = response .json ()["name" ]
95
- if (
96
- appversion == latestversion
97
- ): # If what we scraped and hardcoded versions are same, assume we are up to date.
82
+
83
+ if appversion == latestversion :
98
84
print (
99
85
f'\033 [92m[{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("babble.latestVersion" )} ! [{ latestversion } ]\033 [0m'
100
86
)
101
87
else :
102
88
print (
103
89
f'\033 [93m[{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("babble.needUpdateOne" )} [{ appversion } ] { lang ._instance .get_string ("babble.needUpdateTwo" )} [{ latestversion } ] { lang ._instance .get_string ("babble.needUpdateThree" )} .\033 [0m'
104
90
)
105
- try :
106
- if is_nt :
107
- cwd = os .getcwd ()
108
- icon = cwd + "\Images\logo.ico"
109
- toast = Notification (
110
- app_id = lang ._instance .get_string ("babble.name" ),
111
- title = lang ._instance .get_string ("babble.updatePresent" ),
112
- msg = f'{ lang ._instance .get_string ("babble.updateTo" )} { latestversion } ' ,
113
- icon = r"{}" .format (icon ),
114
- )
115
- toast .add_actions (
116
- label = lang ._instance .get_string ("babble.downloadPage" ),
117
- launch = "https://github.com/SummerSigh/ProjectBabble/releases/latest" ,
118
- )
119
- toast .show ()
120
- except Exception as e :
121
- print (
122
- f'[{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("babble.noToast" )} '
123
- )
124
- except :
91
+ await notification_manager .show_notification (appversion , latestversion , page_url )
92
+ except Exception as e :
125
93
print (
126
- f'[{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("babble.noInternet" )} .'
94
+ f'[{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("babble.noInternet" )} . Error: { e } '
127
95
)
96
+
97
+ async def async_main ():
98
+ EnsurePath ()
99
+
100
+ # Get Configuration
101
+ config : BabbleConfig = BabbleConfig .load ()
102
+
103
+ # Init locale manager
104
+ lang ("Locale" , config .settings .gui_language )
105
+
106
+ config .save ()
107
+
108
+ notification_manager = NotificationManager ()
109
+ await notification_manager .initialize ()
110
+
111
+ # Run the update check
112
+ await check_for_updates (config , notification_manager )
113
+
114
+ cancellation_event = threading .Event ()
115
+ ROSC = False
116
+
128
117
timerResolution (True )
129
- # Check to see if we have an ROI. If not, bring up ROI finder GUI.
130
118
131
- # Spawn worker threads
132
119
osc_queue : queue .Queue [tuple [bool , int , int ]] = queue .Queue (maxsize = 10 )
133
120
osc = VRChatOSC (cancellation_event , osc_queue , config )
134
121
osc_thread = threading .Thread (target = osc .run )
135
- # start worker threads
136
122
osc_thread .start ()
137
123
138
124
cams = [
@@ -233,7 +219,6 @@ def main():
233
219
234
220
tint = 33
235
221
fs = False
236
- # GUI Render loop
237
222
while True :
238
223
# First off, check for any events from the GUI
239
224
event , values = window .read (timeout = tint )
@@ -342,7 +327,12 @@ def main():
342
327
for setting in settings :
343
328
if setting .started ():
344
329
setting .render (window , event , values )
345
-
330
+
331
+ # Does adding this help?
332
+ # await asyncio.sleep(0)
333
+
334
+ def main ():
335
+ asyncio .run (async_main ())
346
336
347
337
if __name__ == "__main__" :
348
338
main ()
0 commit comments