-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (43 loc) · 1.35 KB
/
Copy pathmain.py
File metadata and controls
56 lines (43 loc) · 1.35 KB
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
import os
from PIL import Image
from pystray import Icon, Menu, MenuItem
from utilities.autostart import Autostart
from utilities.device_listener import DeviceListener
from utilities.notification import Notification
from utilities.path import get_icon_path, get_name
from utilities.storage import Storage
class Tray:
__instance = None
def __new__(cls, *args, **kwargs):
if cls.__instance is None:
cls.__instance = super().__new__(cls, *args, **kwargs)
cls.__instance._init()
return cls.__instance
def _init(self):
self.length_sync = -1
self.icon = Icon(
name=get_name(),
icon=Image.open(get_icon_path()),
title=get_name(),
menu=Menu(
MenuItem("Open", self.start_app),
MenuItem("Sync now", self.sync_now),
MenuItem("Close", self.exit),
),
)
Autostart().update()
def sync_now(self):
Storage().sync_all()
Notification().notify(
"Sync", f"Syncs {Storage().number_of_valid_syncs()} folders."
)
def run(self):
DeviceListener(self.sync_now).start()
self.icon.run()
def exit(self):
os._exit(0)
def start_app(self):
from app import App
App().run()
if __name__ == "__main__":
Tray().run()