-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLocalStorage.tsx
More file actions
142 lines (121 loc) · 4.72 KB
/
LocalStorage.tsx
File metadata and controls
142 lines (121 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Pic Display - A cute image viewer ❤ *
* Copyright © 2026 Moebytes <moebytes.com> *
* Licensed under CC BY-NC 4.0. See license.txt for details. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
import React, {useEffect} from "react"
import {ReduxState} from "./structures/functions"
import {useThemeSelector, useThemeActions, useActiveSelector, useActiveActions,
useFilterActions} from "./store"
import {Themes, OS} from "./reducers/themeReducer"
export const lightColorList = {
"--closeButton": "#496dff",
"--minimizeButton": "#398bff",
"--maximizeButton": "#2ea8ff",
"--navColor": "#9abaff",
"--iconColor": "#4a83ff",
"--background": "#ffffff",
"--textColor": "#000000",
"--textColor2": "#000000",
"--buttonColor": "#7e98ff"
}
export const darkColorList = {
"--closeButton": "#496dff",
"--minimizeButton": "#398bff",
"--maximizeButton": "#2ea8ff",
"--navColor": "#091329",
"--iconColor": "#4c85ff",
"--background": "#000000",
"--textColor": "#ffffff",
"--textColor2": "#000000",
"--buttonColor": "#283d91"
}
const LocalStorage: React.FunctionComponent = () => {
const {theme, os, transparent, pinned} = useThemeSelector()
const {setTheme, setOS, setTransparent, setPinned} = useThemeActions()
const {imageDrag} = useActiveSelector()
const {setImageDrag} = useActiveActions()
const {setBrightness, setContrast, setHue, setSaturation,
setLightness, setBlur, setSharpen, setPixelate} = useFilterActions()
useEffect(() => {
const syncState = (event: any, state: ReduxState) => {
if (state.brightness !== undefined) setBrightness(state.brightness)
if (state.contrast !== undefined) setContrast(state.contrast)
if (state.hue !== undefined) setHue(state.hue)
if (state.saturation !== undefined) setSaturation(state.saturation)
if (state.lightness !== undefined) setLightness(state.lightness)
if (state.blur !== undefined) setBlur(state.blur)
if (state.sharpen !== undefined) setSharpen(state.sharpen)
if (state.pixelate !== undefined) setPixelate(state.pixelate)
}
window.ipcRenderer.on("sync-redux-state", syncState)
return () => {
window.ipcRenderer.removeListener("sync-redux-state", syncState)
}
}, [])
useEffect(() => {
if (typeof window === "undefined") return
const colorList = theme.includes("light") ? lightColorList : darkColorList
for (let i = 0; i < Object.keys(colorList).length; i++) {
const key = Object.keys(colorList)[i]
const color = Object.values(colorList)[i]
document.documentElement.style.setProperty(key, color)
}
if (transparent) {
document.documentElement.style.setProperty("--background", "transparent")
document.documentElement.style.setProperty("--navColor", "transparent")
}
}, [theme, transparent])
useEffect(() => {
const initTheme = async () => {
const savedTheme = await window.ipcRenderer.invoke("get-theme")
if (savedTheme) setTheme(savedTheme as Themes)
}
initTheme()
}, [])
useEffect(() => {
window.ipcRenderer.invoke("save-theme", theme)
}, [theme])
useEffect(() => {
const initOS = async () => {
const savedOS = await window.ipcRenderer.invoke("get-os")
if (savedOS) setOS(savedOS as OS)
}
initOS()
}, [])
useEffect(() => {
window.ipcRenderer.invoke("save-os", os)
}, [os])
useEffect(() => {
const initTransparent = async () => {
const savedTransparent = await window.ipcRenderer.invoke("get-transparent")
if (savedTransparent) setTransparent(savedTransparent)
}
initTransparent()
}, [])
useEffect(() => {
window.ipcRenderer.invoke("save-transparent", transparent)
}, [transparent])
useEffect(() => {
const initPinned = async () => {
const savedPinned = await window.ipcRenderer.invoke("get-pinned")
if (savedPinned) setPinned(savedPinned)
}
initPinned()
}, [])
useEffect(() => {
window.ipcRenderer.invoke("save-pinned", pinned)
}, [pinned])
useEffect(() => {
const initImageDrag = async () => {
const savedDrag = await window.ipcRenderer.invoke("get-img-drag")
if (savedDrag) setImageDrag(Boolean(savedDrag))
}
initImageDrag()
}, [])
useEffect(() => {
window.ipcRenderer.invoke("save-img-drag", imageDrag)
}, [imageDrag])
return null
}
export default LocalStorage