Skip to content
This repository was archived by the owner on Mar 8, 2026. It is now read-only.

Commit 5310fbd

Browse files
committed
working settings page (yipperz)
1 parent ce4f884 commit 5310fbd

8 files changed

Lines changed: 340 additions & 20 deletions

File tree

main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from src.front.window import startUp as s
22
from src.back.system.history import History
3+
from src.back.system.settings import Settings
34

45
import argparse
56
import sys
@@ -10,6 +11,7 @@
1011

1112
debugMode = args.debug
1213
History().checkHistory()
14+
Settings().checkFile()
1315

1416
if __name__ == "__main__":
1517
s(debugMode=debugMode)

src/back/extra/settings.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"settings": {
3+
"checkForUpdates": {
4+
"name": "Check For Updates",
5+
"description": "Check for updates on startup. Reccomended to be enabled!",
6+
"type": "boolean",
7+
"default": "true"
8+
},
9+
10+
"history": {
11+
"name": "History",
12+
"description": "Always stores the sucsessful uploads in a json file.",
13+
"type": "boolean",
14+
"default": "true"
15+
},
16+
17+
"minimizeToTray": {
18+
"name": "Minimize To Tray",
19+
"description": "Minimizes the app to the system tray instead of closing it.",
20+
"type": "boolean",
21+
"default": "true"
22+
},
23+
24+
"notifyYou": {
25+
"name": "Notify You",
26+
"description": "Send you a notification when it's sending, when it's done and when it gives an error.",
27+
"type": "boolean",
28+
"default": "true"
29+
}
30+
}
31+
}

src/back/system/contact.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import webview
22
import os
33
import sys
4+
import json
45

56
from src.back.api.sendingFile import catbox, litterbox, buzzheavier
67
from src.back.api.checkForUpdate import isUpdateAvailable
78
from src.back.util.notify import notify
89
import src.back.util.print as print
10+
from src.back.system.settings import Settings
911

1012
class API:
1113
def pickFile(self):
@@ -60,4 +62,54 @@ def checkForUpdates(self):
6062
return isUpdateAvailable(currentVersion)
6163
except Exception as e:
6264
print.error(f"Network error: {e}")
63-
return {"status": "error", "message": f"Network error: {e}"}
65+
return {"status": "error", "message": f"Network error: {e}"}
66+
67+
def localCurrentVersion(self):
68+
try:
69+
if getattr(sys, 'frozen', False):
70+
basePath = sys._MEIPASS
71+
else:
72+
basePath = os.path.abspath(".")
73+
74+
versionPath = os.path.join(basePath, "version.txt")
75+
with open(versionPath, "r") as f:
76+
currentVersion = f.read().strip()
77+
return currentVersion
78+
except Exception as e:
79+
print.error(f"Local file error: {e}")
80+
return None
81+
82+
def getSettings(self):
83+
print.debug("API: getSettings called")
84+
try:
85+
settings = Settings()
86+
87+
# Load the settings definitions (names, descriptions)
88+
if os.path.exists(settings.defaultSettingsPath):
89+
with open(settings.defaultSettingsPath, "r") as f:
90+
data = json.load(f)
91+
print.success(f"Default settings loaded from: {settings.defaultSettingsPath}")
92+
else:
93+
print.error(f"Default settings MISSING at: {settings.defaultSettingsPath}")
94+
return {"settings": {}}
95+
96+
# Load the user's current saved settings
97+
user_settings = {}
98+
if os.path.exists(settings.settingsPath):
99+
with open(settings.settingsPath, "r") as f:
100+
user_settings = json.load(f)
101+
print.success(f"User settings loaded from: {settings.settingsPath}")
102+
103+
# Update the definitions with the user's values
104+
for key, value in data["settings"].items():
105+
if key in user_settings:
106+
data["settings"][key]["default"] = str(user_settings[key]).lower()
107+
108+
return data
109+
except Exception as e:
110+
print.error(f"Error fetching settings: {e}")
111+
return {"settings": {}}
112+
113+
def saveSettings(self, key, value):
114+
settings = Settings()
115+
return settings.updateSetting(key, value)

