diff --git a/.changes/plugin-template-ts7.md b/.changes/plugin-template-ts7.md new file mode 100644 index 000000000000..288916997f9f --- /dev/null +++ b/.changes/plugin-template-ts7.md @@ -0,0 +1,6 @@ +--- +"tauri-cli": patch:deps +"@tauri-apps/cli": patch:deps +--- + +Update typescript to v7 in `tauri plugin init` template. Also fixes the default `rootDir` in the template `tsconfig.json` diff --git a/Cargo.lock b/Cargo.lock index 9d62d961a75d..f97a33cdd6ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1315,7 +1315,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -2492,7 +2492,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -7281,13 +7281,13 @@ dependencies = [ [[package]] name = "rpassword" -version = "7.4.0" +version = "7.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d4c8b64f049c6721ec8ccec37ddfc3d641c4a7fca57e8f2a89de509c73df39" +checksum = "2da316a15f47e3d053de9cb2c439650bd8fa4aaeb9365f2e5f27f492ff73c196" dependencies = [ "libc", "rtoolbox", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -7390,7 +7390,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -7403,7 +7403,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.9.4", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -9350,7 +9350,7 @@ dependencies = [ "getrandom 0.2.15", "once_cell", "rustix 0.38.43", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -10611,7 +10611,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] diff --git a/crates/tauri-cli/templates/plugin/package.json b/crates/tauri-cli/templates/plugin/package.json index 3235e3fd18f9..b22988d92b9e 100644 --- a/crates/tauri-cli/templates/plugin/package.json +++ b/crates/tauri-cli/templates/plugin/package.json @@ -27,7 +27,7 @@ "devDependencies": { "@rollup/plugin-typescript": "^12.0.0", "rollup": "^4.9.6", - "typescript": "^6.0.0", + "typescript": "^7.0.2", "tslib": "^2.6.2" } } diff --git a/crates/tauri-cli/templates/plugin/tsconfig.json b/crates/tauri-cli/templates/plugin/tsconfig.json index 0591122701b9..5e003de104e5 100644 --- a/crates/tauri-cli/templates/plugin/tsconfig.json +++ b/crates/tauri-cli/templates/plugin/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "rootDir": "guest-js", "target": "es2021", "module": "esnext", "moduleResolution": "bundler", diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index 0470b036d943..d24875624330 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -386,7 +386,7 @@ impl Context { self, Message::CreateWebview( window_id, - Box::new(move |window, options| { + Box::new(move |window, _options| { create_webview( WebviewKind::WindowChild, window, @@ -394,7 +394,8 @@ impl Context { webview_id, &context, pending, - options.focused_webview, + #[cfg(windows)] + _options.focused_webview, ) }), tx, @@ -1492,6 +1493,7 @@ pub type CreateWebviewClosure = Box Result + Send>; pub struct CreateWebviewOptions { + #[cfg(windows)] pub focused_webview: Arc>, } @@ -2528,6 +2530,7 @@ impl Drop for WebviewWrapper { } } +#[cfg(windows)] #[derive(Debug)] pub enum FocusState { WindowFocused, @@ -2539,6 +2542,7 @@ pub enum FocusState { }, } +#[cfg(windows)] impl Default for FocusState { fn default() -> Self { Self::Blured { @@ -2561,6 +2565,7 @@ pub struct WindowWrapper { is_window_transparent: bool, #[cfg(windows)] surface: Option, Arc>>, + #[cfg(windows)] focused_webview: Arc>, } @@ -3022,8 +3027,16 @@ impl Runtime for Wry { .0 .borrow() .get(&window_id) - .map(|w| (w.inner.clone(), w.focused_webview.clone())); - if let Some((Some(window), focused_webview)) = window { + .map(|w| { + ( + w.inner.clone(), + CreateWebviewOptions { + #[cfg(windows)] + focused_webview: w.focused_webview.clone(), + }, + ) + }); + if let Some((Some(window), _options)) = window { let window_id_wrapper = Arc::new(Mutex::new(window_id)); let webview_id = self.context.next_webview_id(); @@ -3035,7 +3048,8 @@ impl Runtime for Wry { webview_id, &self.context, pending, - focused_webview, + #[cfg(windows)] + _options.focused_webview, )?; if let Some(w) = self @@ -3312,16 +3326,25 @@ fn handle_user_message( }, Message::Window(id, window_message) => { let w = windows.0.borrow().get(&id).map(|w| { + #[cfg(windows)] + let focused_webview = w.focused_webview.clone(); + #[cfg(not(windows))] + let focused_webview = (); ( w.inner.clone(), w.webviews.clone(), w.has_children.load(Ordering::Relaxed), w.window_event_listeners.clone(), - w.focused_webview.clone(), + focused_webview, ) }); - if let Some((Some(window), webviews, has_children, window_event_listeners, focused_webview)) = - w + if let Some(( + Some(window), + webviews, + has_children, + window_event_listeners, + _focused_webview, + )) = w { match window_message { WindowMessage::AddEventListener(id, listener) => { @@ -3351,12 +3374,15 @@ fn handle_user_message( WindowMessage::IsFullscreen(tx) => tx.send(window.fullscreen().is_some()).unwrap(), WindowMessage::IsMinimized(tx) => tx.send(window.is_minimized()).unwrap(), WindowMessage::IsMaximized(tx) => tx.send(window.is_maximized()).unwrap(), + #[cfg(not(windows))] + WindowMessage::IsFocused(tx) => tx.send(window.is_focused()).unwrap(), + #[cfg(windows)] WindowMessage::IsFocused(tx) => { let focused = if has_children { // on multiwebview mode, get the focused state from cache, // as the window might not have direct focus matches!( - *focused_webview.lock().unwrap(), + *_focused_webview.lock().unwrap(), FocusState::WindowFocused | FocusState::WebviewFocused { .. } ) } else { @@ -4008,13 +4034,17 @@ fn handle_user_message( } } Message::CreateWebview(window_id, handler, sender) => { - let window = windows - .0 - .borrow() - .get(&window_id) - .map(|w| (w.inner.clone(), w.focused_webview.clone())); - if let Some((Some(window), focused_webview)) = window { - match handler(&window, CreateWebviewOptions { focused_webview }) { + let window = windows.0.borrow().get(&window_id).map(|w| { + ( + w.inner.clone(), + CreateWebviewOptions { + #[cfg(windows)] + focused_webview: w.focused_webview.clone(), + }, + ) + }); + if let Some((Some(window), options)) = window { + match handler(&window, options) { Ok(webview) => { if let Some(w) = windows.0.borrow_mut().get_mut(&window_id) { w.webviews.push(webview); @@ -4084,6 +4114,7 @@ fn handle_user_message( is_window_transparent, #[cfg(windows)] surface, + #[cfg(windows)] focused_webview: Default::default(), }, ); @@ -4614,6 +4645,7 @@ fn create_window( let mut webviews = Vec::new(); + #[cfg(windows)] let focused_webview = Arc::new(Mutex::new(FocusState::default())); #[cfg(feature = "unstable")] @@ -4632,6 +4664,7 @@ fn create_window( webview_id, context, webview, + #[cfg(windows)] focused_webview.clone(), )?); } @@ -4666,6 +4699,7 @@ fn create_window( is_window_transparent, #[cfg(windows)] surface, + #[cfg(windows)] focused_webview, }) } @@ -4694,7 +4728,7 @@ fn create_webview( id: WebviewId, context: &Context, pending: PendingWebview>, - #[allow(unused_variables)] focused_webview: Arc>, + #[cfg(windows)] focused_webview: Arc>, ) -> Result { if !context.webview_runtime_installed { #[cfg(all(not(debug_assertions), windows))]