19
19
from appdirs import user_data_dir
20
20
from bs4 import BeautifulSoup
21
21
import logging
22
+ import urllib .request
23
+ import time
24
+
22
25
logging .basicConfig (level = logging .INFO ,
23
26
format = '%(asctime)s - %(levelname)s - %(message)s' )
24
27
@@ -39,6 +42,30 @@ def __init__(self):
39
42
self .app_name = "Vince"
40
43
self .settings = self .load_settings ()
41
44
self .current_events = []
45
+ self .creds = None
46
+
47
+
48
+ def _has_internet (self ):
49
+
50
+ try :
51
+ urllib .request .urlopen ("https://www.google.com" )
52
+ return True
53
+ except urllib .error .URLError :
54
+ return False
55
+ @rumps .timer (5 )
56
+ def _load (self ,_ ):
57
+ if self .creds :
58
+ return
59
+ if not self ._has_internet ():
60
+ print (f"Waiting for internet ... " )
61
+ self .title = "Waiting for internet ... "
62
+ quit_btn = rumps .MenuItem ("Quit" )
63
+ quit_btn .set_callback (self .quit )
64
+ self .menu .clear ()
65
+ self .menu .add (quit_btn )
66
+ return
67
+
68
+
42
69
43
70
data_dir = user_data_dir (self .app_name )
44
71
file_path = os .path .join (data_dir , "token.json" )
@@ -69,6 +96,8 @@ def __init__(self):
69
96
70
97
@rumps .timer (90 * 5 )
71
98
def timely_load_events (self , _ ):
99
+ if not self .creds :
100
+ return
72
101
self .load_events ()
73
102
74
103
def load_events (self ):
@@ -199,21 +228,29 @@ def build_menu(self):
199
228
self .menu .add (quit_btn )
200
229
201
230
def open_browser (self , sender ):
231
+ print (self .settings .get ('app_meet' ,"" ))
202
232
if self .settings ['link_opening_enabled' ]:
203
233
for url in sender .urls :
234
+ if app_meet := self .settings .get ('app_meet' ,"" ):
235
+ if url .startswith ("https://meet.google.com" ):
236
+ cmd = fr"open -a { app_meet } "
237
+ print (cmd )
238
+ os .system (cmd )
239
+ return
240
+
204
241
webbrowser .open (url )
205
242
206
243
@rumps .clicked ("Refresh Menu" )
207
244
def refresh_menu (self , _ ):
208
245
self .load_events ()
209
246
self .build_menu ()
210
247
self .update_exiting_events (None )
211
-
212
-
213
248
214
249
215
250
@rumps .timer (61 )
216
251
def update_exiting_events (self , _ ):
252
+ if not self .creds :
253
+ return
217
254
# every 60 seconds remove the events that are past.
218
255
current_datetime = datetime .now (pytz .utc )
219
256
res = []
@@ -276,6 +313,8 @@ def _get_next_events(self):
276
313
277
314
@rumps .timer (1 )
278
315
def update_bar_str (self , _ ):
316
+ if not self .creds :
317
+ return
279
318
if self .settings ['show_menu_bar' ]:
280
319
# updates the bar
281
320
if self .menu_items :
@@ -347,13 +386,15 @@ def _str_event_menu_next(self, element):
347
386
if element :
348
387
hours , minutes = self ._time_left (
349
388
element ['start' ], current_datetime )
350
- title + = f" [{ element ['summary' ][:20 ]} in { hours :02d} :{ minutes :02d} ]"
389
+ title = f" [{ element ['summary' ][:20 ]} in { hours :02d} :{ minutes :02d} ]"
351
390
return title
352
391
else :
353
392
return ""
354
393
355
394
@rumps .timer (1 )
356
395
def send_notification_ (self , _ ):
396
+ if not self .creds :
397
+ return
357
398
if self .settings ['notifications' ]:
358
399
359
400
if self .menu_items :
@@ -385,6 +426,8 @@ def send_notification_(self, _):
385
426
386
427
@rumps .timer (1 )
387
428
def send_and_open_link (self , _ ):
429
+ if not self .creds :
430
+ return
388
431
if self .settings ['link_opening_enabled' ]:
389
432
# 1 min beofre the meeting it opens the browser with the link
390
433
# you can't miss it.
@@ -409,9 +452,6 @@ def send_and_open_link(self, _):
409
452
@rumps .clicked ("Quit" )
410
453
def quit (self , _ ):
411
454
print ('over' )
412
- data_dir = user_data_dir (self .app_name )
413
- file_path = os .path .join (data_dir , "token.json" )
414
- os .remove (file_path )
415
455
rumps .quit_application ()
416
456
417
457
def _convert_minutes_to_epoch (self , mins ):
@@ -481,6 +521,7 @@ def load_settings(self):
481
521
"calendars" : ["primary" ],
482
522
"link_opening_enabled" : True ,
483
523
"show_menu_bar" : True ,
524
+ "app_meet" :"" ,
484
525
"notifications" : [
485
526
{
486
527
"time_left" : 5 ,
0 commit comments