From c81dff292afc9e9f52470a8d9e34b5a00c14b3a0 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sun, 18 Jun 2023 13:18:20 +0300 Subject: [PATCH 1/5] fix(notification): remove default notification sound on Windows (#440) --- .changes/notification-revert-sound.md | 5 +++++ plugins/notification/src/desktop.rs | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 .changes/notification-revert-sound.md diff --git a/.changes/notification-revert-sound.md b/.changes/notification-revert-sound.md new file mode 100644 index 00000000..b21cb9a6 --- /dev/null +++ b/.changes/notification-revert-sound.md @@ -0,0 +1,5 @@ +--- +"notification": patch +--- + +Revert [7d71ad4e5](https://github.com/tauri-apps/plugins-workspace/commit/7d71ad4e587bcf47ea34645f5b226945e487b765) which added a default sound for notifications on Windows. This introduced inconsistency with other platforms that has silent notifications by default. In the upcoming releases, we will add support for modifying the notification sound across all platforms. diff --git a/plugins/notification/src/desktop.rs b/plugins/notification/src/desktop.rs index 401f6569..897790f0 100644 --- a/plugins/notification/src/desktop.rs +++ b/plugins/notification/src/desktop.rs @@ -184,9 +184,6 @@ mod imp { { notification.app_id(&self.identifier); } - - // will be parsed as a `::winrt_notification::Sound` - notification.sound_name("Default"); } #[cfg(target_os = "macos")] { From 2fc420ba375de924f236f5b32d26667f742fcd6b Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sun, 18 Jun 2023 13:19:04 +0300 Subject: [PATCH 2/5] feat(window): add `incognito` option (#418) Co-authored-by: Lucas Nogueira --- .changes/window-incognito.md | 5 +++++ plugins/window/guest-js/index.ts | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 .changes/window-incognito.md diff --git a/.changes/window-incognito.md b/.changes/window-incognito.md new file mode 100644 index 00000000..5d64fb03 --- /dev/null +++ b/.changes/window-incognito.md @@ -0,0 +1,5 @@ +--- +"window-js": "minor" +--- + +Add `incognito` window configuration option diff --git a/plugins/window/guest-js/index.ts b/plugins/window/guest-js/index.ts index 518383b2..70051edb 100644 --- a/plugins/window/guest-js/index.ts +++ b/plugins/window/guest-js/index.ts @@ -1884,6 +1884,14 @@ interface WindowOptions { * The user agent for the webview. */ userAgent?: string; + /** + * Whether or not the webview should be launched in incognito mode. + * + * #### Platform-specific + * + * - **Android:** Unsupported. + */ + incognito?: boolean; } function mapMonitor(m: Monitor | null): Monitor | null { From c8c3191565aef518037f9f4519886ca98329fe47 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sun, 18 Jun 2023 03:21:27 -0700 Subject: [PATCH 3/5] feat(window): add `setEffects` API (#392) --- .changes/window-set-effects.md | 6 + examples/api/src-tauri/src/lib.rs | 7 +- examples/api/src/views/Window.svelte | 136 +++++++++++++++++ plugins/window/guest-js/index.ts | 195 +++++++++++++++++++++++++ plugins/window/src/api-iife.js | 2 +- plugins/window/src/desktop_commands.rs | 6 +- plugins/window/src/lib.rs | 1 + 7 files changed, 349 insertions(+), 4 deletions(-) create mode 100644 .changes/window-set-effects.md diff --git a/.changes/window-set-effects.md b/.changes/window-set-effects.md new file mode 100644 index 00000000..f2a5d3d9 --- /dev/null +++ b/.changes/window-set-effects.md @@ -0,0 +1,6 @@ +--- +"window": "patch" +"window-js": "patch" +--- + +Added the `setEffects` and `clearEffects` API. diff --git a/examples/api/src-tauri/src/lib.rs b/examples/api/src-tauri/src/lib.rs index 812091e5..00da3ebc 100644 --- a/examples/api/src-tauri/src/lib.rs +++ b/examples/api/src-tauri/src/lib.rs @@ -56,7 +56,7 @@ pub fn run() { #[cfg(desktop)] { window_builder = window_builder - .user_agent("Tauri API") + .user_agent(&format!("Tauri API - {}", std::env::consts::OS)) .title("Tauri API Validation") .inner_size(1000., 800.) .min_inner_size(600., 400.) @@ -71,6 +71,11 @@ pub fn run() { .decorations(false); } + #[cfg(target_os = "macos")] + { + window_builder = window_builder.transparent(true); + } + let window = window_builder.build().unwrap(); #[cfg(debug_assertions)] diff --git a/examples/api/src/views/Window.svelte b/examples/api/src/views/Window.svelte index 2d4a8c61..c8c1a20b 100644 --- a/examples/api/src/views/Window.svelte +++ b/examples/api/src/views/Window.svelte @@ -6,6 +6,8 @@ UserAttentionType, PhysicalSize, PhysicalPosition, + Effect, + EffectState, } from "@tauri-apps/plugin-window"; import { open as openDialog } from "@tauri-apps/plugin-dialog"; import { open } from "@tauri-apps/plugin-shell"; @@ -57,7 +59,20 @@ "rowResize", ]; + const windowsEffects = ["mica", "blur", "acrylic"]; + const isWindows = navigator.appVersion.includes("windows"); + const isMacOS = navigator.appVersion.includes("macos"); + let effectOptions = isWindows + ? windowsEffects + : Object.keys(Effect) + .map((effect) => Effect[effect]) + .filter((e) => !windowsEffects.includes(e)); + const effectStateOptions = Object.keys(EffectState).map( + (state) => EffectState[state] + ); + export let onMessage; + const mainEl = document.querySelector("main"); let newWindowLabel; @@ -91,6 +106,12 @@ let cursorIgnoreEvents = false; let windowTitle = "Awesome Tauri Example!"; + let effects = []; + let selectedEffect; + let effectState; + let effectRadius; + let effectR, effectG, effectB, effectA; + function openUrl() { open(urlValue); } @@ -172,6 +193,38 @@ await windowMap[selectedWindow].requestUserAttention(null); } + async function addEffect() { + if (!effects.includes(selectedEffect)) { + effects = [...effects, selectedEffect]; + } + + const payload = { + effects, + state: effectState, + radius: effectRadius, + }; + if ( + Number.isInteger(effectR) && + Number.isInteger(effectG) && + Number.isInteger(effectB) && + Number.isInteger(effectA) + ) { + payload.color = [effectR, effectG, effectB, effectA]; + } + + mainEl.classList.remove("bg-primary"); + mainEl.classList.remove("dark:bg-darkPrimary"); + await windowMap[selectedWindow].clearEffects(); + await windowMap[selectedWindow].setEffects(payload); + } + + async function clearEffects() { + effects = []; + await windowMap[selectedWindow].clearEffects(); + mainEl.classList.add("bg-primary"); + mainEl.classList.add("dark:bg-darkPrimary"); + } + $: { windowMap[selectedWindow]; loadWindowPosition(); @@ -455,5 +508,88 @@ + +
+ + {#if isWindows || isMacOS} +
+
+ + + + + +
+ +
+ +
+ +
+ +
+ +
+
+ Applied effects: {effects.length ? effects.join(",") : "None"} +
+ + +
+
+ {/if} {/if} diff --git a/plugins/window/guest-js/index.ts b/plugins/window/guest-js/index.ts index 70051edb..79b45059 100644 --- a/plugins/window/guest-js/index.ts +++ b/plugins/window/guest-js/index.ts @@ -950,6 +950,30 @@ class WindowManager extends WebviewWindowHandle { }); } + /** + * Set window effects. + * + * @since 2.0 + */ + async setEffects(effects: Effects): Promise { + return window.__TAURI_INVOKE__("plugin:window|set_effects", { + label: this.label, + value: effects, + }); + } + + /** + * Clear any applied effects if possible. + * + * @since 2.0 + */ + async clearEffects(): Promise { + return window.__TAURI_INVOKE__("plugin:window|set_effects", { + label: this.label, + value: null, + }); + } + /** * Whether the window should always be on top of other windows. * @example @@ -1777,6 +1801,174 @@ if ("__TAURI_METADATA__" in window) { }); } +/** + * an array RGBA colors. Each value has minimum of 0 and maximum of 255. + * + * @since 2.0 + */ +type Color = [number, number, number, number]; + +/** + * Platform-specific window effects + * + * @since 2.0 + */ +enum Effect { + /** + * A default material appropriate for the view's effectiveAppearance. **macOS 10.14-** + * + * @deprecated since macOS 10.14. You should instead choose an appropriate semantic material. + */ + AppearanceBased = "appearanceBased", + /** + * **macOS 10.14-** + * + * @deprecated since macOS 10.14. Use a semantic material instead. + */ + Light = "light", + /** + * **macOS 10.14-** + * + * @deprecated since macOS 10.14. Use a semantic material instead. + */ + Dark = "dark", + /** + * **macOS 10.14-** + * + * @deprecated since macOS 10.14. Use a semantic material instead. + */ + MediumLight = "mediumLight", + /** + * **macOS 10.14-** + * + * @deprecated since macOS 10.14. Use a semantic material instead. + */ + UltraDark = "ultraDark", + /** + * **macOS 10.10+** + */ + Titlebar = "titlebar", + /** + * **macOS 10.10+** + */ + Selection = "selection", + /** + * **macOS 10.11+** + */ + Menu = "menu", + /** + * **macOS 10.11+** + */ + Popover = "popover", + /** + * **macOS 10.11+** + */ + Sidebar = "sidebar", + /** + * **macOS 10.14+** + */ + HeaderView = "headerView", + /** + * **macOS 10.14+** + */ + Sheet = "sheet", + /** + * **macOS 10.14+** + */ + WindowBackground = "windowBackground", + /** + * **macOS 10.14+** + */ + HudWindow = "hudWindow", + /** + * **macOS 10.14+** + */ + FullScreenUI = "fullScreenUI", + /** + * **macOS 10.14+** + */ + Tooltip = "tooltip", + /** + * **macOS 10.14+** + */ + ContentBackground = "contentBackground", + /** + * **macOS 10.14+** + */ + UnderWindowBackground = "underWindowBackground", + /** + * **macOS 10.14+** + */ + UnderPageBackground = "underPageBackground", + /** + * **Windows 11 Only** + */ + Mica = "mica", + /** + * **Windows 7/10/11(22H1) Only** + * + * ## Notes + * + * This effect has bad performance when resizing/dragging the window on Windows 11 build 22621. + */ + Blur = "blur", + /** + * **Windows 10/11** + * + * ## Notes + * + * This effect has bad performance when resizing/dragging the window on Windows 10 v1903+ and Windows 11 build 22000. + */ + Acrylic = "acrylic", +} + +/** + * Window effect state **macOS only** + * + * @see https://developer.apple.com/documentation/appkit/nsvisualeffectview/state + * + * @since 2.0 + */ +enum EffectState { + /** + * Make window effect state follow the window's active state **macOS only** + */ + FollowsWindowActiveState = "followsWindowActiveState", + /** + * Make window effect state always active **macOS only** + */ + Active = "active", + /** + * Make window effect state always inactive **macOS only** + */ + Inactive = "inactive", +} + +/** The window effects configuration object + * + * @since 2.0 + */ +interface Effects { + /** + * List of Window effects to apply to the Window. + * Conflicting effects will apply the first one and ignore the rest. + */ + effects: Effect[]; + /** + * Window effect state **macOS Only** + */ + state?: EffectState; + /** + * Window effect corner radius **macOS Only** + */ + radius?: number; + /** + * Window effect color. Affects {@link Effects.Blur} and {@link Effects.Acrylic} only + * on Windows 10 v1903+. Doesn't have any effect on Windows 7 or Windows 11. + */ + color?: Color; +} + /** * Configuration for the window to create. * @@ -1976,6 +2168,8 @@ export { LogicalPosition, PhysicalPosition, UserAttentionType, + Effect, + EffectState, currentMonitor, primaryMonitor, availableMonitors, @@ -1988,4 +2182,5 @@ export type { ScaleFactorChanged, FileDropEvent, WindowOptions, + Color, }; diff --git a/plugins/window/src/api-iife.js b/plugins/window/src/api-iife.js index 2079c27b..0dd18524 100644 --- a/plugins/window/src/api-iife.js +++ b/plugins/window/src/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_WINDOW__=function(e){"use strict";var i=Object.defineProperty,n=(e,n)=>{for(var t in n)i(e,t,{get:n[t],enumerable:!0})},t=(e,i,n)=>{if(!i.has(e))throw TypeError("Cannot "+n)},l=(e,i,n)=>(t(e,i,"read from private field"),n?n.call(e):i.get(e)),a=(e,i,n,l)=>(t(e,i,"write to private field"),l?l.call(e,n):i.set(e,n),n);function s(e,i=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],t=`_${n}`;return Object.defineProperty(window,t,{value:n=>(i&&Reflect.deleteProperty(window,t),e?.(n)),writable:!1,configurable:!0}),n}n({},{Channel:()=>o,PluginListener:()=>_,addPluginListener:()=>w,convertFileSrc:()=>c,invoke:()=>u,transformCallback:()=>s});var r,o=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,i,n)=>{if(i.has(e))throw TypeError("Cannot add the same private member more than once");i instanceof WeakSet?i.add(e):i.set(e,n)})(this,r,(()=>{})),this.id=s((e=>{l(this,r).call(this,e)}))}set onmessage(e){a(this,r,e)}get onmessage(){return l(this,r)}toJSON(){return`__CHANNEL__:${this.id}`}};r=new WeakMap;var _=class{constructor(e,i,n){this.plugin=e,this.event=i,this.channelId=n}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function w(e,i,n){let t=new o;return t.onmessage=n,u(`plugin:${e}|register_listener`,{event:i,handler:t}).then((()=>new _(e,i,t.id)))}async function u(e,i={}){return new Promise(((n,t)=>{let l=s((e=>{n(e),Reflect.deleteProperty(window,`_${a}`)}),!0),a=s((e=>{t(e),Reflect.deleteProperty(window,`_${l}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:l,error:a,...i})}))}function c(e,i="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${i}.localhost/${n}`:`${i}://localhost/${n}`}n({},{TauriEvent:()=>h,emit:()=>b,listen:()=>y,once:()=>I});var d,h=(e=>(e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_CREATED="tauri://window-created",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WINDOW_FILE_DROP="tauri://file-drop",e.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",e.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",e.MENU="tauri://menu",e))(h||{});async function p(e,i){await u("plugin:event|unlisten",{event:e,eventId:i})}async function y(e,i,n){return u("plugin:event|listen",{event:e,windowLabel:n?.target,handler:s(i)}).then((i=>async()=>p(e,i)))}async function I(e,i,n){return y(e,(n=>{i(n),p(e,n.id).catch((()=>{}))}),n)}async function b(e,i,n){await u("plugin:event|emit",{event:e,windowLabel:n?.target,payload:i})}class g{constructor(e,i){this.type="Logical",this.width=e,this.height=i}}class E{constructor(e,i){this.type="Physical",this.width=e,this.height=i}toLogical(e){return new g(this.width/e,this.height/e)}}class A{constructor(e,i){this.type="Logical",this.x=e,this.y=i}}class O{constructor(e,i){this.type="Physical",this.x=e,this.y=i}toLogical(e){return new A(this.x/e,this.y/e)}}function T(){return window.__TAURI_METADATA__.__windows.map((e=>new U(e.label,{skip:!0})))}e.UserAttentionType=void 0,(d=e.UserAttentionType||(e.UserAttentionType={}))[d.Critical=1]="Critical",d[d.Informational=2]="Informational";const R=["tauri://created","tauri://error"];class N{constructor(e){this.label=e,this.listeners=Object.create(null)}async listen(e,i){return this._handleTauriEvent(e,i)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)})):y(e,i,{target:this.label})}async once(e,i){return this._handleTauriEvent(e,i)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)})):I(e,i,{target:this.label})}async emit(e,i){if(R.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,windowLabel:this.label,payload:i});return Promise.resolve()}return b(e,i,{target:this.label})}_handleTauriEvent(e,i){return!!R.includes(e)&&(e in this.listeners?this.listeners[e].push(i):this.listeners[e]=[i],!0)}}class m extends N{async scaleFactor(){return window.__TAURI_INVOKE__("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return window.__TAURI_INVOKE__("plugin:window|inner_position",{label:this.label}).then((({x:e,y:i})=>new O(e,i)))}async outerPosition(){return window.__TAURI_INVOKE__("plugin:window|outer_position",{label:this.label}).then((({x:e,y:i})=>new O(e,i)))}async innerSize(){return window.__TAURI_INVOKE__("plugin:window|inner_size",{label:this.label}).then((({width:e,height:i})=>new E(e,i)))}async outerSize(){return window.__TAURI_INVOKE__("plugin:window|outer_size",{label:this.label}).then((({width:e,height:i})=>new E(e,i)))}async isFullscreen(){return window.__TAURI_INVOKE__("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return window.__TAURI_INVOKE__("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return window.__TAURI_INVOKE__("plugin:window|is_maximized",{label:this.label})}async isDecorated(){return window.__TAURI_INVOKE__("plugin:window|is_decorated",{label:this.label})}async isResizable(){return window.__TAURI_INVOKE__("plugin:window|is_resizable",{label:this.label})}async isVisible(){return window.__TAURI_INVOKE__("plugin:window|is_visible",{label:this.label})}async title(){return window.__TAURI_INVOKE__("plugin:window|title",{label:this.label})}async theme(){return window.__TAURI_INVOKE__("plugin:window|theme",{label:this.label})}async center(){return window.__TAURI_INVOKE__("plugin:window|center",{label:this.label})}async requestUserAttention(i){let n=null;return i&&(n=i===e.UserAttentionType.Critical?{type:"Critical"}:{type:"Informational"}),window.__TAURI_INVOKE__("plugin:window|request_user_attention",{label:this.label,value:n})}async setResizable(e){return window.__TAURI_INVOKE__("plugin:window|set_resizable",{label:this.label,value:e})}async setTitle(e){return window.__TAURI_INVOKE__("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return window.__TAURI_INVOKE__("plugin:window|maximize",{label:this.label})}async unmaximize(){return window.__TAURI_INVOKE__("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return window.__TAURI_INVOKE__("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return window.__TAURI_INVOKE__("plugin:window|minimize",{label:this.label})}async unminimize(){return window.__TAURI_INVOKE__("plugin:window|unminimize",{label:this.label})}async show(){return window.__TAURI_INVOKE__("plugin:window|show",{label:this.label})}async hide(){return window.__TAURI_INVOKE__("plugin:window|hide",{label:this.label})}async close(){return window.__TAURI_INVOKE__("plugin:window|close",{label:this.label})}async setDecorations(e){return window.__TAURI_INVOKE__("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return window.__TAURI_INVOKE__("plugin:window|set_shadow",{label:this.label,value:e})}async setAlwaysOnTop(e){return window.__TAURI_INVOKE__("plugin:window|set_always_on_top",{label:this.label,value:e})}async setContentProtected(e){return window.__TAURI_INVOKE__("plugin:window|set_content_protected",{label:this.label,value:e})}async setSize(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_size",{label:this.label,value:{type:e.type,data:{width:e.width,height:e.height}}})}async setMinSize(e){if(e&&"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_min_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setMaxSize(e){if(e&&"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_max_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setPosition(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return window.__TAURI_INVOKE__("plugin:window|set_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setFullscreen(e){return window.__TAURI_INVOKE__("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return window.__TAURI_INVOKE__("plugin:window|set_focus",{label:this.label})}async setIcon(e){return window.__TAURI_INVOKE__("plugin:window|set_icon",{label:this.label,value:"string"==typeof e?e:Array.from(e)})}async setSkipTaskbar(e){return window.__TAURI_INVOKE__("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_icon",{label:this.label,value:e})}async setCursorPosition(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return window.__TAURI_INVOKE__("plugin:window|set_cursor_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setIgnoreCursorEvents(e){return window.__TAURI_INVOKE__("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return window.__TAURI_INVOKE__("plugin:window|start_dragging",{label:this.label})}async onResized(e){return this.listen(h.WINDOW_RESIZED,(i=>{i.payload=D(i.payload),e(i)}))}async onMoved(e){return this.listen(h.WINDOW_MOVED,(i=>{i.payload=W(i.payload),e(i)}))}async onCloseRequested(e){return this.listen(h.WINDOW_CLOSE_REQUESTED,(i=>{const n=new v(i);Promise.resolve(e(n)).then((()=>{if(!n.isPreventDefault())return this.close()}))}))}async onFocusChanged(e){const i=await this.listen(h.WINDOW_FOCUS,(i=>{e({...i,payload:!0})})),n=await this.listen(h.WINDOW_BLUR,(i=>{e({...i,payload:!1})}));return()=>{i(),n()}}async onScaleChanged(e){return this.listen(h.WINDOW_SCALE_FACTOR_CHANGED,e)}async onMenuClicked(e){return this.listen(h.MENU,e)}async onFileDropEvent(e){const i=await this.listen(h.WINDOW_FILE_DROP,(i=>{e({...i,payload:{type:"drop",paths:i.payload}})})),n=await this.listen(h.WINDOW_FILE_DROP_HOVER,(i=>{e({...i,payload:{type:"hover",paths:i.payload}})})),t=await this.listen(h.WINDOW_FILE_DROP_CANCELLED,(i=>{e({...i,payload:{type:"cancel"}})}));return()=>{i(),n(),t()}}async onThemeChanged(e){return this.listen(h.WINDOW_THEME_CHANGED,e)}}class v{constructor(e){this._preventDefault=!1,this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}class U extends m{constructor(e,i={}){super(e),(null==i?void 0:i.skip)||window.__TAURI_INVOKE__("plugin:window|create",{options:{...i,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return T().some((i=>i.label===e))?new U(e,{skip:!0}):null}}function f(e){return null===e?null:{name:e.name,scaleFactor:e.scaleFactor,position:W(e.position),size:D(e.size)}}function W(e){return new O(e.x,e.y)}function D(e){return new E(e.width,e.height)}return e.appWindow=void 0,"__TAURI_METADATA__"in window?e.appWindow=new U(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0}):(console.warn('Could not find "window.__TAURI_METADATA__". The "appWindow" value will reference the "main" window label.\nNote that this is not an issue if running this frontend on a browser instead of a Tauri window.'),e.appWindow=new U("main",{skip:!0})),e.CloseRequestedEvent=v,e.LogicalPosition=A,e.LogicalSize=g,e.PhysicalPosition=O,e.PhysicalSize=E,e.WebviewWindow=U,e.WebviewWindowHandle=N,e.WindowManager=m,e.availableMonitors=async function(){return window.__TAURI_INVOKE__("plugin:window|available_monitors").then((e=>e.map(f)))},e.currentMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|current_monitor").then(f)},e.getAll=T,e.getCurrent=function(){return new U(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0})},e.primaryMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|primary_monitor").then(f)},e}({});Object.defineProperty(window.__TAURI__,"window",{value:__TAURI_WINDOW__})} +if("__TAURI__"in window){var __TAURI_WINDOW__=function(e){"use strict";var i=Object.defineProperty,n=(e,n)=>{for(var t in n)i(e,t,{get:n[t],enumerable:!0})},t=(e,i,n)=>{if(!i.has(e))throw TypeError("Cannot "+n)},a=(e,i,n)=>(t(e,i,"read from private field"),n?n.call(e):i.get(e)),l=(e,i,n,a)=>(t(e,i,"write to private field"),a?a.call(e,n):i.set(e,n),n);function s(e,i=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],t=`_${n}`;return Object.defineProperty(window,t,{value:n=>(i&&Reflect.deleteProperty(window,t),e?.(n)),writable:!1,configurable:!0}),n}n({},{Channel:()=>o,PluginListener:()=>_,addPluginListener:()=>w,convertFileSrc:()=>c,invoke:()=>u,transformCallback:()=>s});var r,o=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,i,n)=>{if(i.has(e))throw TypeError("Cannot add the same private member more than once");i instanceof WeakSet?i.add(e):i.set(e,n)})(this,r,(()=>{})),this.id=s((e=>{a(this,r).call(this,e)}))}set onmessage(e){l(this,r,e)}get onmessage(){return a(this,r)}toJSON(){return`__CHANNEL__:${this.id}`}};r=new WeakMap;var _=class{constructor(e,i,n){this.plugin=e,this.event=i,this.channelId=n}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function w(e,i,n){let t=new o;return t.onmessage=n,u(`plugin:${e}|register_listener`,{event:i,handler:t}).then((()=>new _(e,i,t.id)))}async function u(e,i={}){return new Promise(((n,t)=>{let a=s((e=>{n(e),Reflect.deleteProperty(window,`_${l}`)}),!0),l=s((e=>{t(e),Reflect.deleteProperty(window,`_${a}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:a,error:l,...i})}))}function c(e,i="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${i}.localhost/${n}`:`${i}://localhost/${n}`}n({},{TauriEvent:()=>h,emit:()=>g,listen:()=>y,once:()=>I});var d,h=(e=>(e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_CREATED="tauri://window-created",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WINDOW_FILE_DROP="tauri://file-drop",e.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",e.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",e.MENU="tauri://menu",e))(h||{});async function p(e,i){await u("plugin:event|unlisten",{event:e,eventId:i})}async function y(e,i,n){return u("plugin:event|listen",{event:e,windowLabel:n?.target,handler:s(i)}).then((i=>async()=>p(e,i)))}async function I(e,i,n){return y(e,(n=>{i(n),p(e,n.id).catch((()=>{}))}),n)}async function g(e,i,n){await u("plugin:event|emit",{event:e,windowLabel:n?.target,payload:i})}class b{constructor(e,i){this.type="Logical",this.width=e,this.height=i}}class E{constructor(e,i){this.type="Physical",this.width=e,this.height=i}toLogical(e){return new b(this.width/e,this.height/e)}}class A{constructor(e,i){this.type="Logical",this.x=e,this.y=i}}class O{constructor(e,i){this.type="Physical",this.x=e,this.y=i}toLogical(e){return new A(this.x/e,this.y/e)}}function T(){return window.__TAURI_METADATA__.__windows.map((e=>new N(e.label,{skip:!0})))}e.UserAttentionType=void 0,(d=e.UserAttentionType||(e.UserAttentionType={}))[d.Critical=1]="Critical",d[d.Informational=2]="Informational";const v=["tauri://created","tauri://error"];class f{constructor(e){this.label=e,this.listeners=Object.create(null)}async listen(e,i){return this._handleTauriEvent(e,i)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)})):y(e,i,{target:this.label})}async once(e,i){return this._handleTauriEvent(e,i)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)})):I(e,i,{target:this.label})}async emit(e,i){if(v.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,windowLabel:this.label,payload:i});return Promise.resolve()}return g(e,i,{target:this.label})}_handleTauriEvent(e,i){return!!v.includes(e)&&(e in this.listeners?this.listeners[e].push(i):this.listeners[e]=[i],!0)}}class R extends f{async scaleFactor(){return window.__TAURI_INVOKE__("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return window.__TAURI_INVOKE__("plugin:window|inner_position",{label:this.label}).then((({x:e,y:i})=>new O(e,i)))}async outerPosition(){return window.__TAURI_INVOKE__("plugin:window|outer_position",{label:this.label}).then((({x:e,y:i})=>new O(e,i)))}async innerSize(){return window.__TAURI_INVOKE__("plugin:window|inner_size",{label:this.label}).then((({width:e,height:i})=>new E(e,i)))}async outerSize(){return window.__TAURI_INVOKE__("plugin:window|outer_size",{label:this.label}).then((({width:e,height:i})=>new E(e,i)))}async isFullscreen(){return window.__TAURI_INVOKE__("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return window.__TAURI_INVOKE__("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return window.__TAURI_INVOKE__("plugin:window|is_maximized",{label:this.label})}async isDecorated(){return window.__TAURI_INVOKE__("plugin:window|is_decorated",{label:this.label})}async isResizable(){return window.__TAURI_INVOKE__("plugin:window|is_resizable",{label:this.label})}async isVisible(){return window.__TAURI_INVOKE__("plugin:window|is_visible",{label:this.label})}async title(){return window.__TAURI_INVOKE__("plugin:window|title",{label:this.label})}async theme(){return window.__TAURI_INVOKE__("plugin:window|theme",{label:this.label})}async center(){return window.__TAURI_INVOKE__("plugin:window|center",{label:this.label})}async requestUserAttention(i){let n=null;return i&&(n=i===e.UserAttentionType.Critical?{type:"Critical"}:{type:"Informational"}),window.__TAURI_INVOKE__("plugin:window|request_user_attention",{label:this.label,value:n})}async setResizable(e){return window.__TAURI_INVOKE__("plugin:window|set_resizable",{label:this.label,value:e})}async setTitle(e){return window.__TAURI_INVOKE__("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return window.__TAURI_INVOKE__("plugin:window|maximize",{label:this.label})}async unmaximize(){return window.__TAURI_INVOKE__("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return window.__TAURI_INVOKE__("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return window.__TAURI_INVOKE__("plugin:window|minimize",{label:this.label})}async unminimize(){return window.__TAURI_INVOKE__("plugin:window|unminimize",{label:this.label})}async show(){return window.__TAURI_INVOKE__("plugin:window|show",{label:this.label})}async hide(){return window.__TAURI_INVOKE__("plugin:window|hide",{label:this.label})}async close(){return window.__TAURI_INVOKE__("plugin:window|close",{label:this.label})}async setDecorations(e){return window.__TAURI_INVOKE__("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return window.__TAURI_INVOKE__("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return window.__TAURI_INVOKE__("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return window.__TAURI_INVOKE__("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return window.__TAURI_INVOKE__("plugin:window|set_always_on_top",{label:this.label,value:e})}async setContentProtected(e){return window.__TAURI_INVOKE__("plugin:window|set_content_protected",{label:this.label,value:e})}async setSize(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_size",{label:this.label,value:{type:e.type,data:{width:e.width,height:e.height}}})}async setMinSize(e){if(e&&"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_min_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setMaxSize(e){if(e&&"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_max_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setPosition(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return window.__TAURI_INVOKE__("plugin:window|set_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setFullscreen(e){return window.__TAURI_INVOKE__("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return window.__TAURI_INVOKE__("plugin:window|set_focus",{label:this.label})}async setIcon(e){return window.__TAURI_INVOKE__("plugin:window|set_icon",{label:this.label,value:"string"==typeof e?e:Array.from(e)})}async setSkipTaskbar(e){return window.__TAURI_INVOKE__("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_icon",{label:this.label,value:e})}async setCursorPosition(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return window.__TAURI_INVOKE__("plugin:window|set_cursor_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setIgnoreCursorEvents(e){return window.__TAURI_INVOKE__("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return window.__TAURI_INVOKE__("plugin:window|start_dragging",{label:this.label})}async onResized(e){return this.listen(h.WINDOW_RESIZED,(i=>{i.payload=K(i.payload),e(i)}))}async onMoved(e){return this.listen(h.WINDOW_MOVED,(i=>{i.payload=V(i.payload),e(i)}))}async onCloseRequested(e){return this.listen(h.WINDOW_CLOSE_REQUESTED,(i=>{const n=new m(i);Promise.resolve(e(n)).then((()=>{if(!n.isPreventDefault())return this.close()}))}))}async onFocusChanged(e){const i=await this.listen(h.WINDOW_FOCUS,(i=>{e({...i,payload:!0})})),n=await this.listen(h.WINDOW_BLUR,(i=>{e({...i,payload:!1})}));return()=>{i(),n()}}async onScaleChanged(e){return this.listen(h.WINDOW_SCALE_FACTOR_CHANGED,e)}async onMenuClicked(e){return this.listen(h.MENU,e)}async onFileDropEvent(e){const i=await this.listen(h.WINDOW_FILE_DROP,(i=>{e({...i,payload:{type:"drop",paths:i.payload}})})),n=await this.listen(h.WINDOW_FILE_DROP_HOVER,(i=>{e({...i,payload:{type:"hover",paths:i.payload}})})),t=await this.listen(h.WINDOW_FILE_DROP_CANCELLED,(i=>{e({...i,payload:{type:"cancel"}})}));return()=>{i(),n(),t()}}async onThemeChanged(e){return this.listen(h.WINDOW_THEME_CHANGED,e)}}class m{constructor(e){this._preventDefault=!1,this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}class N extends R{constructor(e,i={}){super(e),(null==i?void 0:i.skip)||window.__TAURI_INVOKE__("plugin:window|create",{options:{...i,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return T().some((i=>i.label===e))?new N(e,{skip:!0}):null}}var U,W;function D(e){return null===e?null:{name:e.name,scaleFactor:e.scaleFactor,position:V(e.position),size:K(e.size)}}function V(e){return new O(e.x,e.y)}function K(e){return new E(e.width,e.height)}return e.appWindow=void 0,"__TAURI_METADATA__"in window?e.appWindow=new N(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0}):(console.warn('Could not find "window.__TAURI_METADATA__". The "appWindow" value will reference the "main" window label.\nNote that this is not an issue if running this frontend on a browser instead of a Tauri window.'),e.appWindow=new N("main",{skip:!0})),e.Effect=void 0,(U=e.Effect||(e.Effect={})).AppearanceBased="appearanceBased",U.Light="light",U.Dark="dark",U.MediumLight="mediumLight",U.UltraDark="ultraDark",U.Titlebar="titlebar",U.Selection="selection",U.Menu="menu",U.Popover="popover",U.Sidebar="sidebar",U.HeaderView="headerView",U.Sheet="sheet",U.WindowBackground="windowBackground",U.HudWindow="hudWindow",U.FullScreenUI="fullScreenUI",U.Tooltip="tooltip",U.ContentBackground="contentBackground",U.UnderWindowBackground="underWindowBackground",U.UnderPageBackground="underPageBackground",U.Mica="mica",U.Blur="blur",U.Acrylic="acrylic",e.EffectState=void 0,(W=e.EffectState||(e.EffectState={})).FollowsWindowActiveState="followsWindowActiveState",W.Active="active",W.Inactive="inactive",e.CloseRequestedEvent=m,e.LogicalPosition=A,e.LogicalSize=b,e.PhysicalPosition=O,e.PhysicalSize=E,e.WebviewWindow=N,e.WebviewWindowHandle=f,e.WindowManager=R,e.availableMonitors=async function(){return window.__TAURI_INVOKE__("plugin:window|available_monitors").then((e=>e.map(D)))},e.currentMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|current_monitor").then(D)},e.getAll=T,e.getCurrent=function(){return new N(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0})},e.primaryMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|primary_monitor").then(D)},e}({});Object.defineProperty(window.__TAURI__,"window",{value:__TAURI_WINDOW__})} diff --git a/plugins/window/src/desktop_commands.rs b/plugins/window/src/desktop_commands.rs index 135e8d80..df2f9c75 100644 --- a/plugins/window/src/desktop_commands.rs +++ b/plugins/window/src/desktop_commands.rs @@ -4,8 +4,9 @@ use serde::{Deserialize, Serialize, Serializer}; use tauri::{ - utils::config::WindowConfig, AppHandle, CursorIcon, Icon, Manager, Monitor, PhysicalPosition, - PhysicalSize, Position, Runtime, Size, Theme, UserAttentionType, Window, + utils::config::{WindowConfig, WindowEffectsConfig}, + AppHandle, CursorIcon, Icon, Manager, Monitor, PhysicalPosition, PhysicalSize, Position, + Runtime, Size, Theme, UserAttentionType, Window, }; #[derive(Debug, thiserror::Error)] @@ -133,6 +134,7 @@ setter!(hide); setter!(close); setter!(set_decorations, bool); setter!(set_shadow, bool); +setter!(set_effects, Option); setter!(set_always_on_top, bool); setter!(set_content_protected, bool); setter!(set_size, Size); diff --git a/plugins/window/src/lib.rs b/plugins/window/src/lib.rs index 1efeae15..d4e30151 100644 --- a/plugins/window/src/lib.rs +++ b/plugins/window/src/lib.rs @@ -62,6 +62,7 @@ pub fn init() -> TauriPlugin { desktop_commands::close, desktop_commands::set_decorations, desktop_commands::set_shadow, + desktop_commands::set_effects, desktop_commands::set_always_on_top, desktop_commands::set_content_protected, desktop_commands::set_size, From db7f4f9a418690de0ee3e9b102eb5eaab30cc0ef Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sun, 18 Jun 2023 13:35:07 +0300 Subject: [PATCH 4/5] refactor(os): refactor EOL const (#427) Co-authored-by: Lucas Nogueira --- .changes/os-plugin-refactor.md | 1 + .eslintignore | 3 ++- Cargo.lock | 1 + plugins/os/Cargo.toml | 1 + plugins/os/guest-js/index.ts | 15 ++++++++------- plugins/os/src/api-iife.js | 2 +- plugins/os/src/init.js | 8 ++++++++ plugins/os/src/lib.rs | 22 +++++++++++++++++++++- 8 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 plugins/os/src/init.js diff --git a/.changes/os-plugin-refactor.md b/.changes/os-plugin-refactor.md index 63cd5bdd..ff0f7384 100644 --- a/.changes/os-plugin-refactor.md +++ b/.changes/os-plugin-refactor.md @@ -9,3 +9,4 @@ The os plugin is recieving a few changes to improve consistency and add new feat - Added `family()`,`exe_extension()`, and `hostname()` functions and their equivalents for JS. - Removed `tempdir()` function and its equivalent on JS, use `std::env::temp_dir` instead of `temp_dir` from `tauri::path::PathResolver::temp_dir` and `path.tempDir` on JS. - Modified `platform()` implementation to return `windows` instead of `win32` and `macos` instead of `darwin` to align with Rust's `std::env::consts::OS` +- `EOL` const in JS has been modified into a function `eol()` fix import issues in frameworks like `next.js` diff --git a/.eslintignore b/.eslintignore index efef8f77..329feacb 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,4 +2,5 @@ target node_modules dist dist-js -api-iife.js \ No newline at end of file +api-iife.js +init.js \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index d5c3a540..4664da11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5298,6 +5298,7 @@ dependencies = [ "os_info", "serde", "serde_json", + "serialize-to-javascript", "sys-locale", "tauri", "thiserror", diff --git a/plugins/os/Cargo.toml b/plugins/os/Cargo.toml index ef2f8a6d..e2280410 100644 --- a/plugins/os/Cargo.toml +++ b/plugins/os/Cargo.toml @@ -15,3 +15,4 @@ thiserror = { workspace = true } os_info = "3" sys-locale = "0.3" gethostname = "0.4" +serialize-to-javascript = "=0.1.1" diff --git a/plugins/os/guest-js/index.ts b/plugins/os/guest-js/index.ts index 2b94895d..5c85b579 100644 --- a/plugins/os/guest-js/index.ts +++ b/plugins/os/guest-js/index.ts @@ -11,6 +11,9 @@ declare global { interface Window { __TAURI_INVOKE__: (cmd: string, args?: unknown) => Promise; + __TAURI__: { + os: { __eol: string }; + }; } } @@ -41,18 +44,16 @@ type Arch = | "s390x" | "sparc64"; -function isWindows(): boolean { - return navigator.appVersion.includes("Win"); -} - /** - * The operating system-specific end-of-line marker. + * Returns the operating system-specific end-of-line marker. * - `\n` on POSIX * - `\r\n` on Windows * * @since 2.0.0 * */ -const EOL = isWindows() ? "\r\n" : "\n"; +function eol() { + return window.__TAURI__.os.__eol; +} /** * Returns a string describing the specific operating system in use. @@ -174,7 +175,7 @@ async function hostname(): Promise { } export { - EOL, + eol, platform, family, version, diff --git a/plugins/os/src/api-iife.js b/plugins/os/src/api-iife.js index 382e6d15..98ed20a7 100644 --- a/plugins/os/src/api-iife.js +++ b/plugins/os/src/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_OS__=function(n){"use strict";const _=navigator.appVersion.includes("Win")?"\r\n":"\n";return n.EOL=_,n.arch=async function(){return window.__TAURI_INVOKE__("plugin:os|arch")},n.exeExtension=async function(){return window.__TAURI_INVOKE__("plugin:os|exe_extension")},n.family=async function(){return window.__TAURI_INVOKE__("plugin:os|family")},n.hostname=async function(){return window.__TAURI_INVOKE__("plugin:os|hostname")},n.locale=async function(){return window.__TAURI_INVOKE__("plugin:os|locale")},n.platform=async function(){return window.__TAURI_INVOKE__("plugin:os|platform")},n.type=async function(){return window.__TAURI_INVOKE__("plugin:os|os_type")},n.version=async function(){return window.__TAURI_INVOKE__("plugin:os|version")},n}({});Object.defineProperty(window.__TAURI__,"os",{value:__TAURI_OS__})} +if("__TAURI__"in window){var __TAURI_OS__=function(n){"use strict";return n.arch=async function(){return window.__TAURI_INVOKE__("plugin:os|arch")},n.eol=function(){return window.__TAURI__.os.__eol},n.exeExtension=async function(){return window.__TAURI_INVOKE__("plugin:os|exe_extension")},n.family=async function(){return window.__TAURI_INVOKE__("plugin:os|family")},n.hostname=async function(){return window.__TAURI_INVOKE__("plugin:os|hostname")},n.locale=async function(){return window.__TAURI_INVOKE__("plugin:os|locale")},n.platform=async function(){return window.__TAURI_INVOKE__("plugin:os|platform")},n.type=async function(){return window.__TAURI_INVOKE__("plugin:os|os_type")},n.version=async function(){return window.__TAURI_INVOKE__("plugin:os|version")},n}({});Object.defineProperty(window.__TAURI__,"os",{value:__TAURI_OS__})} diff --git a/plugins/os/src/init.js b/plugins/os/src/init.js new file mode 100644 index 00000000..33e42748 --- /dev/null +++ b/plugins/os/src/init.js @@ -0,0 +1,8 @@ +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +__RAW_global_os_api__; + +// eslint-disable-next-line +window.__TAURI__.os.__eol = __TEMPLATE_eol__; diff --git a/plugins/os/src/lib.rs b/plugins/os/src/lib.rs index ccbbdfef..c66580d1 100644 --- a/plugins/os/src/lib.rs +++ b/plugins/os/src/lib.rs @@ -5,6 +5,7 @@ use std::fmt::Display; pub use os_info::Version; +use serialize_to_javascript::{default_template, DefaultTemplate, Template}; use tauri::{ plugin::{Builder, TauriPlugin}, Runtime, @@ -90,9 +91,28 @@ pub fn hostname() -> String { gethostname::gethostname().to_string_lossy().to_string() } +#[derive(Template)] +#[default_template("./init.js")] +struct InitJavascript { + #[raw] + global_os_api: &'static str, + eol: &'static str, +} + pub fn init() -> TauriPlugin { + let init_js = InitJavascript { + global_os_api: include_str!("api-iife.js"), + #[cfg(windows)] + eol: "\r\n", + #[cfg(not(windows))] + eol: "\n", + } + .render_default(&Default::default()) + // this will never fail with the above global_os_api eol values + .unwrap(); + Builder::new("os") - .js_init_script(include_str!("api-iife.js").to_string()) + .js_init_script(init_js.to_string()) .invoke_handler(tauri::generate_handler![ commands::platform, commands::version, From 1cb831183c63ba5bd3f72d8a482992f6467d950d Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sun, 18 Jun 2023 03:36:39 -0700 Subject: [PATCH 5/5] feat(updater): backport changes from tauri v1 (#405) --- .changes/updater-nsis.md | 5 +++++ plugins/updater/src/updater/core.rs | 14 +++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 .changes/updater-nsis.md diff --git a/.changes/updater-nsis.md b/.changes/updater-nsis.md new file mode 100644 index 00000000..adfd7f0d --- /dev/null +++ b/.changes/updater-nsis.md @@ -0,0 +1,5 @@ +--- +"updater": patch +--- + +Implement passive mode on NSIS and automatically restart after NSIS update. diff --git a/plugins/updater/src/updater/core.rs b/plugins/updater/src/updater/core.rs index fd917497..8ebaf842 100644 --- a/plugins/updater/src/updater/core.rs +++ b/plugins/updater/src/updater/core.rs @@ -736,15 +736,11 @@ fn copy_files_and_run( // If it's an `exe` we expect an installer not a runtime. if found_path.extension() == Some(OsStr::new("exe")) { // Run the EXE - let mut installer = Command::new(found_path); - if tauri::utils::config::WindowsUpdateInstallMode::Quiet - == config.tauri.bundle.updater.windows.install_mode - { - installer.arg("/S"); - } - installer.args(&updater_config.installer_args); - - installer.spawn().expect("installer failed to start"); + Command::new(found_path) + .args(config.tauri.bundle.updater.windows.install_mode.nsis_args()) + .args(&updater_config.installer_args) + .spawn() + .expect("installer failed to start"); exit(0); } else if found_path.extension() == Some(OsStr::new("msi")) {