-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/custom themes #1409
Feature/custom themes #1409
Changes from all commits
148e577
44aed56
6bf049d
58f63ca
3e2d7a7
c8044f6
ab44348
5a19e9f
b56fc4d
1fe6abb
a42975a
613d8ca
56e686f
5510036
f542b2d
e49a321
61d4910
13eeb2c
afcd99a
d91d8dd
964e9bb
6a6e3ca
4758b8c
4535ebc
15746a5
e4631bb
f6e4852
f288870
b9e04de
47e6d88
0f0e27e
0a37ce4
ec638d1
1fe7e23
c0c78b5
418ad71
740d3ff
ce95dbb
821149b
9314b17
730184d
ae159a4
543528b
b202daf
0511cc0
3271de0
39ceb8e
ba6eb2e
6158108
22e5674
d7d88ec
bf3905f
3f6315f
c36aff8
9449d7c
484fa86
d1dc27a
ca75ad6
ef28337
569c80c
4cfecf8
e3a4f12
74c7668
a13e991
cd48acc
f428c52
6e35600
21684ef
b74e093
002f814
a372afc
043062e
5d48ce8
401e61a
b999da3
4f725d0
7064da8
d1a77dc
cc14562
f7acb44
5a6f66a
f1e47fc
777f857
2246775
e8d5c62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Theme } from "@types"; | ||
import { registerEvent } from "../register-event"; | ||
import { themesSublevel } from "@main/level"; | ||
|
||
const addCustomTheme = async ( | ||
_event: Electron.IpcMainInvokeEvent, | ||
theme: Theme | ||
) => { | ||
await themesSublevel.put(theme.id, theme); | ||
}; | ||
|
||
registerEvent("addCustomTheme", addCustomTheme); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { WindowManager } from "@main/services"; | ||
import { registerEvent } from "../register-event"; | ||
|
||
const closeEditorWindow = async ( | ||
_event: Electron.IpcMainInvokeEvent, | ||
themeId?: string | ||
) => { | ||
WindowManager.closeEditorWindow(themeId); | ||
}; | ||
|
||
registerEvent("closeEditorWindow", closeEditorWindow); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { themesSublevel } from "@main/level"; | ||
import { registerEvent } from "../register-event"; | ||
|
||
const deleteAllCustomThemes = async (_event: Electron.IpcMainInvokeEvent) => { | ||
await themesSublevel.clear(); | ||
}; | ||
|
||
registerEvent("deleteAllCustomThemes", deleteAllCustomThemes); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { themesSublevel } from "@main/level"; | ||
import { registerEvent } from "../register-event"; | ||
|
||
const deleteCustomTheme = async ( | ||
_event: Electron.IpcMainInvokeEvent, | ||
themeId: string | ||
) => { | ||
await themesSublevel.del(themeId); | ||
}; | ||
|
||
registerEvent("deleteCustomTheme", deleteCustomTheme); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { themesSublevel } from "@main/level"; | ||
import { registerEvent } from "../register-event"; | ||
|
||
const getActiveCustomTheme = async () => { | ||
const allThemes = await themesSublevel.values().all(); | ||
return allThemes.find((theme) => theme.isActive); | ||
}; | ||
|
||
registerEvent("getActiveCustomTheme", getActiveCustomTheme); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { themesSublevel } from "@main/level"; | ||
import { registerEvent } from "../register-event"; | ||
|
||
const getAllCustomThemes = async (_event: Electron.IpcMainInvokeEvent) => { | ||
return themesSublevel.values().all(); | ||
}; | ||
|
||
registerEvent("getAllCustomThemes", getAllCustomThemes); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { themesSublevel } from "@main/level"; | ||
import { registerEvent } from "../register-event"; | ||
|
||
const getCustomThemeById = async ( | ||
_event: Electron.IpcMainInvokeEvent, | ||
themeId: string | ||
) => { | ||
return themesSublevel.get(themeId); | ||
}; | ||
|
||
registerEvent("getCustomThemeById", getCustomThemeById); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,11 @@ | ||||||||||||||||||||||||||
import { WindowManager } from "@main/services"; | ||||||||||||||||||||||||||
import { registerEvent } from "../register-event"; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const openEditorWindow = async ( | ||||||||||||||||||||||||||
_event: Electron.IpcMainInvokeEvent, | ||||||||||||||||||||||||||
themeId: string | ||||||||||||||||||||||||||
) => { | ||||||||||||||||||||||||||
WindowManager.openEditorWindow(themeId); | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
Comment on lines
+4
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: function is marked async but doesn't use await or return a Promise. Either remove async or handle the Promise from openEditorWindow
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
registerEvent("openEditorWindow", openEditorWindow); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { themesSublevel } from "@main/level"; | ||
import { registerEvent } from "../register-event"; | ||
|
||
const toggleCustomTheme = async ( | ||
_event: Electron.IpcMainInvokeEvent, | ||
themeId: string, | ||
isActive: boolean | ||
) => { | ||
const theme = await themesSublevel.get(themeId); | ||
|
||
if (!theme) { | ||
throw new Error("Theme not found"); | ||
} | ||
|
||
await themesSublevel.put(themeId, { | ||
...theme, | ||
isActive, | ||
updatedAt: new Date(), | ||
}); | ||
}; | ||
|
||
registerEvent("toggleCustomTheme", toggleCustomTheme); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { themesSublevel } from "@main/level"; | ||
import { registerEvent } from "../register-event"; | ||
import { WindowManager } from "@main/services"; | ||
|
||
const updateCustomTheme = async ( | ||
_event: Electron.IpcMainInvokeEvent, | ||
themeId: string, | ||
code: string | ||
) => { | ||
const theme = await themesSublevel.get(themeId); | ||
|
||
if (!theme) { | ||
throw new Error("Theme not found"); | ||
} | ||
|
||
await themesSublevel.put(themeId, { | ||
...theme, | ||
code, | ||
updatedAt: new Date(), | ||
}); | ||
|
||
if (theme.isActive) { | ||
WindowManager.mainWindow?.webContents.send("css-injected", code); | ||
} | ||
}; | ||
|
||
registerEvent("updateCustomTheme", updateCustomTheme); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,10 @@ | ||
import { registerEvent } from "../register-event"; | ||
import { db, levelKeys } from "@main/level"; | ||
import { Crypto } from "@main/services"; | ||
import type { UserPreferences } from "@types"; | ||
|
||
const getUserPreferences = async () => | ||
db | ||
.get<string, UserPreferences | null>(levelKeys.userPreferences, { | ||
valueEncoding: "json", | ||
}) | ||
.then((userPreferences) => { | ||
if (userPreferences?.realDebridApiToken) { | ||
userPreferences.realDebridApiToken = Crypto.decrypt( | ||
userPreferences.realDebridApiToken | ||
); | ||
} | ||
|
||
if (userPreferences?.torBoxApiToken) { | ||
userPreferences.torBoxApiToken = Crypto.decrypt( | ||
userPreferences.torBoxApiToken | ||
); | ||
} | ||
|
||
return userPreferences; | ||
}); | ||
db.get<string, UserPreferences | null>(levelKeys.userPreferences, { | ||
valueEncoding: "json", | ||
}); | ||
|
||
registerEvent("getUserPreferences", getUserPreferences); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ import { registerEvent } from "../register-event"; | |
import type { UserPreferences } from "@types"; | ||
import i18next from "i18next"; | ||
import { db, levelKeys } from "@main/level"; | ||
import { Crypto } from "@main/services"; | ||
import { patchUserProfile } from "../profile/update-profile"; | ||
|
||
const updateUserPreferences = async ( | ||
|
@@ -24,16 +23,6 @@ const updateUserPreferences = async ( | |
patchUserProfile({ language: preferences.language }).catch(() => {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Empty catch block silently ignores profile update failures. Consider at least logging the error |
||
} | ||
|
||
if (preferences.realDebridApiToken) { | ||
preferences.realDebridApiToken = Crypto.encrypt( | ||
preferences.realDebridApiToken | ||
); | ||
} | ||
|
||
if (preferences.torBoxApiToken) { | ||
preferences.torBoxApiToken = Crypto.encrypt(preferences.torBoxApiToken); | ||
} | ||
|
||
if (!preferences.downloadsPath) { | ||
preferences.downloadsPath = null; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The isPortableVersion import is now separated from other imports by the theme imports. Consider grouping it with other helper/constant imports at the top of the file