Skip to content

Commit

Permalink
feat(wallpaper): allow change wallpaper from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Aug 15, 2024
1 parent 69c0e4a commit 245ae98
Show file tree
Hide file tree
Showing 25 changed files with 363 additions and 20 deletions.
143 changes: 142 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tauri-plugin-process = "2.0.0-beta.2"
tauri-plugin-log = "2.0.0-beta.2"
tauri-plugin-updater = "2.0.0-beta.2"
tauri-plugin-deep-link = "2.0.0-beta.10"
tauri-plugin-http = "2.0.0-beta.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9.34"
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]
### features
- .slu and uri now are loaded correctly on seelen ui.
- allow change wallpaper from seelen settings.

### enhancements
- add file associations for .slu files
Expand Down
4 changes: 4 additions & 0 deletions src/apps/settings/components/SettingsBox/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
overflow: hidden;
position: relative;

&:last-child {
margin-bottom: 10px;
}

> div {
position: absolute; /* for noise and blur */
top: 0;
Expand Down
28 changes: 28 additions & 0 deletions src/apps/settings/components/monitor/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.monitor {
height: 144px;
width: 256px;
border-radius: 12px;
background-color: var(--color-persist-gray-800);
padding: 8px;

.screen {
position: relative;
border-radius: 8px;
background: linear-gradient(
40deg,
var(--color-blue-500) 2%,
var(--color-blue-300) 60%,
var(--color-blue-100) 100%
);
width: 100%;
height: 100%;
overflow: hidden;

.wallpaper {
width: 100%;
height: 100%;
object-fit: cover;
position: absolute;
}
}
}
22 changes: 22 additions & 0 deletions src/apps/settings/components/monitor/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { convertFileSrc } from '@tauri-apps/api/core';
import { PropsWithChildren } from 'react';
import { useSelector } from 'react-redux';

import { newSelectors } from '../../modules/shared/store/app/reducer';

import cs from './index.module.css';

interface Props extends PropsWithChildren {}

export function Monitor({ children }: Props) {
const wallpaper = useSelector(newSelectors.wallpaper);

return (
<div className={cs.monitor}>
<div className={cs.screen}>
{wallpaper ? <img className={cs.wallpaper} src={convertFileSrc(wallpaper)} /> : null}
{children}
</div>
</div>
);
}
2 changes: 2 additions & 0 deletions src/apps/settings/i18n/translations/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ general:
selected: Selected
icon_pack:
label: Icon Packs
wallpaper:
select: Select Wallpaper
accent_color: Accent Color
toolbar:
enable: Enable Fancy Toolbar
Expand Down
38 changes: 38 additions & 0 deletions src/apps/settings/modules/general/main/infra/Wallpaper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Monitor } from '../../../../components/monitor';
import { SettingsOption } from '../../../../components/SettingsBox';
import { invoke } from '@tauri-apps/api/core';
import { Button } from 'antd';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';

import { dialog } from '../../../shared/tauri/infra';

import { RootActions } from '../../../shared/store/app/reducer';

export function Wallpaper() {
const { t } = useTranslation();
const dispatch = useDispatch();

async function loadWallpaper() {
const file = await dialog.open({
title: t('general.wallpaper.select'),
filters: [{ name: 'images', extensions: ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'tif', 'tiff'] }],
});

if (!file) {
return;
}

await invoke('state_set_wallpaper', { path: file.path });
dispatch(RootActions.setWallpaper(file.path));
}

return (
<>
<SettingsOption>
<Monitor />
<Button onClick={loadWallpaper} size="middle">{t('general.wallpaper.select')}</Button>
</SettingsOption>
</>
);
}
Loading

0 comments on commit 245ae98

Please sign in to comment.