chore: follow up
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
pub mod folder;
|
||||
pub mod opg;
|
||||
pub mod window;
|
||||
|
||||
69
src-tauri/src/commands/window.rs
Normal file
69
src-tauri/src/commands/window.rs
Normal file
@@ -0,0 +1,69 @@
|
||||
use std::path::PathBuf;
|
||||
use tauri::{LogicalPosition, LogicalSize, Manager, WebviewUrl};
|
||||
|
||||
#[tauri::command]
|
||||
pub fn create_column(
|
||||
label: &str,
|
||||
x: f32,
|
||||
y: f32,
|
||||
width: f32,
|
||||
height: f32,
|
||||
url: &str,
|
||||
app_handle: tauri::AppHandle,
|
||||
) -> Result<String, String> {
|
||||
match app_handle.get_window("main") {
|
||||
Some(main_window) => match app_handle.get_webview(label) {
|
||||
Some(_) => Err("Webview is exist".into()),
|
||||
None => {
|
||||
let path = PathBuf::from(url);
|
||||
let webview_url = WebviewUrl::App(path);
|
||||
let builder = tauri::webview::WebviewBuilder::new(label, webview_url)
|
||||
.auto_resize()
|
||||
.user_agent("Lume/4.0")
|
||||
.transparent(true);
|
||||
match main_window.add_child(
|
||||
builder,
|
||||
LogicalPosition::new(x, y),
|
||||
LogicalSize::new(width, height),
|
||||
) {
|
||||
Ok(webview) => Ok(webview.label().into()),
|
||||
Err(_) => Err("Something is wrong".into()),
|
||||
}
|
||||
}
|
||||
},
|
||||
None => Err("Main window not found".into()),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn close_column(label: &str, app_handle: tauri::AppHandle) -> Result<bool, String> {
|
||||
match app_handle.get_webview(label) {
|
||||
Some(webview) => {
|
||||
if let Ok(_) = webview.close() {
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
None => Err("Webview not found".into()),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn reposition_column(
|
||||
label: &str,
|
||||
x: f32,
|
||||
y: f32,
|
||||
app_handle: tauri::AppHandle,
|
||||
) -> Result<(), String> {
|
||||
match app_handle.get_webview(label) {
|
||||
Some(webview) => {
|
||||
if let Ok(_) = webview.set_position(LogicalPosition::new(x, y)) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Reposition column failed".into())
|
||||
}
|
||||
}
|
||||
None => Err("Webview not found".into()),
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,9 @@ fn main() {
|
||||
commands::folder::show_in_folder,
|
||||
commands::folder::get_accounts,
|
||||
commands::opg::fetch_opg,
|
||||
commands::window::create_column,
|
||||
commands::window::close_column,
|
||||
commands::window::reposition_column
|
||||
])
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while running tauri application")
|
||||
|
||||
Reference in New Issue
Block a user