Skip to content

Commit

Permalink
feat: open settings form to given route
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Nov 27, 2024
1 parent 88b1cbb commit d629530
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
1 change: 1 addition & 0 deletions 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 packages/desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ tauri-build = { version = "2.0", features = [] }
[dependencies]
anyhow = "1"
async-trait = "0.1"
base64 = "0.22"
clap = { version = "4", features = ["derive"] }
crossbeam = "0.8"
reqwest = { version = "0.11", features = ["json"] }
Expand Down
44 changes: 22 additions & 22 deletions packages/desktop/src/sys_tray.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::{collections::HashMap, path::PathBuf, str::FromStr, sync::Arc};

use anyhow::{bail, Context};
use base64::prelude::*;
use tauri::{
image::Image,
menu::{CheckMenuItem, Menu, MenuBuilder, Submenu, SubmenuBuilder},
tray::{
MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder,
TrayIconEvent,
},
AppHandle, Manager, Url, WebviewUrl, WebviewWindowBuilder, Wry,
AppHandle, Manager, WebviewUrl, WebviewWindowBuilder, Wry,
};
use tokio::task;
use tracing::{error, info};
Expand Down Expand Up @@ -332,39 +333,38 @@ impl SysTray {
// Get existing settings window if it's already open.
let settings_window = app_handle.get_webview_window("settings");

// let route = match config_path {
// None => WebviewUrl::default(),
// Some(path) => WebviewUrl::App(PathBuf::from(format!(
// "index.html#/widget/{}",
// path.to_unicode_string()
// ))),
// };

// let route = format!("index.html#/widget/{}",
// path.to_unicode_string());

let route = match config_path {
None => "index.html".to_string(),
None => "/index.html".to_string(),
Some(path) => {
format!("index.html#/widget/{}", path.to_unicode_string())
format!(
"/index.html#/widget/{}",
BASE64_STANDARD.encode(path.to_unicode_string())
)
}
};

match &settings_window {
None => {
WebviewWindowBuilder::new(app_handle, "settings", route)
.title("Settings - Zebar")
.focused(true)
.visible(true)
.inner_size(900., 600.)
.build()
.context("Failed to build the settings window.")?;
WebviewWindowBuilder::new(
app_handle,
"settings",
WebviewUrl::App(route.into()),
)
.title("Settings - Zebar")
.focused(true)
.visible(true)
.inner_size(900., 600.)
.build()
.context("Failed to build the settings window.")?;

Ok(())
}
Some(window) => {
window
.navigate(Url::parse(&route)?)
.eval(&format!(
"location.replace('{}'); location.reload();",
route
))
.context("Failed to navigate to widget edit page.")?;

window
Expand Down
7 changes: 4 additions & 3 deletions packages/settings-ui/src/configs/WidgetConfigs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from '@glzr/components';
import { useParams } from '@solidjs/router';
import { IconChevronDown } from '@tabler/icons-solidjs';
import { invoke } from '@tauri-apps/api/core';
import { listen, type Event } from '@tauri-apps/api/event';
Expand All @@ -24,6 +25,8 @@ import { WidgetConfigSidebar } from './WidgetConfigSidebar';
import { WidgetConfigForm } from './WidgetConfigForm';

export function WidgetConfigs() {
const params = useParams();

const [configs, { mutate: mutateWidgetConfigs }] = createResource(
async () => invoke<Record<string, WidgetConfig>>('widget_configs'),
{ initialValue: {} },
Expand All @@ -34,11 +37,9 @@ export function WidgetConfigs() {
{ initialValue: {} },
);

createEffect(() => console.log('widgetStates', widgetStates()));

const [selectedConfigPath, setSelectedConfigPath] = createSignal<
string | null
>(null);
>(params.path ? atob(params.path) : null);

const [selectedPreset, setSelectedPreset] = createSignal<string | null>(
null,
Expand Down
1 change: 1 addition & 0 deletions packages/settings-ui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ render(
() => (
<HashRouter>
<Route path="/" component={WidgetConfigs} />
<Route path="/widget/:path" component={WidgetConfigs} />
</HashRouter>
),
document.getElementById('root')!,
Expand Down

0 comments on commit d629530

Please sign in to comment.