Skip to content

Commit

Permalink
Removing singleton from Settings. We do not need the Settings in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeubas committed Sep 4, 2024
1 parent 129fc19 commit 3d316d5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion i18n/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def bake_translations():
with open(filepath, "w", encoding="utf8", newline="\n") as translations:
translations.write(file_header)
translations.write("translation_index = ")
translations.write(repr(tuple(translation_index)))
translations.write(repr(translation_index))
translations.write("\n\n")
print("Baked", filepath)

Expand Down
6 changes: 1 addition & 5 deletions src/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,16 @@ def login(ctx_login):

login_start_from = None
while True:
login_page = krux.pages.login.Login(ctx_login)
if not login_page.run(login_start_from):
if not krux.pages.login.Login(ctx_login).run(login_start_from):
break

if ctx_login.wallet is not None:
# Have a loaded wallet
del login_page
break

# Login closed due to change of locale at Settings
login_start_from = (
krux.pages.login.Login.SETTINGS_MENU_INDEX
) # will start Login again from Settings index
del login_page

# Unimport login
del krux.pages.login
Expand Down
18 changes: 5 additions & 13 deletions src/krux/krux_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class DefaultWallet(SettingsNamespace):
network = CategorySetting("network", MAIN_TXT, [MAIN_TXT, TEST_TXT])
multisig = CategorySetting("multisig", False, [False, True])
script_type = CategorySetting(
"script_type", "Native Segwit - 84", list(SCRIPT_LONG_NAMES.keys())
"script_type", "Native Segwit - 84", tuple(SCRIPT_LONG_NAMES.keys())
)

def label(self, attr):
Expand All @@ -107,7 +107,7 @@ class I18nSettings(SettingsNamespace):

namespace = "settings.i18n"
locale = CategorySetting(
"locale", DEFAULT_LOCALE, list(translation_index) + [DEFAULT_LOCALE]
"locale", DEFAULT_LOCALE, translation_index + [DEFAULT_LOCALE]
)

def label(self, attr):
Expand Down Expand Up @@ -216,7 +216,7 @@ class PrinterSettings(SettingsNamespace):
"cnc/file": ("cnc", "FilePrinter"),
}
namespace = "settings.printer"
driver = CategorySetting("driver", "none", list(PRINTERS.keys()))
driver = CategorySetting("driver", "none", tuple(PRINTERS.keys()))

def __init__(self):
self.thermal = ThermalSettings()
Expand Down Expand Up @@ -347,7 +347,7 @@ class EncryptionSettings(SettingsNamespace):
PBKDF2_HMAC_CBC: AES_CBC_NAME,
}
namespace = "settings.encryption"
version = CategorySetting("version", AES_ECB_NAME, list(VERSION_NAMES.values()))
version = CategorySetting("version", AES_ECB_NAME, tuple(VERSION_NAMES.values()))
pbkdf2_iterations = NumberSetting(int, "pbkdf2_iterations", 100000, [1, 500000])

def label(self, attr):
Expand Down Expand Up @@ -379,7 +379,7 @@ class ThemeSettings(SettingsNamespace):
PINK_THEME: PINK_THEME_NAME,
}
namespace = "settings.appearance"
theme = CategorySetting("theme", DARK_THEME_NAME, list(THEME_NAMES.values()))
theme = CategorySetting("theme", DARK_THEME_NAME, tuple(THEME_NAMES.values()))
screensaver_time = NumberSetting(int, "screensaver_time", 5, [0, 30])

def label(self, attr):
Expand Down Expand Up @@ -410,14 +410,6 @@ class Settings(SettingsNamespace):

namespace = "settings"

# Make sure only one instance is created (Singleton)
_instance = None

def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)
return cls._instance

def __init__(self):
self.wallet = DefaultWallet()
self.security = SecuritySettings()
Expand Down
4 changes: 2 additions & 2 deletions src/krux/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

translation_index = (
translation_index = [
"de-DE",
"es-MX",
"fr-FR",
Expand All @@ -29,4 +29,4 @@
"ru-RU",
"tr-TR",
"vi-VN",
)
]

0 comments on commit 3d316d5

Please sign in to comment.