aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-09-11 22:51:20 -0500
committerGitHub <noreply@github.com>2024-09-11 22:51:20 -0500
commit1b77dcb84cb8887cdb13a94e459f7e0c2587afa0 (patch)
treecdb6b6c76aafcd95d226956b5fea7fb2fbd83a06
parentafd42e73305f05b0eb0ea0b7dec50c18eebe23e3 (diff)
parent255cfefa5d3c5998e1c0067dce070a39a8627de8 (diff)
downloadslskd-1b77dcb84cb8887cdb13a94e459f7e0c2587afa0.tar.gz
Merge branch 'master' into browsers
-rw-r--r--.github/workflows/ci.yml8
-rw-r--r--src/web/src/components/App.jsx57
2 files changed, 41 insertions, 24 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 0adfb1d2..1238b703 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -37,7 +37,7 @@ jobs:
- name: Upload Static Web Content
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
- uses: actions/upload-artifact@v3
+ uses: actions/upload-artifact@v4
with:
name: web-${{ env.VERSION }}
path: src/web/build
@@ -76,7 +76,7 @@ jobs:
echo "VERSION=$(git describe --tags --abbrev=0).$([[ $GITHUB_REF = refs/tags/* ]] && echo 0 || echo 65534)+$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Download Static Web Content
- uses: actions/download-artifact@v3
+ uses: actions/download-artifact@v4
with:
name: web-${{ env.VERSION }}
path: src/slskd/wwwroot
@@ -85,7 +85,7 @@ jobs:
run: bin/publish --no-prebuild --runtime ${{ matrix.runtime }} --version ${{ env.VERSION }}
- name: Upload Binaries
- uses: actions/upload-artifact@v3
+ uses: actions/upload-artifact@v4
with:
name: slskd-${{ env.VERSION }}-${{ matrix.runtime }}
path: dist/${{ matrix.runtime }}
@@ -199,7 +199,7 @@ jobs:
echo "TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
echo "VERSION=$(git describe --tags --abbrev=0).$([[ $GITHUB_REF = refs/tags/* ]] && echo 0 || echo 65534)+$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Download ${{ matrix.runtime }} Binaries
- uses: actions/download-artifact@v3
+ uses: actions/download-artifact@v4
with:
name: slskd-${{ env.VERSION }}-${{ matrix.runtime }}
path: dist/${{ matrix.runtime }}
diff --git a/src/web/src/components/App.jsx b/src/web/src/components/App.jsx
index 1580db8e..5c82697a 100644
--- a/src/web/src/components/App.jsx
+++ b/src/web/src/components/App.jsx
@@ -136,18 +136,21 @@ class App extends Component {
}
componentDidMount() {
- window
- .matchMedia('(prefers-color-scheme: dark)')
- .addEventListener(
- 'change',
- (event) => event.matches && this.setState({ theme: 'dark' }),
- );
- window
- .matchMedia('(prefers-color-scheme: light)')
- .addEventListener(
- 'change',
- (event) => event.matches && this.setState({ theme: 'light' }),
- );
+ if (this.getSavedTheme() == null) {
+ window
+ .matchMedia('(prefers-color-scheme: dark)')
+ .addEventListener(
+ 'change',
+ (event) => event.matches && this.setState({ theme: 'dark' }),
+ );
+ window
+ .matchMedia('(prefers-color-scheme: light)')
+ .addEventListener(
+ 'change',
+ (event) => event.matches && this.setState({ theme: 'light' }),
+ );
+ }
+
this.init();
}
@@ -185,6 +188,11 @@ class App extends Component {
await appHub.start();
}
+ const savedTheme = this.getSavedTheme();
+ if (savedTheme != null) {
+ this.setState({ theme: savedTheme });
+ }
+
this.setState({
error: false,
});
@@ -197,6 +205,18 @@ class App extends Component {
});
};
+ getSavedTheme = () => {
+ return localStorage.getItem('slskd-theme');
+ };
+
+ toggleTheme = () => {
+ this.setState((state) => {
+ const newTheme = state.theme === 'dark' ? 'light' : 'dark';
+ localStorage.setItem('slskd-theme', newTheme);
+ return { theme: newTheme };
+ });
+ };
+
handleLogin = (username, password, rememberMe) => {
this.setState(
(previousState) => ({
@@ -238,9 +258,10 @@ class App extends Component {
initialized,
login,
retriesExhausted,
- theme = window.matchMedia('(prefers-color-scheme: dark)').matches
- ? 'dark'
- : 'light',
+ theme = this.getSavedTheme() ||
+ (window.matchMedia('(prefers-color-scheme: dark)').matches
+ ? 'dark'
+ : 'light'),
} = this.state;
const {
pendingReconnect,
@@ -383,11 +404,7 @@ class App extends Component {
className="right"
inverted
>
- <Menu.Item
- onClick={() =>
- this.setState({ theme: theme === 'dark' ? 'light' : 'dark' })
- }
- >
+ <Menu.Item onClick={() => this.toggleTheme()}>
<Icon name="theme" />
Theme
</Menu.Item>