Port
This commit is contained in:
@@ -3,47 +3,50 @@
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
// mod menu;
|
||||
|
||||
use tauri::{webview::{NewWindowResponse, WebviewWindowBuilder}, WebviewUrl};
|
||||
use tauri::{
|
||||
webview::{NewWindowResponse, WebviewWindowBuilder},
|
||||
WebviewUrl,
|
||||
};
|
||||
use tauri_plugin_opener::OpenerExt;
|
||||
|
||||
const LOCALHOST_PORT: u16 = 44_548;
|
||||
|
||||
fn main_window_url() -> WebviewUrl {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
WebviewUrl::default()
|
||||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
let url = format!("http://localhost:{LOCALHOST_PORT}")
|
||||
.parse()
|
||||
.expect("failed to parse localhost app URL");
|
||||
WebviewUrl::External(url)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let port: u16 = 44548;
|
||||
let context = tauri::generate_context!();
|
||||
let builder = tauri::Builder::default();
|
||||
|
||||
// #[cfg(target_os = "macos")]
|
||||
// {
|
||||
// builder = builder.menu(menu::menu());
|
||||
// }
|
||||
|
||||
builder
|
||||
.plugin(tauri_plugin_localhost::Builder::new(port).build())
|
||||
.plugin(tauri_plugin_window_state::Builder::default().build())
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_localhost::Builder::new(LOCALHOST_PORT).build())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.setup(move |app| {
|
||||
// Dev: use devUrl from tauri.conf.json (http://localhost:8080) to support HMR
|
||||
#[cfg(debug_assertions)]
|
||||
let window_url = WebviewUrl::App(Default::default());
|
||||
|
||||
// Release: tauri-plugin-localhost serves bundled frontend assets on this port
|
||||
#[cfg(not(debug_assertions))]
|
||||
let window_url = {
|
||||
let url = format!("http://localhost:{}", port).parse().unwrap();
|
||||
WebviewUrl::External(url)
|
||||
};
|
||||
|
||||
.setup(|app| {
|
||||
let app_handle = app.handle().clone();
|
||||
WebviewWindowBuilder::new(app, "main".to_string(), window_url)
|
||||
.title("Cinny")
|
||||
let builder = WebviewWindowBuilder::new(app, "main", main_window_url());
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
let builder = builder.title("Cinny");
|
||||
|
||||
builder
|
||||
.on_new_window(move |url, _features| {
|
||||
let _ = app_handle.opener().open_url(url.as_str(), None::<&str>);
|
||||
NewWindowResponse::Deny
|
||||
})
|
||||
.build()?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.run(context)
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while building tauri application");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
app_lib::run();
|
||||
}
|
||||
app_lib::run();
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
use tauri::menu::{MenuBuilder, SubmenuBuilder};
|
||||
use tauri::AppHandle;
|
||||
|
||||
pub fn menu() -> tauri::menu::Menu {
|
||||
let app_menu = SubmenuBuilder::new(app, "Cinny")
|
||||
.about(Some(Default::default()))
|
||||
.separator()
|
||||
.hide()
|
||||
.hide_others()
|
||||
.show_all()
|
||||
.separator()
|
||||
.quit()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let edit_menu = SubmenuBuilder::new(app, "Edit")
|
||||
.undo()
|
||||
.redo()
|
||||
.separator()
|
||||
.cut()
|
||||
.copy()
|
||||
.paste()
|
||||
.select_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let view_menu = SubmenuBuilder::new(app, "View")
|
||||
.fullscreen() // `.fullscreen()` works instead of `.enter_fullscreen()`
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let window_menu = SubmenuBuilder::new(app, "Window")
|
||||
.minimize()
|
||||
.build() // no `.zoom()` method directly available
|
||||
.unwrap();
|
||||
|
||||
MenuBuilder::new(app)
|
||||
.item(&app_menu)
|
||||
.item(&edit_menu)
|
||||
.item(&view_menu)
|
||||
.item(&window_menu)
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
Reference in New Issue
Block a user