control panel ui
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use tauri::{AppHandle, Manager, WebviewUrl};
|
||||
|
||||
const WINDOW_LABEL: &str = "control-panel";
|
||||
const ACTION_WINDOW_PREFIX: &str = "control-panel-action-";
|
||||
|
||||
pub fn init(handle: &AppHandle) {
|
||||
if let Some(window) = handle.get_webview_window(WINDOW_LABEL) {
|
||||
@@ -33,3 +34,51 @@ pub fn init(handle: &AppHandle) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub fn open_action_window(
|
||||
handle: AppHandle,
|
||||
name: String,
|
||||
title: String,
|
||||
page_url: String,
|
||||
) -> Result<(), String> {
|
||||
if name.is_empty()
|
||||
|| !name
|
||||
.chars()
|
||||
.all(|character| character.is_ascii_alphanumeric() || character == '-')
|
||||
{
|
||||
return Err("Action window name must contain only letters, numbers, or hyphens.".into());
|
||||
}
|
||||
if title.trim().is_empty() || title.chars().count() > 80 {
|
||||
return Err("Action window title must contain between 1 and 80 characters.".into());
|
||||
}
|
||||
if !(page_url.starts_with("/control-panel/add/")
|
||||
|| page_url.starts_with("/control-panel/edit/"))
|
||||
|| page_url.contains("..")
|
||||
|| page_url.contains(['?', '#'])
|
||||
{
|
||||
return Err("Action windows can only open control-panel add or edit pages.".into());
|
||||
}
|
||||
|
||||
let label = format!("{ACTION_WINDOW_PREFIX}{name}");
|
||||
if let Some(window) = handle.get_webview_window(&label) {
|
||||
window.show().map_err(|error| error.to_string())?;
|
||||
window.center().map_err(|error| error.to_string())?;
|
||||
window.set_focus().map_err(|error| error.to_string())?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tauri::WebviewWindowBuilder::new(&handle, label, WebviewUrl::App(page_url.into()))
|
||||
.title(title)
|
||||
.inner_size(300.0, 450.0)
|
||||
.min_inner_size(300.0, 450.0)
|
||||
.resizable(false)
|
||||
.minimizable(false)
|
||||
.maximizable(false)
|
||||
.skip_taskbar(true)
|
||||
.center()
|
||||
.build()
|
||||
.map(|_| ())
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use tauri::AppHandle;
|
||||
|
||||
mod control_panel;
|
||||
pub mod control_panel;
|
||||
#[cfg(debug_assertions)]
|
||||
mod debug;
|
||||
pub mod scene;
|
||||
|
||||
Reference in New Issue
Block a user