Skip to content

Commit 9479cdb

Browse files
committed
Port change function added and some translations fixed. Created a function named tryload to fix repetitive code lines.
1 parent a07d811 commit 9479cdb

File tree

7 files changed

+67
-28
lines changed

7 files changed

+67
-28
lines changed

main.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Description: Main file for the LockDown project
22
import webbrowser
33
from flask import Flask, render_template, request, redirect, url_for
4-
from modules.config import readAppConfig, updateAppConfig, loadLanguageFiles
4+
from modules.config import readAppConfig, updateAppConfig, loadLanguageFiles, tryLoad
55

66

77
app = Flask(__name__)
88
appcfg = readAppConfig()
9-
language = appcfg["app_language"]
9+
language = tryLoad("app_language")
1010
language_files = loadLanguageFiles(language)
11-
print(language_files)
12-
version = appcfg["app_version"]
13-
author = appcfg["app_author"]
11+
version = tryLoad("app_version")
12+
author = tryLoad("app_author")
13+
port = tryLoad("app_port")
1414

1515

1616
@app.route("/set_language", methods=["POST"])
@@ -38,6 +38,7 @@ def reset_everything():
3838

3939
appcfg["app_language"] = ""
4040
updateAppConfig("app_language", "")
41+
updateAppConfig("app_port", "4900")
4142
language_files = loadLanguageFiles("")
4243
language = ""
4344

@@ -57,6 +58,8 @@ def status():
5758

5859

5960
if __name__ == "__main__":
60-
webbrowser.open("http://localhost:4900/")
61-
app.run(debug=True, port=4900, host="0.0.0.0")
61+
appcfg = readAppConfig()
62+
app_port = tryLoad("app_port")
63+
webbrowser.open("http://localhost:" + str(app_port))
64+
app.run(debug=True, port=app_port, host="0.0.0.0")
6265

modules/config.py

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
11
import json
22

33

4+
# noinspection PyBroadException
5+
def tryLoad(key):
6+
appcfg = readAppConfig()
7+
try:
8+
data = appcfg[key]
9+
except:
10+
data = getDefaultConfig()[key]
11+
return data
12+
13+
14+
def getDefaultConfig():
15+
data = {
16+
"app_name": "FastCode.Ninja LockDown",
17+
"app_version": "0.0.1",
18+
"app_author": "Emir Tunahan Alim",
19+
"app_author_email": "emrtnhalim@gmail.com",
20+
"app_description": "Cross-platform multi-lingual screen locker app for computers and smart boards.",
21+
"github_user": "https://github.com/Eta06",
22+
"github_repo": "https://github.com/Eta06/LockDown",
23+
"app_license": "Apache License 2.0",
24+
"app_license_url": "https://github.com/Eta06/LockDown/blob/main/LICENSE",
25+
"app_language": "",
26+
"app_port": "4900"
27+
}
28+
return data
29+
30+
431
def readAppConfig():
532
try:
633
with open("appconfig.json", "r") as f:
734
data = json.load(f)
835
return data
936
except FileNotFoundError:
1037
with open("appconfig.json", "w") as f:
11-
data = {
12-
"app_name": "FastCode.Ninja LockDown",
13-
"app_version": "0.0.1",
14-
"app_author": "Emir Tunahan Alim",
15-
"app_author_email": "emrtnhalim@gmail.com",
16-
"app_description": "Cross-platform multi-lingual screen locker app for computers and smart boards.",
17-
"github_user": "https://github.com/Eta06",
18-
"github_repo": "https://github.com/Eta06/LockDown",
19-
"app_license": "Apache License 2.0",
20-
"app_license_url": "https://github.com/Eta06/LockDown/blob/main/LICENSE",
21-
"app_language": "",
22-
}
38+
data = getDefaultConfig()
2339
json.dump(data, f, indent=4)
2440
return data
2541

templates/index.html

+21-9
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154

155155
.tab-content {
156156
display: none;
157+
padding: 10px;
157158
}
158159

159160
.tab-content.active {
@@ -192,6 +193,9 @@
192193
}
193194

194195
.settings-card {
196+
display: flex;
197+
flex-direction: column;
198+
flex-wrap: nowrap;
195199
max-width: 550px;
196200
width: 70%;
197201
margin: 10px auto;
@@ -209,7 +213,11 @@
209213
border-radius: 5px;
210214
}
211215

