21
21
import queue
22
22
import requests
23
23
import threading
24
- import webbrowser
25
- from pathlib import Path
24
+ import asyncio
26
25
from ctypes import c_int
27
26
from babble_model_loader import *
28
27
from camera_widget import CameraWidget
29
28
from config import BabbleConfig
30
- from tab import CamInfo , Tab
29
+ from tab import Tab
31
30
from osc import VRChatOSCReceiver , VRChatOSC
32
31
from general_settings_widget import SettingsWidget
33
32
from algo_settings_widget import AlgoSettingsWidget
34
33
from calib_settings_widget import CalibSettingsWidget
34
+ from notification_manager import NotificationManager
35
35
from utils .misc_utils import EnsurePath , is_nt , bg_color_highlight , bg_color_clear
36
36
from lang_manager import LocaleStringManager as lang
37
- from desktop_notifier import DesktopNotifierSync , Urgency , Button , Icon , DEFAULT_SOUND
38
37
39
38
winmm = None
40
39
60
59
ALGO_SETTINGS_RADIO_NAME = "-ALGOSETTINGSRADIO-"
61
60
CALIB_SETTINGS_RADIO_NAME = "-CALIBSETTINGSRADIO-"
62
61
63
- page_url = "https://github.com/SummerSigh /ProjectBabble/releases/latest"
62
+ page_url = "https://github.com/Project-Babble /ProjectBabble/releases/latest"
64
63
appversion = "Babble v2.0.7"
65
64
66
65
def timerResolution (toggle ):
@@ -73,26 +72,29 @@ def timerResolution(toggle):
73
72
else :
74
73
winmm .timeEndPeriod (1 )
75
74
76
- def send_notification (latestversion ):
77
- logo = Icon (
78
- path = Path (os .path .join (os .getcwd (), "Images" , "logo.ico" ))
79
- )
80
- notifier = DesktopNotifierSync (app_name = "Babble App" )
81
- notifier .send (
82
- title = lang ._instance .get_string ("babble.updatePresent" ),
83
- message = f'{ lang ._instance .get_string ("babble.updateTo" )} { latestversion } ' ,
84
- urgency = Urgency .Normal ,
85
- buttons = [
86
- Button (
87
- title = lang ._instance .get_string ("babble.downloadPage" ),
88
- on_pressed = lambda : webbrowser .open ("https://github.com/SummerSigh/ProjectBabble/releases/latest" ),
75
+ async def check_for_updates (config , notification_manager ):
76
+ if config .settings .gui_update_check :
77
+ try :
78
+ response = requests .get (
79
+ "https://api.github.com/repos/Project-Babble/ProjectBabble/releases/latest"
89
80
)
90
- ],
91
- icon = logo ,
92
- sound = DEFAULT_SOUND
93
- )
81
+ latestversion = response .json ()["name" ]
94
82
95
- def main ():
83
+ if appversion == latestversion :
84
+ print (
85
+ f'\033 [92m[{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("babble.latestVersion" )} ! [{ latestversion } ]\033 [0m'
86
+ )
87
+ else :
88
+ print (
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'
90
+ )
91
+ await notification_manager .show_notification (appversion , latestversion , page_url )
92
+ except Exception as e :
93
+ print (
94
+ f'[{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("babble.noInternet" )} . Error: { e } '
95
+ )
96
+
97
+ async def async_main ():
96
98
EnsurePath ()
97
99
98
100
# Get Configuration
@@ -102,10 +104,15 @@ def main():
102
104
lang ("Locale" , config .settings .gui_language )
103
105
104
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 )
105
113
106
114
cancellation_event = threading .Event ()
107
115
ROSC = False
108
- # Check to see if we can connect to our video source first. If not, bring up the camera dialog.
109
116
110
117
if config .settings .gui_update_check :
111
118
try :
@@ -124,10 +131,11 @@ def main():
124
131
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'
125
132
)
126
133
try :
127
- send_notification (latestversion )
134
+ # Run notification in a separate thread to avoid blocking
135
+ await notification_manager .show_notification (latestversion )
128
136
except Exception as e :
129
137
print (
130
- f'[{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("babble.noToast" )} '
138
+ f'[{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("babble.noToast" )} Error: { e } '
131
139
)
132
140
except Exception as e :
133
141
print (
@@ -136,13 +144,9 @@ def main():
136
144
137
145
timerResolution (True )
138
146
139
- # At this, check to see if we have an ROI. If not, bring up ROI finder GUI.
140
-
141
- # Spawn worker threads
142
147
osc_queue : queue .Queue [tuple [bool , int , int ]] = queue .Queue (maxsize = 10 )
143
148
osc = VRChatOSC (cancellation_event , osc_queue , config )
144
149
osc_thread = threading .Thread (target = osc .run )
145
- # start worker threads
146
150
osc_thread .start ()
147
151
148
152
cams = [
@@ -243,7 +247,6 @@ def main():
243
247
244
248
tint = 33
245
249
fs = False
246
- # GUI Render loop
247
250
while True :
248
251
# First off, check for any events from the GUI
249
252
event , values = window .read (timeout = tint )
@@ -352,8 +355,12 @@ def main():
352
355
for setting in settings :
353
356
if setting .started ():
354
357
setting .render (window , event , values )
355
-
358
+
359
+ # Does adding this help?
360
+ # await asyncio.sleep(0)
361
+
362
+ def main ():
363
+ asyncio .run (async_main ())
356
364
357
365
if __name__ == "__main__" :
358
366
main ()
359
-
0 commit comments