src/back/system/history.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
2222
"""
2323

24-
2524
import json
2625
import os
2726
import datetime
@@ -40,8 +39,8 @@ def checkHistory(self):
4039
print.success(f"History found at: {self.historyPath}")
4140
return True
4241
else:
43-
print.error(f"History not found at: {self.historyPath}")
44-
print.success(f"Creating history at: {self.historyPath}")
42+
print.warning(f"History not found at: {self.historyPath}")
43+
print.debug(f"Creating history at: {self.historyPath}")
4544

4645
try:
4746
se.checkFolder(self)
@@ -53,7 +52,7 @@ def checkHistory(self):
5352
print.error(f"Error creating history: {e}")
5453
return False
5554
except OSError as e:
56-
print.fatal(f"Fatal error creating history: {e}")
55+
print.fatal(f"Fatal OS error creating history: {e}")
5756
return False
5857

5958
def storeHistory(self, service, filename, link, litterboxdur):
@@ -72,5 +71,4 @@ def storeHistory(self, service, filename, link, litterboxdur):
7271

7372
return print.success(f"History stored at: {self.historyPath}")
7473
except Exception as e:
75-
return print.error(f"Error storing history: {e}")
76-
74+
return print.error(f"Error storing history: {e}")

src/back/system/settings.py

Lines changed: 118 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import os
2+
import json
3+
24
from sys import platform
5+
36
import src.back.util.print as print
47

58
appID = "dev.pages.codedave.SendYourFiles"
6-
configPath = ""
9+
710

811
class Sys:
912
def getOSpath(self):
@@ -12,22 +15,129 @@ def getOSpath(self):
1215
elif platform == "linux":
1316
configPath = os.path.join(os.getenv("XDG_CONFIG_HOME"), appID)
1417
elif platform == "darwin":
15-
configPath = os.path.join(os.getenv("HOME"), "Library", "Application Support", appID)
18+
configPath = os.path.join(
19+
os.getenv("HOME"), "Library", "Application Support", appID
20+
)
1621
else:
1722
configPath = os.path.join(os.getenv("HOME"), ".config", appID)
1823
print.debug(f"Config path: {configPath}")
1924
return configPath
2025

26+
2127
class Settings:
28+
def __init__(self):
29+
self.configPath = os.path.join(Sys.getOSpath(self))
30+
31+
self.settingsPath = os.path.join(self.configPath, "settings.json")
32+
self.defaultSettingsPath = os.path.join(os.path.dirname(__file__), "extra", "settings.json")
33+
34+
if not os.path.exists(self.defaultSettingsPath):
35+
# Fallback for running from root
36+
self.defaultSettingsPath = os.path.abspath(os.path.join("src", "back", "extra", "settings.json"))
37+
38+
self.defaultSettings = {}
39+
self.settings = {}
40+
41+
# passing through
42+
self.readSet = self.ReadSettings(self.settingsPath)
43+
2244
def checkFolder(self):
23-
configPath = Sys.getOSpath(self)
24-
if not os.path.exists(configPath):
45+
if os.path.exists(self.configPath):
46+
print.success(f"Config path found at: {self.configPath}")
47+
return True
48+
else:
49+
print.warning(f"Config path not found at: {self.configPath}")
50+
print.debug(f"Creating config path at: {self.configPath}")
51+
2552
try:
26-
os.makedirs(configPath)
27-
print.success(f"Created config path: {configPath}")
53+
os.makedirs(self.configPath)
54+
print.success(f"Config path created at: {self.configPath}")
55+
return True
2856
except Exception as e:
2957
print.error(f"Error creating config path: {e}")
58+
return False
3059
except OSError as e:
31-
print.fatal(f"Fatal error creating config path: {e}")
60+
print.fatal(f"Fatal OS error creating config path: {e}")
61+
return False
62+
63+
def checkFile(self):
64+
if os.path.exists(self.settingsPath):
65+
print.success(f"Settings found at: {self.settingsPath}")
66+
return True
3267
else:
33-
print.debug(f"Config path already exists: {configPath}")
68+
print.warning(f"Settings not found at: {self.settingsPath}")
69+
print.debug(f"Creating settings file at: {self.settingsPath}")
70+
71+
try:
72+
with open(self.settingsPath, "w") as f:
73+
with open(self.defaultSettingsPath, "r") as f2:
74+
data = json.load(f2)
75+
newSettings = {}
76+
for key, value in data["settings"].items():
77+
val = value["default"]
78+
if value.get("type") == "boolean":
79+
if str(val).lower() == "true":
80+
val = True
81+
elif str(val).lower() == "false":
82+
val = False
83+
newSettings[key] = val
84+
json.dump(newSettings, f, indent=4)
85+
print.success(f"Settings created at: {self.settingsPath}")
86+
return True
87+
except Exception as e:
88+
print.error(f"Error creating settings: {e}")
89+
return False
90+
except OSError as e:
91+
print.fatal(f"Fatal OS error creating settings: {e}")
92+
return False
93+
94+
def updateSetting(self, key, value):
95+
try:
96+
data = {}
97+
if os.path.exists(self.settingsPath):
98+
with open(self.settingsPath, "r") as f:
99+
data = json.load(f)
100+
101+
data[key] = value
102+
103+
with open(self.settingsPath, "w") as f:
104+
json.dump(data, f, indent=4)
105+
return True
106+
except Exception as e:
107+
print.error(f"Error updating setting: {e}")
108+
return False
109+
110+
class ReadSettings:
111+
def __init__(self, path):
112+
self.settingPath = path
113+
114+
def _checkForUpdates(self):
115+
try:
116+
with open(self.settingPath, "r") as f:
117+
return json.load(f).get("checkForUpdates", True)
118+
except Exception:
119+
pass
120+
121+
def _history(self):
122+
try:
123+
with open(self.settingPath, "r") as f:
124+
return json.load(f).get("history", True)
125+
except Exception:
126+
pass
127+
return True
128+
129+
def _minimizeToTray(self):
130+
try:
131+
with open(self.settingPath, "r") as f:
132+
return json.load(f).get("minimizeToTray", True)
133+
except Exception:
134+
pass
135+
return True
136+
137+
def _notifyYou(self):
138+
try:
139+
with open(self.settingPath, "r") as f:
140+
return json.load(f).get("notifyYou", True)
141+
except Exception:
142+
pass
143+
return True

src/front/main/css/cacaStyle.css

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,28 @@ body {
9696
user-select: text;
9797
-webkit-user-select: text;
9898
cursor: text;
99-
}
99+
}
100+
101+
select {
102+
background-color: var(--frameColor);
103+
color: var(--textColor);
104+
105+
border: none;
106+
padding: 5px 10px;
107+
border-radius: 5px;
108+
width: 100%;
109+
margin-top: 10px;
110+
111+
outline: none;
112+
cursor: pointer;
113+
114+
font-family: inherit;
115+
}
116+
117+
option {
118+
border-radius: 5px;
119+
border: none;
120+
121+
background-color: var(--frameColor);
122+
color: var(--textColor);
123+
}

0 commit comments

Comments
 (0)