212-
.reset-card button {
216+
.click-buttons:hover {
217+
background-color: #7a3131;
218+
}
219+
220+
.click-buttons {
213221
background-color: #F25D5D;
214222
color: #fff;
215223
padding: 5px 10px;
@@ -220,12 +228,8 @@
220228
margin-bottom: 20px;
221229
}
222230

223-
.reset-card button:hover {
224-
background-color: #7a3131;
225-
}
226-
227231
.reset-card p {
228-
margin-top: 10px;
232+
margin: 0 0 20px 0;
229233
font-size: 14px;
230234
}
231235

@@ -265,6 +269,9 @@
265269
.tabs {
266270
width: 90%; /* Set the width to 90% on mobile devices */
267271
}
272+
.settings-card{
273+
width: 90%;
274+
}
268275
}
269276
</style>
270277
</head>
@@ -300,19 +307,24 @@ <h1>{{ language_files.home }}</h1>
300307
<div class="settings-card language-card">
301308
<h3>{{ language_files.language }}</h3>
302309
<label>
303-
<select name="language">
310+
<select name="language" style="margin-bottom: 10px;">
304311
<option value="en">English</option>
305312
<option value="tr">Turkish</option>
306313
<option value="es">Spanish</option>
307314
<option value="ru">Russian</option>
308315
</select>
309316
</label>
310-
<button id="save-language">{{ language_files.save }}</button>
317+
<button class="click-buttons" id="save-language">{{ language_files.save }}</button>
311318
</div>
312319
<div class="settings-card reset-card">
313320
<h3>{{ language_files.reset }}</h3>
314321
<p>{{ language_files.resetinfo }}</p>
315-
<button id="confirm-reset">{{ language_files.reset }}</button>
322+
<button class="click-buttons" id="confirm-reset">{{ language_files.reset }}</button>
323+
</div>
324+
<div class="settings-card">
325+
<h3>{{ language_files.port }}</h3>
326+
<p>{{ language_files.portinfo }}</p>
327+
<input type="number" name="port" value="{{ port }}" min="1" max="65535" step="1">
316328
</div>
317329
</cardwidget>
318330
</div>

translations/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"reset": "Reset",
1616
"yesreset": "Yes, reset!",
1717
"areyousure": "Are you sure?",
18+
"port": "Server Port",
19+
"portinfo": "Port number to use for the application",
1820
"irreversibleAction": "This action cannot be undone!",
1921
"resetinfo": "Are you sure you want to reset all settings?",
2022
"infotext1": "This is the web UI for LockDown App.",

translations/es.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"reset": "Restablecer",
1616
"yesreset": "Si, restablecer!",
1717
"areyousure": "¿Está seguro?",
18+
"port": "Puerto del servidor",
19+
"portinfo": "Número de puerto para usar la aplicación",
1820
"irreversibleAction": "Esta acción no se puede deshacer!",
1921
"resetinfo": "¿Está seguro de que desea restablecer todas las configuraciones?",
2022
"infotext1": "Esta es la interfaz web de la aplicación LockDown.",

translations/ru.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"reset": "Сброс",
1616
"yesreset": "Да, сбросить!",
1717
"areyousure": "Вы уверены?",
18+
"port": "Порт сервера",
19+
"portinfo": "",
1820
"irreversibleAction": "Эта операция не может быть отменена!",
1921
"resetinfo": "Вы уверены, что хотите сбросить все настройки?",
2022
"infotext1": "Это веб-интерфейс приложения LockDown.",

translations/tr.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"reset": "Sıfırla",
1616
"yesreset": "Evet, sıfırla!",
1717
"areyousure": "Emin misiniz?",
18+
"port": "Sunucu Portu",
19+
"portinfo": "Uygulama için kullanılacak port numarasıdır. Varsayılan: 4900",
1820
"irreversibleAction": "Bu işlem geri alınamaz!",
1921
"resetinfo": "Tüm ayarları sıfırlamak istediğinizden emin misiniz?",
2022
"infotext1": "Bu, LockDown uygulamasının web arayüzüdür.",

0 commit comments

Comments
 (0)