-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔧 Migrated preference storage to local sqlite3 database
- Loading branch information
Showing
4 changed files
with
29 additions
and
9 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,41 @@ | ||
import sqlite3 | ||
|
||
from pyrebase.pyrebase import Firebase | ||
|
||
from domain.assetmanager import get_database_path | ||
from model.ThemeEnum import Theme | ||
from model.User import User | ||
|
||
|
||
class SettingsDao: | ||
|
||
get_theme_dict = { | ||
"light": Theme.LIGHT, | ||
"dark": Theme.DARK | ||
"dark": Theme.DARK, | ||
"light": Theme.LIGHT | ||
} | ||
|
||
put_theme_dict = { | ||
Theme.LIGHT: "light", | ||
Theme.DARK: "dark" | ||
Theme.LIGHT: 1, | ||
Theme.DARK: 0 | ||
} | ||
|
||
db_path = get_database_path("prefs_db.sqlite") | ||
connection = sqlite3.connect(db_path) | ||
cursor = connection.cursor() | ||
|
||
def __init__(self, firebase: Firebase): | ||
self.__db = firebase.database() | ||
pass | ||
|
||
def save_theme(self, user: User, theme: Theme): | ||
data = self.put_theme_dict.get(theme, "dark") | ||
self.__db.child("users").child(user.id).child("settings").child("def_theme").set(data) | ||
theme_id = self.put_theme_dict.get(theme, 0) | ||
self.cursor.execute(f"UPDATE prefs SET mode_id = {theme_id} WHERE id = 1").fetchall() | ||
self.connection.commit() | ||
|
||
def get_current_theme(self, user: User): | ||
data = self.__db.child("users").child(user.id).child("settings").child("def_theme").get().val() | ||
return self.get_theme_dict.get(data, Theme.DARK) | ||
cmd = "SELECT modes.name FROM prefs INNER JOIN modes ON prefs.mode_id == modes.id" | ||
res = self.cursor.execute(cmd).fetchall() | ||
return self.get_theme_dict.get(res[0][0], Theme.DARK) | ||
|
||
def close(self): | ||
self.cursor.close() | ||
self.connection.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,3 +143,4 @@ def get_current_user(self): | |
|
||
def stop_updating(self): | ||
self.active = False | ||
self.settings_dao.close() |