Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Commit de1122a

Browse files
authored
Update app.py
1 parent 0395501 commit de1122a

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

app.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
11
import rumps
2-
import sys
3-
import threading
2+
import getpass
3+
import os
4+
import requests
45

56
from utils.logger import Logger
67
from utils.note import Note
7-
from utils.resourcePath import resource_path
8+
9+
user_name = getpass.getuser()
10+
11+
def check_files():
12+
files = [
13+
"https://raw.githubusercontent.com/bentettmar/barnotes/main/data/icon.png",
14+
"https://raw.githubusercontent.com/bentettmar/barnotes/main/data/note.txt"
15+
]
16+
17+
if not os.path.exists(os.path.expanduser("~/Library/Application Support/BarNotes")):
18+
os.makedirs(os.path.expanduser("~/Library/Application Support/BarNotes"))
19+
20+
for file in files:
21+
if not os.path.exists(os.path.expanduser(f"~/Library/Application Support/BarNotes/{file.split('/')[-1]}")):
22+
r = requests.get(file)
23+
with open(os.path.expanduser(f"~/Library/Application Support/BarNotes/{file.split('/')[-1]}"), "wb") as f:
24+
f.write(r.content)
825

926
class BarNotes(rumps.App):
1027
def __init__(self):
11-
super(BarNotes, self).__init__("BarNotes", title=" " + Note.get_note(), icon="data/icon.png", quit_button=None)
28+
super(BarNotes, self).__init__("BarNotes", title=" " + Note.get_note(), icon=f"/users/{user_name}/Library/Application Support/BarNotes/icon.png")
1229

1330
self.logger = Logger()
1431
self.logger.log("BarNotes initialized")
1532

16-
self.menu = ["Edit Note", "Quit"]
33+
self.menu = ["Edit Note"]
1734

1835
@rumps.clicked("Edit Note")
1936
def edit(self, _):
2037
window = rumps.Window(title="Edit your note", message="The max amount of characters is 100.", dimensions=(300, 85), ok="Save", cancel="Cancel")
2138
window.default_text = Note.get_note()
22-
window.icon = "data/icon.png"
39+
window.icon = f"/users/{user_name}/Library/Application Support/BarNotes/icon.png"
2340

2441
self.logger.log("Edit Note window opened")
2542

@@ -31,16 +48,11 @@ def edit(self, _):
3148
elif response.clicked == 0:
3249
self.logger.log("Note was not changed")
3350

34-
@rumps.clicked("Quit")
35-
def close(self, _):
36-
self.logger.log("BarNotes quit")
37-
self.logger.close()
38-
rumps.quit_application()
39-
4051
def start(self):
4152
self.logger.log("BarNotes running")
4253
self.run()
4354

4455
if __name__ == "__main__":
56+
check_files()
4557
app = BarNotes()
46-
app.start()
58+
app.start()

0 commit comments

Comments
 (0)