Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
4767ee32
Unverified
Commit
4767ee32
authored
Dec 04, 2022
by
boojack
Committed by
GitHub
Dec 04, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support follow system appearance (#670)
parent
1ea74dfd
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
43 additions
and
22 deletions
+43
-22
user_setting.go
api/user_setting.go
+1
-1
App.tsx
web/src/App.tsx
+29
-10
AppearanceSelect.tsx
web/src/components/AppearanceSelect.tsx
+3
-1
en.json
web/src/locales/en.json
+2
-2
sv.json
web/src/locales/sv.json
+3
-3
zh.json
web/src/locales/zh.json
+2
-2
globalService.ts
web/src/services/globalService.ts
+1
-1
global.ts
web/src/store/modules/global.ts
+1
-1
setting.d.ts
web/src/types/modules/setting.d.ts
+1
-1
No files found.
api/user_setting.go
View file @
4767ee32
...
...
@@ -35,7 +35,7 @@ func (key UserSettingKey) String() string {
var
(
UserSettingLocaleValue
=
[]
string
{
"en"
,
"zh"
,
"vi"
,
"fr"
,
"sv"
}
UserSettingAppearanceValue
=
[]
string
{
"light"
,
"dark"
}
UserSettingAppearanceValue
=
[]
string
{
"
system"
,
"
light"
,
"dark"
}
UserSettingMemoVisibilityValue
=
[]
Visibility
{
Private
,
Protected
,
Public
}
UserSettingMemoDisplayTsOptionKeyValue
=
[]
string
{
"created_ts"
,
"updated_ts"
}
)
...
...
web/src/App.tsx
View file @
4767ee32
import
{
useColorScheme
}
from
"@mui/joy"
;
import
{
useEffect
,
Suspense
}
from
"react"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
RouterProvider
}
from
"react-router-dom"
;
import
{
locationService
}
from
"./services"
;
import
{
globalService
,
locationService
}
from
"./services"
;
import
{
useAppSelector
}
from
"./store"
;
import
Loading
from
"./pages/Loading"
;
import
router
from
"./router"
;
import
*
as
storage
from
"./helpers/storage"
;
import
{
useColorScheme
}
from
"@mui/joy
"
;
import
{
getSystemColorScheme
}
from
"./helpers/utils
"
;
function
App
()
{
const
{
i18n
}
=
useTranslation
();
const
{
appearance
,
locale
,
systemStatus
}
=
useAppSelector
((
state
)
=>
state
.
global
);
const
{
setMode
}
=
useColorScheme
();
const
{
mode
,
setMode
}
=
useColorScheme
();
useEffect
(()
=>
{
locationService
.
updateStateWithLocation
();
...
...
@@ -20,6 +21,15 @@ function App() {
};
},
[]);
useEffect
(()
=>
{
window
.
matchMedia
(
"(prefers-color-scheme: dark)"
).
addEventListener
(
"change"
,
(
e
)
=>
{
if
(
globalService
.
getState
().
appearance
===
"system"
)
{
const
mode
=
e
.
matches
?
"dark"
:
"light"
;
setMode
(
mode
);
}
});
},
[]);
// Inject additional style and script codes.
useEffect
(()
=>
{
if
(
systemStatus
.
additionalStyle
)
{
...
...
@@ -43,18 +53,27 @@ function App() {
},
[
locale
]);
useEffect
(()
=>
{
const
root
=
document
.
documentElement
;
if
(
appearance
===
"light"
)
{
root
.
classList
.
remove
(
"dark"
);
}
else
if
(
appearance
===
"dark"
)
{
root
.
classList
.
add
(
"dark"
);
}
setMode
(
appearance
);
storage
.
set
({
appearance
:
appearance
,
});
let
currentAppearance
=
appearance
;
if
(
appearance
===
"system"
)
{
currentAppearance
=
getSystemColorScheme
();
}
setMode
(
currentAppearance
);
},
[
appearance
]);
useEffect
(()
=>
{
const
root
=
document
.
documentElement
;
if
(
mode
===
"light"
)
{
root
.
classList
.
remove
(
"dark"
);
}
else
{
root
.
classList
.
add
(
"dark"
);
}
},
[
mode
]);
return
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
RouterProvider
router=
{
router
}
/>
...
...
web/src/components/AppearanceSelect.tsx
View file @
4767ee32
...
...
@@ -4,7 +4,7 @@ import { globalService, userService } from "../services";
import
{
useAppSelector
}
from
"../store"
;
import
Icon
from
"./Icon"
;
const
appearanceList
=
[
"light"
,
"dark"
];
const
appearanceList
=
[
"
system"
,
"
light"
,
"dark"
];
const
AppearanceSelect
=
()
=>
{
const
user
=
useAppSelector
((
state
)
=>
state
.
user
.
user
);
...
...
@@ -17,6 +17,8 @@ const AppearanceSelect = () => {
return
<
Icon
.
Sun
className=
{
className
}
/>;
}
else
if
(
apperance
===
"dark"
)
{
return
<
Icon
.
Moon
className=
{
className
}
/>;
}
else
{
return
<
Icon
.
Smile
className=
{
className
}
/>;
}
};
...
...
web/src/locales/en.json
View file @
4767ee32
...
...
@@ -168,9 +168,9 @@
"additional-script-placeholder"
:
"Additional JavaScript codes"
},
"apperance-option"
:
{
"system"
:
"Follow system"
,
"light"
:
"Always light"
,
"dark"
:
"Always dark"
,
"system"
:
"Follow system"
"dark"
:
"Always dark"
}
},
"amount-text"
:
{
...
...
web/src/locales/sv.json
View file @
4767ee32
...
...
@@ -168,9 +168,9 @@
"additional-script-placeholder"
:
"Ytterligare JavaScript kod"
},
"apperance-option"
:
{
"system"
:
"Follow system"
,
"light"
:
"Alltid ljus"
,
"dark"
:
"Alltid mörk"
,
"system"
:
"Följ systeminställningarna"
"dark"
:
"Alltid mörk"
}
},
"amount-text"
:
{
...
...
@@ -210,4 +210,4 @@
"not-allow-space"
:
"Tillåt inte mellanslag"
,
"not-allow-chinese"
:
"Tillåt inte kinesiska"
}
}
\ No newline at end of file
}
web/src/locales/zh.json
View file @
4767ee32
...
...
@@ -168,9 +168,9 @@
"additional-script-placeholder"
:
"自定义 JavaScript 代码"
},
"apperance-option"
:
{
"system"
:
"跟随系统"
,
"light"
:
"总是浅色"
,
"dark"
:
"总是深色"
,
"system"
:
"跟随系统"
"dark"
:
"总是深色"
}
},
"amount-text"
:
{
...
...
web/src/services/globalService.ts
View file @
4767ee32
...
...
@@ -11,7 +11,7 @@ const globalService = {
initialState
:
async
()
=>
{
const
defaultGlobalState
=
{
locale
:
"en"
as
Locale
,
appearance
:
"
light
"
as
Appearance
,
appearance
:
"
system
"
as
Appearance
,
systemStatus
:
{
allowSignUp
:
false
,
additionalStyle
:
""
,
...
...
web/src/store/modules/global.ts
View file @
4767ee32
...
...
@@ -10,7 +10,7 @@ const globalSlice = createSlice({
name
:
"global"
,
initialState
:
{
locale
:
"en"
,
appearance
:
"
light
"
,
appearance
:
"
system
"
,
systemStatus
:
{
host
:
undefined
,
profile
:
{
...
...
web/src/types/modules/setting.d.ts
View file @
4767ee32
type
Appearance
=
"light"
|
"dark"
;
type
Appearance
=
"
system"
|
"
light"
|
"dark"
;
interface
Setting
{
locale
:
Locale
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment