mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 11:37:47 +01:00
fix: fix main.ts tauri::Builder::default() repeat (#31)
This commit is contained in:
@@ -1,15 +1,91 @@
|
|||||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||||
|
use tauri::{AppHandle, Manager, WebviewWindow};
|
||||||
|
use tauri_nspanel::{panel_delegate, ManagerExt, WebviewWindowExt};
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn greet(name: &str) -> String {
|
fn greet(name: &str) -> String {
|
||||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn change_window_height(handle: AppHandle, height: u32) {
|
||||||
|
let window: WebviewWindow = handle.get_webview_window("main").unwrap();
|
||||||
|
|
||||||
|
let mut size = window.outer_size().unwrap();
|
||||||
|
size.height = height;
|
||||||
|
window.set_size(size).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn show_panel(handle: AppHandle) {
|
||||||
|
let panel = handle.get_webview_panel("main").unwrap();
|
||||||
|
|
||||||
|
panel.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn hide_panel(handle: AppHandle) {
|
||||||
|
let panel = handle.get_webview_panel("main").unwrap();
|
||||||
|
|
||||||
|
panel.order_out(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn close_panel(handle: AppHandle) {
|
||||||
|
let panel = handle.get_webview_panel("main").unwrap();
|
||||||
|
|
||||||
|
panel.released_when_closed(true);
|
||||||
|
|
||||||
|
panel.close();
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_http::init())
|
.plugin(tauri_plugin_http::init())
|
||||||
.plugin(tauri_plugin_shell::init())
|
.plugin(tauri_plugin_shell::init())
|
||||||
.invoke_handler(tauri::generate_handler![greet])
|
.plugin(tauri_nspanel::init())
|
||||||
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
greet,
|
||||||
|
change_window_height,
|
||||||
|
show_panel,
|
||||||
|
hide_panel,
|
||||||
|
close_panel,
|
||||||
|
])
|
||||||
|
.setup(|app| {
|
||||||
|
init(app.app_handle());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn init(app_handle: &AppHandle) {
|
||||||
|
let window: WebviewWindow = app_handle.get_webview_window("main").unwrap();
|
||||||
|
|
||||||
|
let panel = window.to_panel().unwrap();
|
||||||
|
|
||||||
|
let delegate = panel_delegate!(MyPanelDelegate {
|
||||||
|
window_did_become_key,
|
||||||
|
window_did_resign_key
|
||||||
|
});
|
||||||
|
|
||||||
|
let handle = app_handle.to_owned();
|
||||||
|
|
||||||
|
delegate.set_listener(Box::new(move |delegate_name: String| {
|
||||||
|
match delegate_name.as_str() {
|
||||||
|
"window_did_become_key" => {
|
||||||
|
let app_name = handle.package_info().name.to_owned();
|
||||||
|
|
||||||
|
println!("[info]: {:?} panel becomes key window!", app_name);
|
||||||
|
}
|
||||||
|
"window_did_resign_key" => {
|
||||||
|
println!("[info]: panel resigned from key window!");
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
panel.set_delegate(delegate);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,92 +1,6 @@
|
|||||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||||
#![cfg_attr(
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
not(debug_assertions),
|
|
||||||
windows_subsystem = "windows"
|
|
||||||
)]
|
|
||||||
|
|
||||||
use tauri::{AppHandle, Manager, WebviewWindow};
|
|
||||||
use tauri_nspanel::{panel_delegate, ManagerExt, WebviewWindowExt};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
coco_lib::run();
|
coco_lib::run()
|
||||||
|
|
||||||
tauri::Builder::default()
|
|
||||||
.plugin(tauri_plugin_websocket::init())
|
|
||||||
.plugin(tauri_plugin_http::init())
|
|
||||||
.plugin(tauri_nspanel::init())
|
|
||||||
.invoke_handler(tauri::generate_handler![
|
|
||||||
show_panel,
|
|
||||||
hide_panel,
|
|
||||||
close_panel,
|
|
||||||
change_window_height
|
|
||||||
])
|
|
||||||
.setup(|app| {
|
|
||||||
init(app.app_handle());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.run(tauri::generate_context!())
|
|
||||||
.expect("error while running tauri application");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn init(app_handle: &AppHandle) {
|
|
||||||
let window: WebviewWindow = app_handle.get_webview_window("main").unwrap();
|
|
||||||
|
|
||||||
let panel = window.to_panel().unwrap();
|
|
||||||
|
|
||||||
let delegate = panel_delegate!(MyPanelDelegate {
|
|
||||||
window_did_become_key,
|
|
||||||
window_did_resign_key
|
|
||||||
});
|
|
||||||
|
|
||||||
let handle = app_handle.to_owned();
|
|
||||||
|
|
||||||
delegate.set_listener(Box::new(move |delegate_name: String| {
|
|
||||||
match delegate_name.as_str() {
|
|
||||||
"window_did_become_key" => {
|
|
||||||
let app_name = handle.package_info().name.to_owned();
|
|
||||||
|
|
||||||
println!("[info]: {:?} panel becomes key window!", app_name);
|
|
||||||
}
|
|
||||||
"window_did_resign_key" => {
|
|
||||||
println!("[info]: panel resigned from key window!");
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
panel.set_delegate(delegate);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn change_window_height(handle: AppHandle,height: u32) {
|
|
||||||
let window: WebviewWindow = handle.get_webview_window("main").unwrap();
|
|
||||||
|
|
||||||
let mut size = window.outer_size().unwrap();
|
|
||||||
size.height = height;
|
|
||||||
window.set_size(size).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn show_panel(handle: AppHandle) {
|
|
||||||
let panel = handle.get_webview_panel("main").unwrap();
|
|
||||||
|
|
||||||
panel.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn hide_panel(handle: AppHandle) {
|
|
||||||
let panel = handle.get_webview_panel("main").unwrap();
|
|
||||||
|
|
||||||
panel.order_out(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn close_panel(handle: AppHandle) {
|
|
||||||
let panel = handle.get_webview_panel("main").unwrap();
|
|
||||||
|
|
||||||
panel.released_when_closed(true);
|
|
||||||
|
|
||||||
panel.close();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export default function SearchChat() {
|
|||||||
if (!isTransitioned) {
|
if (!isTransitioned) {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await getCurrentWebviewWindow()?.setSize(new LogicalSize(680, 90));
|
await getCurrentWebviewWindow()?.setSize(new LogicalSize(680, 90));
|
||||||
}, 500);
|
}, 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user