From 3531b1e14d28714886c68d289b0244959d99c412 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 23 May 2023 16:34:46 -0300 Subject: [PATCH 1/4] feat(window): add `setEffects` API Ref https://github.com/tauri-apps/tauri/pull/6442 --- .changes/window-set-effects.md | 6 + Cargo.lock | 21 +-- Cargo.toml | 4 +- examples/api/src-tauri/src/lib.rs | 5 + examples/api/src/views/Window.svelte | 121 +++++++++++++++ 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 + 9 files changed, 342 insertions(+), 19 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 000000000..fba28f99b --- /dev/null +++ b/.changes/window-set-effects.md @@ -0,0 +1,6 @@ +--- +"window": "patch:feat" +"window-js": "patch:feat" +--- + +Added the `setEffects` and `clearEffects` API. diff --git a/Cargo.lock b/Cargo.lock index 23b0f5f51..e9acd17a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4982,8 +4982,7 @@ dependencies = [ [[package]] name = "tauri" version = "2.0.0-alpha.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "695b6c1cdf861002bc2ea17a53cf0669e62da5def6ffcbff02fa00c7515d40b4" +source = "git+https://github.com/tauri-apps/tauri?branch=next#e0f0dce220730e2822fc202463aedf0166145de7" dependencies = [ "anyhow", "bytes 1.4.0", @@ -5033,8 +5032,7 @@ dependencies = [ [[package]] name = "tauri-build" version = "2.0.0-alpha.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34a5b16abedfa53fdb6ad4c68c41612e097dbfac1c18390fe6e4ded18d9ec28d" +source = "git+https://github.com/tauri-apps/tauri?branch=next#e0f0dce220730e2822fc202463aedf0166145de7" dependencies = [ "anyhow", "cargo_toml", @@ -5054,8 +5052,7 @@ dependencies = [ [[package]] name = "tauri-codegen" version = "2.0.0-alpha.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f03863ab7ecf1fea3a748c4a9ace7b0a6a2051b4ce10ae954ec546957fb529" +source = "git+https://github.com/tauri-apps/tauri?branch=next#e0f0dce220730e2822fc202463aedf0166145de7" dependencies = [ "base64 0.21.0", "brotli", @@ -5080,8 +5077,7 @@ dependencies = [ [[package]] name = "tauri-macros" version = "2.0.0-alpha.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f9a2623fed6b5bc04f2e1344c88df6415617bd223599c60a4171630b63fb74" +source = "git+https://github.com/tauri-apps/tauri?branch=next#e0f0dce220730e2822fc202463aedf0166145de7" dependencies = [ "heck 0.4.1", "proc-macro2", @@ -5464,8 +5460,7 @@ dependencies = [ [[package]] name = "tauri-runtime" version = "0.13.0-alpha.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de05147581dd8cfdac638455029eb06c57fa64eb17eb03d5d7f229c571941cd9" +source = "git+https://github.com/tauri-apps/tauri?branch=next#e0f0dce220730e2822fc202463aedf0166145de7" dependencies = [ "gtk", "http", @@ -5485,8 +5480,7 @@ dependencies = [ [[package]] name = "tauri-runtime-wry" version = "0.13.0-alpha.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7784048ef49a57ff32d55bf4ce89ec72fc97e3d4fdc68785d164b23965170e49" +source = "git+https://github.com/tauri-apps/tauri?branch=next#e0f0dce220730e2822fc202463aedf0166145de7" dependencies = [ "cocoa", "gtk", @@ -5506,8 +5500,7 @@ dependencies = [ [[package]] name = "tauri-utils" version = "2.0.0-alpha.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58eca5e3b6714c6bd87052182ebb7d5392d551f478f994878f136f49d4e6d640" +source = "git+https://github.com/tauri-apps/tauri?branch=next#e0f0dce220730e2822fc202463aedf0166145de7" dependencies = [ "aes-gcm 0.10.1", "brotli", diff --git a/Cargo.toml b/Cargo.toml index 7d05f86c6..c70e53f15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,8 @@ resolver = "2" [workspace.dependencies] serde = { version = "1", features = ["derive"] } log = "0.4" -tauri = "2.0.0-alpha.9" -tauri-build = "2.0.0-alpha.5" +tauri = { git = "https://github.com/tauri-apps/tauri", branch = "next" } +tauri-build = { git = "https://github.com/tauri-apps/tauri", branch = "next" } serde_json = "1" thiserror = "1" diff --git a/examples/api/src-tauri/src/lib.rs b/examples/api/src-tauri/src/lib.rs index 41be8760e..356641378 100644 --- a/examples/api/src-tauri/src/lib.rs +++ b/examples/api/src-tauri/src/lib.rs @@ -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 2d4a8c617..87fd7aa3a 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,6 +59,18 @@ "rowResize", ]; + const windowsEffects = ["mica", "blur", "acrylic"]; + const isWindows = navigator.appVersion.includes("Win"); + const isMacOS = navigator.appVersion.includes("Mac"); + 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; let newWindowLabel; @@ -91,6 +105,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 +192,32 @@ 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]; + } + await windowMap[selectedWindow].setEffects(payload); + } + + async function clearEffects() { + effects = []; + await windowMap[selectedWindow].clearEffects(); + } + $: { windowMap[selectedWindow]; loadWindowPosition(); @@ -455,5 +501,80 @@ + +
+ + {#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 2cf7eb8fe..32afca0f9 100644 --- a/plugins/window/guest-js/index.ts +++ b/plugins/window/guest-js/index.ts @@ -900,6 +900,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 @@ -1693,6 +1717,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. * @@ -1884,6 +2076,8 @@ export { LogicalPosition, PhysicalPosition, UserAttentionType, + Effect, + EffectState, currentMonitor, primaryMonitor, availableMonitors, @@ -1896,4 +2090,5 @@ export type { ScaleFactorChanged, FileDropEvent, WindowOptions, + Color, }; diff --git a/plugins/window/src/api-iife.js b/plugins/window/src/api-iife.js index ffa35ae00..23d780464 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 n=Object.defineProperty,i=(e,i)=>{for(var t in i)n(e,t,{get:i[t],enumerable:!0})},t=(e,n,i)=>{if(!n.has(e))throw TypeError("Cannot "+i)},l=(e,n,i)=>(t(e,n,"read from private field"),i?i.call(e):n.get(e)),a=(e,n,i,l)=>(t(e,n,"write to private field"),l?l.call(e,i):n.set(e,i),i);function s(e,n=!1){let i=window.crypto.getRandomValues(new Uint32Array(1))[0],t=`_${i}`;return Object.defineProperty(window,t,{value:i=>(n&&Reflect.deleteProperty(window,t),e?.(i)),writable:!1,configurable:!0}),i}i({},{Channel:()=>o,PluginListener:()=>_,addPluginListener:()=>w,convertFileSrc:()=>c,invoke:()=>u,transformCallback:()=>s});var r,o=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,i)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,i)})(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,n,i){this.plugin=e,this.event=n,this.channelId=i}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function w(e,n,i){let t=new o;return t.onmessage=i,u(`plugin:${e}|register_listener`,{event:n,handler:t}).then((()=>new _(e,n,t.id)))}async function u(e,n={}){return new Promise(((i,t)=>{let l=s((e=>{i(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,...n})}))}function c(e,n="asset"){let i=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${i}`:`${n}://localhost/${i}`}async function d(e,n){await u("plugin:event|unlisten",{event:e,eventId:n})}async function h(e,n,i){return u("plugin:event|listen",{event:e,windowLabel:n,handler:s(i)}).then((n=>async()=>d(e,n)))}i({},{TauriEvent:()=>I,emit:()=>E,listen:()=>b,once:()=>g});var p,y,I=((p=I||{}).WINDOW_RESIZED="tauri://resize",p.WINDOW_MOVED="tauri://move",p.WINDOW_CLOSE_REQUESTED="tauri://close-requested",p.WINDOW_CREATED="tauri://window-created",p.WINDOW_DESTROYED="tauri://destroyed",p.WINDOW_FOCUS="tauri://focus",p.WINDOW_BLUR="tauri://blur",p.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",p.WINDOW_THEME_CHANGED="tauri://theme-changed",p.WINDOW_FILE_DROP="tauri://file-drop",p.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",p.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",p.MENU="tauri://menu",p);async function b(e,n){return h(e,null,n)}async function g(e,n){return async function(e,n,i){return h(e,n,(n=>{i(n),d(e,n.id).catch((()=>{}))}))}(e,null,n)}async function E(e,n){return async function(e,n,i){await u("plugin:event|emit",{event:e,windowLabel:n,payload:i})}(e,void 0,n)}async function A(e,n){await window.__TAURI_INVOKE__("plugin:event|unlisten",{event:e,eventId:n})}async function O(e,n,i){return window.__TAURI_INVOKE__("plugin:event|listen",{event:e,windowLabel:n,handler:window.__TAURI__.transformCallback(i)}).then((n=>async()=>A(e,n)))}class T{constructor(e,n){this.type="Logical",this.width=e,this.height=n}}class R{constructor(e,n){this.type="Physical",this.width=e,this.height=n}toLogical(e){return new T(this.width/e,this.height/e)}}class v{constructor(e,n){this.type="Logical",this.x=e,this.y=n}}class N{constructor(e,n){this.type="Physical",this.x=e,this.y=n}toLogical(e){return new v(this.x/e,this.y/e)}}function m(){return window.__TAURI_METADATA__.__windows.map((e=>new V(e.label,{skip:!0})))}e.UserAttentionType=void 0,(y=e.UserAttentionType||(e.UserAttentionType={}))[y.Critical=1]="Critical",y[y.Informational=2]="Informational";const U=["tauri://created","tauri://error"];class f{constructor(e){this.label=e,this.listeners=Object.create(null)}async listen(e,n){return this._handleTauriEvent(e,n)?Promise.resolve((()=>{const i=this.listeners[e];i.splice(i.indexOf(n),1)})):O(e,this.label,n)}async once(e,n){return this._handleTauriEvent(e,n)?Promise.resolve((()=>{const i=this.listeners[e];i.splice(i.indexOf(n),1)})):async function(e,n,i){return O(e,n,(n=>{i(n),A(e,n.id).catch((()=>{}))}))}(e,this.label,n)}async emit(e,n){if(U.includes(e)){for(const i of this.listeners[e]||[])i({event:e,id:-1,windowLabel:this.label,payload:n});return Promise.resolve()}return async function(e,n,i){await window.__TAURI_INVOKE__("plugin:event|emit",{event:e,windowLabel:n,payload:i})}(e,this.label,n)}_handleTauriEvent(e,n){return!!U.includes(e)&&(e in this.listeners?this.listeners[e].push(n):this.listeners[e]=[n],!0)}}class W 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:n})=>new N(e,n)))}async outerPosition(){return window.__TAURI_INVOKE__("plugin:window|outer_position",{label:this.label}).then((({x:e,y:n})=>new N(e,n)))}async innerSize(){return window.__TAURI_INVOKE__("plugin:window|inner_size",{label:this.label}).then((({width:e,height:n})=>new R(e,n)))}async outerSize(){return window.__TAURI_INVOKE__("plugin:window|outer_size",{label:this.label}).then((({width:e,height:n})=>new R(e,n)))}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(n){let i=null;return n&&(i=n===e.UserAttentionType.Critical?{type:"Critical"}:{type:"Informational"}),window.__TAURI_INVOKE__("plugin:window|request_user_attention",{label:this.label,value:i})}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(I.WINDOW_RESIZED,(n=>{n.payload=C(n.payload),e(n)}))}async onMoved(e){return this.listen(I.WINDOW_MOVED,(n=>{n.payload=P(n.payload),e(n)}))}async onCloseRequested(e){return this.listen(I.WINDOW_CLOSE_REQUESTED,(n=>{const i=new D(n);Promise.resolve(e(i)).then((()=>{if(!i.isPreventDefault())return this.close()}))}))}async onFocusChanged(e){const n=await this.listen(I.WINDOW_FOCUS,(n=>{e({...n,payload:!0})})),i=await this.listen(I.WINDOW_BLUR,(n=>{e({...n,payload:!1})}));return()=>{n(),i()}}async onScaleChanged(e){return this.listen(I.WINDOW_SCALE_FACTOR_CHANGED,e)}async onMenuClicked(e){return this.listen(I.MENU,e)}async onFileDropEvent(e){const n=await this.listen(I.WINDOW_FILE_DROP,(n=>{e({...n,payload:{type:"drop",paths:n.payload}})})),i=await this.listen(I.WINDOW_FILE_DROP_HOVER,(n=>{e({...n,payload:{type:"hover",paths:n.payload}})})),t=await this.listen(I.WINDOW_FILE_DROP_CANCELLED,(n=>{e({...n,payload:{type:"cancel"}})}));return()=>{n(),i(),t()}}async onThemeChanged(e){return this.listen(I.WINDOW_THEME_CHANGED,e)}}class D{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 V extends W{constructor(e,n={}){super(e),(null==n?void 0:n.skip)||window.__TAURI_INVOKE__("plugin:window|create",{options:{...n,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return m().some((n=>n.label===e))?new V(e,{skip:!0}):null}}function K(e){return null===e?null:{name:e.name,scaleFactor:e.scaleFactor,position:P(e.position),size:C(e.size)}}function P(e){return new N(e.x,e.y)}function C(e){return new R(e.width,e.height)}return e.appWindow=void 0,"__TAURI_METADATA__"in window?e.appWindow=new V(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 V("main",{skip:!0})),e.CloseRequestedEvent=D,e.LogicalPosition=v,e.LogicalSize=T,e.PhysicalPosition=N,e.PhysicalSize=R,e.WebviewWindow=V,e.WebviewWindowHandle=f,e.WindowManager=W,e.availableMonitors=async function(){return window.__TAURI_INVOKE__("plugin:window|available_monitors").then((e=>e.map(K)))},e.currentMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|current_monitor").then(K)},e.getAll=m,e.getCurrent=function(){return new V(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0})},e.primaryMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|primary_monitor").then(K)},e}({});Object.defineProperty(window.__TAURI__,"window",{value:__TAURI_WINDOW__})} +if("__TAURI__"in window){var __TAURI_WINDOW__=function(e){"use strict";var n=Object.defineProperty,i=(e,i)=>{for(var t in i)n(e,t,{get:i[t],enumerable:!0})},t=(e,n,i)=>{if(!n.has(e))throw TypeError("Cannot "+i)},a=(e,n,i)=>(t(e,n,"read from private field"),i?i.call(e):n.get(e)),l=(e,n,i,a)=>(t(e,n,"write to private field"),a?a.call(e,i):n.set(e,i),i);function s(e,n=!1){let i=window.crypto.getRandomValues(new Uint32Array(1))[0],t=`_${i}`;return Object.defineProperty(window,t,{value:i=>(n&&Reflect.deleteProperty(window,t),e?.(i)),writable:!1,configurable:!0}),i}i({},{Channel:()=>o,PluginListener:()=>_,addPluginListener:()=>w,convertFileSrc:()=>c,invoke:()=>u,transformCallback:()=>s});var r,o=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,i)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,i)})(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,n,i){this.plugin=e,this.event=n,this.channelId=i}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function w(e,n,i){let t=new o;return t.onmessage=i,u(`plugin:${e}|register_listener`,{event:n,handler:t}).then((()=>new _(e,n,t.id)))}async function u(e,n={}){return new Promise(((i,t)=>{let a=s((e=>{i(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,...n})}))}function c(e,n="asset"){let i=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${i}`:`${n}://localhost/${i}`}async function d(e,n){await u("plugin:event|unlisten",{event:e,eventId:n})}async function h(e,n,i){return u("plugin:event|listen",{event:e,windowLabel:n,handler:s(i)}).then((n=>async()=>d(e,n)))}i({},{TauriEvent:()=>I,emit:()=>E,listen:()=>b,once:()=>g});var p,y,I=((p=I||{}).WINDOW_RESIZED="tauri://resize",p.WINDOW_MOVED="tauri://move",p.WINDOW_CLOSE_REQUESTED="tauri://close-requested",p.WINDOW_CREATED="tauri://window-created",p.WINDOW_DESTROYED="tauri://destroyed",p.WINDOW_FOCUS="tauri://focus",p.WINDOW_BLUR="tauri://blur",p.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",p.WINDOW_THEME_CHANGED="tauri://theme-changed",p.WINDOW_FILE_DROP="tauri://file-drop",p.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",p.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",p.MENU="tauri://menu",p);async function b(e,n){return h(e,null,n)}async function g(e,n){return async function(e,n,i){return h(e,n,(n=>{i(n),d(e,n.id).catch((()=>{}))}))}(e,null,n)}async function E(e,n){return async function(e,n,i){await u("plugin:event|emit",{event:e,windowLabel:n,payload:i})}(e,void 0,n)}async function A(e,n){await window.__TAURI_INVOKE__("plugin:event|unlisten",{event:e,eventId:n})}async function v(e,n,i){return window.__TAURI_INVOKE__("plugin:event|listen",{event:e,windowLabel:n,handler:window.__TAURI__.transformCallback(i)}).then((n=>async()=>A(e,n)))}class O{constructor(e,n){this.type="Logical",this.width=e,this.height=n}}class T{constructor(e,n){this.type="Physical",this.width=e,this.height=n}toLogical(e){return new O(this.width/e,this.height/e)}}class f{constructor(e,n){this.type="Logical",this.x=e,this.y=n}}class R{constructor(e,n){this.type="Physical",this.x=e,this.y=n}toLogical(e){return new f(this.x/e,this.y/e)}}function m(){return window.__TAURI_METADATA__.__windows.map((e=>new V(e.label,{skip:!0})))}e.UserAttentionType=void 0,(y=e.UserAttentionType||(e.UserAttentionType={}))[y.Critical=1]="Critical",y[y.Informational=2]="Informational";const N=["tauri://created","tauri://error"];class U{constructor(e){this.label=e,this.listeners=Object.create(null)}async listen(e,n){return this._handleTauriEvent(e,n)?Promise.resolve((()=>{const i=this.listeners[e];i.splice(i.indexOf(n),1)})):v(e,this.label,n)}async once(e,n){return this._handleTauriEvent(e,n)?Promise.resolve((()=>{const i=this.listeners[e];i.splice(i.indexOf(n),1)})):async function(e,n,i){return v(e,n,(n=>{i(n),A(e,n.id).catch((()=>{}))}))}(e,this.label,n)}async emit(e,n){if(N.includes(e)){for(const i of this.listeners[e]||[])i({event:e,id:-1,windowLabel:this.label,payload:n});return Promise.resolve()}return async function(e,n,i){await window.__TAURI_INVOKE__("plugin:event|emit",{event:e,windowLabel:n,payload:i})}(e,this.label,n)}_handleTauriEvent(e,n){return!!N.includes(e)&&(e in this.listeners?this.listeners[e].push(n):this.listeners[e]=[n],!0)}}class W extends U{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:n})=>new R(e,n)))}async outerPosition(){return window.__TAURI_INVOKE__("plugin:window|outer_position",{label:this.label}).then((({x:e,y:n})=>new R(e,n)))}async innerSize(){return window.__TAURI_INVOKE__("plugin:window|inner_size",{label:this.label}).then((({width:e,height:n})=>new T(e,n)))}async outerSize(){return window.__TAURI_INVOKE__("plugin:window|outer_size",{label:this.label}).then((({width:e,height:n})=>new T(e,n)))}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(n){let i=null;return n&&(i=n===e.UserAttentionType.Critical?{type:"Critical"}:{type:"Informational"}),window.__TAURI_INVOKE__("plugin:window|request_user_attention",{label:this.label,value:i})}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(I.WINDOW_RESIZED,(n=>{n.payload=z(n.payload),e(n)}))}async onMoved(e){return this.listen(I.WINDOW_MOVED,(n=>{n.payload=C(n.payload),e(n)}))}async onCloseRequested(e){return this.listen(I.WINDOW_CLOSE_REQUESTED,(n=>{const i=new D(n);Promise.resolve(e(i)).then((()=>{if(!i.isPreventDefault())return this.close()}))}))}async onFocusChanged(e){const n=await this.listen(I.WINDOW_FOCUS,(n=>{e({...n,payload:!0})})),i=await this.listen(I.WINDOW_BLUR,(n=>{e({...n,payload:!1})}));return()=>{n(),i()}}async onScaleChanged(e){return this.listen(I.WINDOW_SCALE_FACTOR_CHANGED,e)}async onMenuClicked(e){return this.listen(I.MENU,e)}async onFileDropEvent(e){const n=await this.listen(I.WINDOW_FILE_DROP,(n=>{e({...n,payload:{type:"drop",paths:n.payload}})})),i=await this.listen(I.WINDOW_FILE_DROP_HOVER,(n=>{e({...n,payload:{type:"hover",paths:n.payload}})})),t=await this.listen(I.WINDOW_FILE_DROP_CANCELLED,(n=>{e({...n,payload:{type:"cancel"}})}));return()=>{n(),i(),t()}}async onThemeChanged(e){return this.listen(I.WINDOW_THEME_CHANGED,e)}}class D{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 V extends W{constructor(e,n={}){super(e),(null==n?void 0:n.skip)||window.__TAURI_INVOKE__("plugin:window|create",{options:{...n,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return m().some((n=>n.label===e))?new V(e,{skip:!0}):null}}var K,P;function L(e){return null===e?null:{name:e.name,scaleFactor:e.scaleFactor,position:C(e.position),size:z(e.size)}}function C(e){return new R(e.x,e.y)}function z(e){return new T(e.width,e.height)}return e.appWindow=void 0,"__TAURI_METADATA__"in window?e.appWindow=new V(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 V("main",{skip:!0})),e.Effect=void 0,(K=e.Effect||(e.Effect={})).AppearanceBased="appearanceBased",K.Light="light",K.Dark="dark",K.MediumLight="mediumLight",K.UltraDark="ultraDark",K.Titlebar="titlebar",K.Selection="selection",K.Menu="menu",K.Popover="popover",K.Sidebar="sidebar",K.HeaderView="headerView",K.Sheet="sheet",K.WindowBackground="windowBackground",K.HudWindow="hudWindow",K.FullScreenUI="fullScreenUI",K.Tooltip="tooltip",K.ContentBackground="contentBackground",K.UnderWindowBackground="underWindowBackground",K.UnderPageBackground="underPageBackground",K.Mica="mica",K.Blur="blur",K.Acrylic="acrylic",e.EffectState=void 0,(P=e.EffectState||(e.EffectState={})).FollowsWindowActiveState="followsWindowActiveState",P.Active="active",P.Inactive="inactive",e.CloseRequestedEvent=D,e.LogicalPosition=f,e.LogicalSize=O,e.PhysicalPosition=R,e.PhysicalSize=T,e.WebviewWindow=V,e.WebviewWindowHandle=U,e.WindowManager=W,e.availableMonitors=async function(){return window.__TAURI_INVOKE__("plugin:window|available_monitors").then((e=>e.map(L)))},e.currentMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|current_monitor").then(L)},e.getAll=m,e.getCurrent=function(){return new V(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0})},e.primaryMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|primary_monitor").then(L)},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 135e8d804..df2f9c758 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 1efeae152..d4e301512 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 06bc8590f5160b6ac6ab197d430a86b3b8549091 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 23 May 2023 16:39:34 -0300 Subject: [PATCH 2/4] drop new covector syntax --- .changes/window-set-effects.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changes/window-set-effects.md b/.changes/window-set-effects.md index fba28f99b..f2a5d3d99 100644 --- a/.changes/window-set-effects.md +++ b/.changes/window-set-effects.md @@ -1,6 +1,6 @@ --- -"window": "patch:feat" -"window-js": "patch:feat" +"window": "patch" +"window-js": "patch" --- Added the `setEffects` and `clearEffects` API. From 2b633be9ed8c34aa9d5ac9f19a1b101a8b44f8a4 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 23 May 2023 16:57:32 -0300 Subject: [PATCH 3/4] update example [skip ci] --- examples/api/src-tauri/src/lib.rs | 2 +- examples/api/src/views/Window.svelte | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/api/src-tauri/src/lib.rs b/examples/api/src-tauri/src/lib.rs index 356641378..d7f355b36 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.) diff --git a/examples/api/src/views/Window.svelte b/examples/api/src/views/Window.svelte index 87fd7aa3a..352ec7e2f 100644 --- a/examples/api/src/views/Window.svelte +++ b/examples/api/src/views/Window.svelte @@ -60,8 +60,8 @@ ]; const windowsEffects = ["mica", "blur", "acrylic"]; - const isWindows = navigator.appVersion.includes("Win"); - const isMacOS = navigator.appVersion.includes("Mac"); + const isWindows = navigator.appVersion.includes("windows"); + const isMacOS = navigator.appVersion.includes("macos"); let effectOptions = isWindows ? windowsEffects : Object.keys(Effect) @@ -72,6 +72,7 @@ ); export let onMessage; + const mainEl = document.querySelector("main"); let newWindowLabel; @@ -210,12 +211,18 @@ ) { 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"); } $: { From a600ceaa48c15db60f6e6cb3faac36ed22f42c0e Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 23 May 2023 17:07:07 -0300 Subject: [PATCH 4/4] adjust layout [skip ci] --- examples/api/src/views/Window.svelte | 138 ++++++++++++++------------- 1 file changed, 73 insertions(+), 65 deletions(-) diff --git a/examples/api/src/views/Window.svelte b/examples/api/src/views/Window.svelte index 352ec7e2f..c8c1a20b9 100644 --- a/examples/api/src/views/Window.svelte +++ b/examples/api/src/views/Window.svelte @@ -512,75 +512,83 @@
{#if isWindows || isMacOS} -
- - - - - - - +
+
+ + + + + +
- +
+ +
-
- Applied effects: {effects.length ? effects.join(",") : "None"} +
+
- +
+
+ Applied effects: {effects.length ? effects.join(",") : "None"} +
+ + +
{/if} {/if}