Skip to content

Commit

Permalink
fix(settings): cancel and save buttons behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Dec 11, 2024
1 parent 837b190 commit eac7db5
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 482 deletions.
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
## [Unreleased]
### fixes
- fix settings `cancel` button not working correctly.
- fix settings `save` button not saving the monitor settings correctly.

## [2.0.9]
### enhancements
- add `XboxGameBarWidgets.exe` to the bundled apps settings list.
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

15 changes: 6 additions & 9 deletions src/apps/settings/modules/ByMonitor/infra/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,29 @@ export function MonitorConfig({ device, config, onChange }: MonitorConfigProps)

export function SettingsByMonitor() {
const devices = useSelector(newSelectors.connectedMonitors);
const monitors = useSelector(newSelectors.monitorsV2);
const settingsByMonitor = useSelector(newSelectors.monitorsV2);

const dispatch = useDispatch();

function onMonitorChange(id: string, monitor: MonitorConfiguration) {
dispatch(
RootActions.setMonitors({
...monitors,
...settingsByMonitor,
[id]: monitor,
}),
);
}

return (
<>
{Object.entries(monitors).map(([id, monitor]) => {
let device = devices.find((d) => d.id === id);
if (!device) {
return null;
}
{devices.map((device) => {
let monitor = settingsByMonitor[device.id] || new MonitorConfiguration();
return (
<MonitorConfig
key={id}
key={device.id}
device={device}
config={monitor}
onChange={onMonitorChange.bind(null, id)}
onChange={onMonitorChange.bind(null, device.id)}
/>
);
})}
Expand Down
18 changes: 6 additions & 12 deletions src/apps/settings/modules/shared/store/infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { cloneDeep } from 'lodash';
import {
AppConfiguration,
ConnectedMonitorList,
MonitorConfiguration,
PluginList,
ProfileList,
SeelenEvent,
Expand Down Expand Up @@ -44,16 +43,7 @@ export type store = {
// ======================

function setMonitorsOnState(list: ConnectedMonitorList) {
const monitors = list.all();
store.dispatch(RootActions.setConnectedMonitors(monitors));
const settingsByMonitor = { ...store.getState().monitorsV2 };
for (const monitor of monitors) {
if (!settingsByMonitor[monitor.id]) {
settingsByMonitor[monitor.id] = new MonitorConfiguration();
}
}
console.log({ monitors, settingsByMonitor });
store.dispatch(RootActions.setMonitorsV2(settingsByMonitor));
store.dispatch(RootActions.setConnectedMonitors(list.all()));
}

async function initUIColors() {
Expand Down Expand Up @@ -122,13 +112,17 @@ export const LoadSettingsToStore = async (customPath?: string) => {

const currentState = store.getState();
const newState = StaticSettingsToState(userSettings, currentState);
newState.lastLoaded = cloneDeep(newState);
store.dispatch(RootActions.setState(newState));

store.dispatch(RootActions.setPlugins((await PluginList.getAsync()).all()));
store.dispatch(RootActions.setWidgets((await WidgetList.getAsync()).all()));
store.dispatch(RootActions.setProfiles((await ProfileList.getAsync()).toArray()));
setMonitorsOnState(await ConnectedMonitorList.getAsync());

const state = { ...store.getState() };
state.lastLoaded = cloneDeep(state);
state.toBeSaved = false;
store.dispatch(RootActions.setState(state));
};

export const SaveStore = async () => {
Expand Down
8 changes: 2 additions & 6 deletions src/apps/settings/modules/shared/store/storeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { resolveDataPath } from '../config/infra';
import { dialog, fs } from '../tauri/infra';

import { UserSettings } from '../../../../../shared.interfaces';
import { VariableConvention } from '../../../../shared/schemas';

export class UserSettingsLoader {
private _withUserApps: boolean = false;
Expand Down Expand Up @@ -86,11 +85,8 @@ export class UserSettingsLoader {
}

export async function saveJsonSettings(settings: UserSettings['jsonSettings']) {
const json_route = await resolveDataPath('settings.json');
await fs.writeTextFile(
json_route,
JSON.stringify(VariableConvention.fromCamelToSnake(settings), null, 2),
);
// TODO add command to SeelenCommand enum list and replace here
await invoke('state_write_settings', { settings });
}

export async function saveUserSettings(
Expand Down
1 change: 1 addition & 0 deletions src/background/exposed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub fn register_invoke_handler(app_builder: Builder<Wry>) -> Builder<Wry> {
state_get_layouts,
state_get_weg_items,
state_get_settings,
state_write_settings,
state_get_specific_apps_configurations,
state_get_wallpaper,
state_set_wallpaper,
Expand Down
11 changes: 7 additions & 4 deletions src/background/modules/cli/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use parking_lot::Mutex;
use windows::Win32::System::Console::{AttachConsole, FreeConsole, ATTACH_PARENT_PROCESS};

use crate::error_handler::Result;
use crate::modules::cli::domain::Resource;
use crate::modules::virtual_desk::{VirtualDesktopManager, VIRTUAL_DESKTOP_MANAGER};
use crate::seelen::{Seelen, SEELEN};
use crate::seelen_bar::FancyToolbar;
Expand Down Expand Up @@ -173,10 +174,12 @@ pub fn process_uri(uri: &str) -> Result<()> {

let engine = base64::engine::general_purpose::URL_SAFE_NO_PAD;
let decoded = engine.decode(contents.as_bytes())?;

let mut state = FULL_STATE.load().cloned();
state.load_resource(serde_yaml::from_slice(&decoded)?)?;
state.store();
let resource: Resource = serde_yaml::from_slice(&decoded)?;
FULL_STATE.rcu(|state| {
let mut state = state.cloned();
let _ = state.load_resource(resource.clone());
state
});
Ok(())
}

Expand Down
12 changes: 1 addition & 11 deletions src/background/state/application/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@ use itertools::Itertools;
use seelen_core::{handlers::SeelenEvent, state::WegItems};
use tauri::Emitter;

use crate::{
error_handler::Result,
seelen::{get_app_handle, SEELEN},
trace_lock,
};
use crate::{error_handler::Result, seelen::get_app_handle, trace_lock};

use super::FullState;

impl FullState {
pub(super) fn emit_settings(&self) -> Result<()> {
get_app_handle().emit(SeelenEvent::StateSettingsChanged, self.settings())?;
trace_lock!(SEELEN).on_settings_change()?;
Ok(())
}

pub fn emit_weg_items(&self, items: &WegItems) -> Result<()> {
get_app_handle().emit(SeelenEvent::StateWegItemsChanged, items)?;
Ok(())
Expand Down
Loading

0 comments on commit eac7db5

Please sign in to comment.