Merge branch 'v2' into feat/updater/refactor

pull/431/head
Amr Bashir 2 years ago
commit a78fd79343
No known key found for this signature in database
GPG Key ID: BBD7A47A2003FF33

@ -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.

@ -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`

@ -0,0 +1,5 @@
---
"updater": patch
---
Implement passive mode on NSIS and automatically restart after NSIS update.

@ -0,0 +1,5 @@
---
"window-js": "minor"
---
Add `incognito` window configuration option

@ -0,0 +1,6 @@
---
"window": "minor:feat"
"window-js": "minor:feat"
---
Add `WebviewWindow.is_focused` and `WebviewWindow.getFocusedWindow` getters.

@ -0,0 +1,6 @@
---
"window": "patch"
"window-js": "patch"
---
Added the `setEffects` and `clearEffects` API.

@ -2,4 +2,5 @@ target
node_modules
dist
dist-js
api-iife.js
api-iife.js
init.js

659
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -55,7 +55,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.)
@ -70,6 +70,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)]

@ -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 @@
<button class="btn" id="open-url"> Open URL </button>
</form>
</div>
<br />
{#if isWindows || isMacOS}
<div class="flex flex-col gap-1">
<div class="flex">
<label>
Effect
<select class="input" bind:value={selectedEffect}>
{#each effectOptions as effect}
<option value={effect}>{effect}</option>
{/each}
</select>
</label>
<label>
State
<select class="input" bind:value={effectState}>
{#each effectStateOptions as state}
<option value={state}>{state}</option>
{/each}
</select>
</label>
<label>
Radius
<input class="input" type="number" bind:value={effectRadius} />
</label>
</div>
<div class="flex">
<label>
Color
<div class="flex">
<input
style="max-width: 120px;"
class="input"
type="number"
placeholder="R"
bind:value={effectR}
/>
<input
style="max-width: 120px;"
class="input"
type="number"
placeholder="G"
bind:value={effectG}
/>
<input
style="max-width: 120px;"
class="input"
type="number"
placeholder="B"
bind:value={effectB}
/>
<input
style="max-width: 120px;"
class="input"
type="number"
placeholder="A"
bind:value={effectA}
/>
</div>
</label>
</div>
<div class="flex">
<button class="btn" style="width: 80px;" on:click={addEffect}
>Add</button
>
</div>
<div class="flex">
<div>
Applied effects: {effects.length ? effects.join(",") : "None"}
</div>
<button class="btn" style="width: 80px;" on:click={clearEffects}
>Clear</button
>
</div>
</div>
{/if}
{/if}
</div>

@ -1,4 +1,4 @@
# App
![plugin-app](banner.png)
This plugin provides APIs to read application metadata and macOS app visibility functions.

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

@ -1,4 +1,4 @@
# CLI
![plugin-cli](banner.png)
Parse arguments from your Command Line Interface.

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

@ -1,4 +1,4 @@
# Clipboard Manager
![plugin-clipboard-manager](banner.png)
Read and write to the system clipboard.

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

@ -1,4 +1,4 @@
# Dialog
![plugin-dialog](banner.png)
Native system dialogs for opening and saving files along with message dialogs.

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

@ -1,4 +1,4 @@
# File System
![plugin-fs](banner.png)
Access the file system.

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

@ -1,4 +1,4 @@
# Global Shortcut
![plugin-global-shortcut](banner.png)
Register global shortcuts.

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

@ -1,4 +1,4 @@
# HTTP
![plugin-http](banner.png)
Access the HTTP client written in Rust.

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

@ -1,4 +1,4 @@
# Notification
![plugin-notification](banner.png)
Send message notifications (brief auto-expiring OS window element) to your user. Can also be used with the Notification Web API.

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

@ -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")]
{

@ -15,3 +15,4 @@ thiserror = { workspace = true }
os_info = "3"
sys-locale = "0.3"
gethostname = "0.4"
serialize-to-javascript = "=0.1.1"

@ -1,4 +1,4 @@
# Operating System
![plugin-os](banner.png)
Read information about the operating system.

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

@ -11,6 +11,9 @@
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
__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<string | null> {
}
export {
EOL,
eol,
platform,
family,
version,

@ -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__})}

@ -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__;

@ -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<R: Runtime>() -> TauriPlugin<R> {
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,

@ -1,4 +1,4 @@
# Process
![plugin-process](banner.png)
This plugin provides APIs to access the current process. To spawn child processes, see the [`shell`](https://github.com/tauri-apps/tauri-plugin-shell) plugin.

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

@ -1,4 +1,4 @@
# Shell
![plugin-shell](banner.png)
Access the system shell. Allows you to spawn child processes and manage files and URLs using their default application.

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

@ -1,4 +1,4 @@
# Updater
![plugin-updater](banner.png)
In-app updates for Tauri applications.

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

@ -1,4 +1,4 @@
# Window
![plugin-window](banner.png)
Interact with the Tauri window.

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

@ -563,6 +563,24 @@ class WindowManager extends WebviewWindowHandle {
});
}
/**
* Gets the window's current focus state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/plugin-window';
* const focused = await appWindow.isFocused();
* ```
*
* @returns Whether the window is focused or not.
*
* @since 2.0.0
* */
async isFocused(): Promise<boolean> {
return window.__TAURI_INVOKE__("plugin:window|is_focused", {
label: this.label,
});
}
/**
* Gets the window's current decorated state.
* @example
@ -950,6 +968,30 @@ class WindowManager extends WebviewWindowHandle {
});
}
/**
* Set window effects.
*
* @since 2.0
*/
async setEffects(effects: Effects): Promise<void> {
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<void> {
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
@ -1755,6 +1797,27 @@ class WebviewWindow extends WindowManager {
}
return null;
}
/**
* Gets the focused window.
* @example
* ```typescript
* import { WebviewWindow } from '@tauri-apps/plugin-window';
* const focusedWindow = WebviewWindow.getFocusedWindow();
* ```
*
* @returns The WebviewWindow instance to communicate with the webview or `undefined` if there is not any focused window.
*
* @since 1.4
*/
static async getFocusedWindow(): Promise<WebviewWindow | null> {
for (const w of getAll()) {
if (await w.isFocused()) {
return w;
}
}
return null;
}
}
/** The WebviewWindow for the current window. */
@ -1777,6 +1840,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 +2115,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 {
@ -1968,6 +2207,8 @@ export {
LogicalPosition,
PhysicalPosition,
UserAttentionType,
Effect,
EffectState,
currentMonitor,
primaryMonitor,
availableMonitors,
@ -1980,4 +2221,5 @@ export type {
ScaleFactorChanged,
FileDropEvent,
WindowOptions,
Color,
};

File diff suppressed because one or more lines are too long

@ -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)]
@ -111,6 +112,7 @@ getter!(outer_size, PhysicalSize<u32>);
getter!(is_fullscreen, bool);
getter!(is_minimized, bool);
getter!(is_maximized, bool);
getter!(is_focused, bool);
getter!(is_decorated, bool);
getter!(is_resizable, bool);
getter!(is_visible, bool);
@ -133,6 +135,7 @@ setter!(hide);
setter!(close);
setter!(set_decorations, bool);
setter!(set_shadow, bool);
setter!(set_effects, Option<WindowEffectsConfig>);
setter!(set_always_on_top, bool);
setter!(set_content_protected, bool);
setter!(set_size, Size);

@ -40,6 +40,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
desktop_commands::is_fullscreen,
desktop_commands::is_minimized,
desktop_commands::is_maximized,
desktop_commands::is_focused,
desktop_commands::is_decorated,
desktop_commands::is_resizable,
desktop_commands::is_visible,
@ -62,6 +63,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
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,

Loading…
Cancel
Save