From 0f480d0985b3cdd2a0427340ac0c49324d31a9c2 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sat, 27 May 2023 04:39:54 -0700 Subject: [PATCH 01/12] fix(tests): backport updater test fix from tauri (#404) --- plugins/updater/tests/app-updater/src/main.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/updater/tests/app-updater/src/main.rs b/plugins/updater/tests/app-updater/src/main.rs index b08d8df9..5b5a868a 100644 --- a/plugins/updater/tests/app-updater/src/main.rs +++ b/plugins/updater/tests/app-updater/src/main.rs @@ -34,9 +34,11 @@ fn main() { tauri::async_runtime::spawn(async move { match handle.updater().check().await { Ok(update) => { - if let Err(e) = update.download_and_install(|_event| {}).await { - println!("{e}"); - std::process::exit(1); + if update.is_update_available() { + if let Err(e) = update.download_and_install(|_event| {}).await { + println!("{e}"); + std::process::exit(1); + } } std::process::exit(0); } From cf5864266e2e0fe465af5f01d36214b7de66b528 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sat, 27 May 2023 05:20:09 -0700 Subject: [PATCH 02/12] chore(window): fix package name on documentation (#408) --- plugins/window/guest-js/index.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/window/guest-js/index.ts b/plugins/window/guest-js/index.ts index 4b88f194..f1ae5e0d 100644 --- a/plugins/window/guest-js/index.ts +++ b/plugins/window/guest-js/index.ts @@ -9,7 +9,7 @@ * * Events can be listened to using `appWindow.listen`: * ```typescript - * import { appWindow } from "@tauri-apps/window"; + * import { appWindow } from "@tauri-apps/plugin-window"; * appWindow.listen("my-window-event", ({ event, payload }) => { }); * ``` * @@ -1378,7 +1378,7 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/window"; + * import { appWindow } from "@tauri-apps/plugin-window"; * const unlisten = await appWindow.onResized(({ payload: size }) => { * console.log('Window resized', size); * }); @@ -1404,7 +1404,7 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/window"; + * import { appWindow } from "@tauri-apps/plugin-window"; * const unlisten = await appWindow.onMoved(({ payload: position }) => { * console.log('Window moved', position); * }); @@ -1430,7 +1430,7 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/window"; + * import { appWindow } from "@tauri-apps/plugin-window"; * import { confirm } from '@tauri-apps/api/dialog'; * const unlisten = await appWindow.onCloseRequested(async (event) => { * const confirmed = await confirm('Are you sure?'); @@ -1469,7 +1469,7 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/window"; + * import { appWindow } from "@tauri-apps/plugin-window"; * const unlisten = await appWindow.onFocusChanged(({ payload: focused }) => { * console.log('Focus changed, window is focused? ' + focused); * }); @@ -1511,7 +1511,7 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/window"; + * import { appWindow } from "@tauri-apps/plugin-window"; * const unlisten = await appWindow.onScaleChanged(({ payload }) => { * console.log('Scale changed', payload.scaleFactor, payload.size); * }); @@ -1539,7 +1539,7 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/window"; + * import { appWindow } from "@tauri-apps/plugin-window"; * const unlisten = await appWindow.onMenuClicked(({ payload: menuId }) => { * console.log('Menu clicked: ' + menuId); * }); @@ -1564,7 +1564,7 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/window"; + * import { appWindow } from "@tauri-apps/plugin-window"; * const unlisten = await appWindow.onFileDropEvent((event) => { * if (event.payload.type === 'hover') { * console.log('User hovering', event.payload.paths); @@ -1620,7 +1620,7 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/window"; + * import { appWindow } from "@tauri-apps/plugin-window"; * const unlisten = await appWindow.onThemeChanged(({ payload: theme }) => { * console.log('New theme: ' + theme); * }); From 393667b547c099c1ad68b7e6858454ef55e15560 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Fri, 2 Jun 2023 13:30:44 +0200 Subject: [PATCH 03/12] chore: update pnpm version to 7.33 (#413) * chore: update pnpm version to 7.33 * fmt --- .npmrc | 1 + package.json | 2 +- plugins/upload/README.md | 22 +++++++++++----------- pnpm-lock.yaml | 6 +++++- 4 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..f87a0443 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +auto-install-peers=true \ No newline at end of file diff --git a/package.json b/package.json index 8a842919..f25a88ae 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,6 @@ "typescript": "^5.0.4" }, "engines": { - "pnpm": ">=7.24.2" + "pnpm": ">=7.33.0" } } diff --git a/plugins/upload/README.md b/plugins/upload/README.md index 0f74288d..48fe0153 100644 --- a/plugins/upload/README.md +++ b/plugins/upload/README.md @@ -52,25 +52,25 @@ fn main() { Afterwards all the plugin's APIs are available through the JavaScript guest bindings: ```javascript -import { upload } from 'tauri-plugin-upload-api' +import { upload } from "tauri-plugin-upload-api"; upload( - 'https://example.com/file-upload', - './path/to/my/file.txt', - (progress, total) => console.log(`Uploaded ${progress} of ${total} bytes`), // a callback that will be called with the upload progress - { 'Content-Type': 'text/plain' } // optional headers to send with the request -) + "https://example.com/file-upload", + "./path/to/my/file.txt", + (progress, total) => console.log(`Uploaded ${progress} of ${total} bytes`), // a callback that will be called with the upload progress + { "Content-Type": "text/plain" } // optional headers to send with the request +); ``` ```javascript import { download } from "tauri-plugin-upload-api"; download( - 'https://example.com/file-download-link', - './path/to/save/my/file.txt', - (progress, total) => console.log(`Downloaded ${progress} of ${total} bytes`), // a callback that will be called with the download progress - { 'Content-Type': 'text/plain' } // optional headers to send with the request -) + "https://example.com/file-download-link", + "./path/to/save/my/file.txt", + (progress, total) => console.log(`Downloaded ${progress} of ${total} bytes`), // a callback that will be called with the download progress + { "Content-Type": "text/plain" } // optional headers to send with the request +); ``` ## Contributing diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 18a1cda0..69468078 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,8 @@ -lockfileVersion: '6.0' +lockfileVersion: '6.1' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false importers: From 29bf8a2ab45ad0f16c467d2a1bcb7a26424cc634 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 2 Jun 2023 13:48:49 +0200 Subject: [PATCH 04/12] chore(deps): update dependency eslint-config-standard-with-typescript to v35 (#412) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- pnpm-lock.yaml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index f25a88ae..8872a988 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@typescript-eslint/parser": "^5.58.0", "eslint": "^8.38.0", "eslint-config-prettier": "^8.8.0", - "eslint-config-standard-with-typescript": "^34.0.1", + "eslint-config-standard-with-typescript": "^35.0.0", "eslint-plugin-import": "^2.27.5", "eslint-plugin-n": "^16.0.0", "eslint-plugin-promise": "^6.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 69468078..c5ee8389 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^8.8.0 version: 8.8.0(eslint@8.38.0) eslint-config-standard-with-typescript: - specifier: ^34.0.1 - version: 34.0.1(@typescript-eslint/eslint-plugin@5.58.0)(eslint-plugin-import@2.27.5)(eslint-plugin-n@16.0.0)(eslint-plugin-promise@6.1.1)(eslint@8.38.0)(typescript@5.0.4) + specifier: ^35.0.0 + version: 35.0.0(@typescript-eslint/eslint-plugin@5.58.0)(eslint-plugin-import@2.27.5)(eslint-plugin-n@16.0.0)(eslint-plugin-promise@6.1.1)(eslint@8.38.0)(typescript@5.0.4) eslint-plugin-import: specifier: ^2.27.5 version: 2.27.5(@typescript-eslint/parser@5.58.0)(eslint@8.38.0) @@ -1311,10 +1311,10 @@ packages: eslint: 8.38.0 dev: true - /eslint-config-standard-with-typescript@34.0.1(@typescript-eslint/eslint-plugin@5.58.0)(eslint-plugin-import@2.27.5)(eslint-plugin-n@16.0.0)(eslint-plugin-promise@6.1.1)(eslint@8.38.0)(typescript@5.0.4): - resolution: {integrity: sha512-J7WvZeLtd0Vr9F+v4dZbqJCLD16cbIy4U+alJMq4MiXdpipdBM3U5NkXaGUjePc4sb1ZE01U9g6VuTBpHHz1fg==} + /eslint-config-standard-with-typescript@35.0.0(@typescript-eslint/eslint-plugin@5.58.0)(eslint-plugin-import@2.27.5)(eslint-plugin-n@16.0.0)(eslint-plugin-promise@6.1.1)(eslint@8.38.0)(typescript@5.0.4): + resolution: {integrity: sha512-Xa7DY9GgduZyp0qmXxBF0/dB+Vm4/DgWu1lGpNLJV2d46aCaUxTKDEnkzjUWX/1O9S0a+Dhnw7A4oI0JpYzwtw==} peerDependencies: - '@typescript-eslint/eslint-plugin': ^5.43.0 + '@typescript-eslint/eslint-plugin': ^5.50.0 eslint: ^8.0.1 eslint-plugin-import: ^2.25.2 eslint-plugin-n: ^15.0.0 From d8b4aca69f628b170804ecb982e2c319d026ef47 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Sun, 4 Jun 2023 13:36:49 +0200 Subject: [PATCH 05/12] fix(notification): Fix init.js script for use without global tauri object. (#414) --- .changes/notification-init-script.md | 5 +++++ plugins/notification/src/init.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changes/notification-init-script.md diff --git a/.changes/notification-init-script.md b/.changes/notification-init-script.md new file mode 100644 index 00000000..fce58ba4 --- /dev/null +++ b/.changes/notification-init-script.md @@ -0,0 +1,5 @@ +--- +"notification": patch +--- + +Use `window.__TAURI_INVOKE__` instead of `window.__TAURI__` in init.js, fixes usage in apps without `withGlobalTauri` enabled. diff --git a/plugins/notification/src/init.js b/plugins/notification/src/init.js index 53de9586..1fbf3c52 100644 --- a/plugins/notification/src/init.js +++ b/plugins/notification/src/init.js @@ -10,7 +10,7 @@ if (window.Notification.permission !== "default") { return Promise.resolve(window.Notification.permission === "granted"); } - return window.__TAURI__.invoke("plugin:notification|is_permission_granted"); + return window.__TAURI_INVOKE__("plugin:notification|is_permission_granted"); } function setNotificationPermission(value) { @@ -34,7 +34,7 @@ Object.freeze(options); } - return window.__TAURI__.invoke("plugin:notification|notify", { + return window.__TAURI_INVOKE__("plugin:notification|notify", { options: typeof options === "string" ? { From b3d7d11ae32e0970184f53be26e2c5530f78cdf0 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 6 Jun 2023 04:50:05 -0700 Subject: [PATCH 06/12] fix(stronghold): remove constructor, add static load function (#416) --- .changes/stronghold-constructor.md | 5 +++++ plugins/stronghold/guest-js/index.ts | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 .changes/stronghold-constructor.md diff --git a/.changes/stronghold-constructor.md b/.changes/stronghold-constructor.md new file mode 100644 index 00000000..99966095 --- /dev/null +++ b/.changes/stronghold-constructor.md @@ -0,0 +1,5 @@ +--- +"stronghold-js": minor +--- + +Added `Stronghold.load` and removed its constructor. diff --git a/plugins/stronghold/guest-js/index.ts b/plugins/stronghold/guest-js/index.ts index 3339f87f..071eabf1 100644 --- a/plugins/stronghold/guest-js/index.ts +++ b/plugins/stronghold/guest-js/index.ts @@ -395,21 +395,20 @@ export class Stronghold { * @param path * @param password */ - constructor(path: string, password: string) { + private constructor(path: string) { this.path = path; - void this.reload(password); } /** - * Force a reload of the snapshot. The password must match. + * Load the snapshot if it exists (password must match), or start a fresh stronghold instance otherwise. * @param password * @returns */ - private async reload(password: string): Promise { + static async load(path: string, password: string): Promise { return await invoke("plugin:stronghold|initialize", { - snapshotPath: this.path, + snapshotPath: path, password, - }); + }).then(() => new Stronghold(path)); } /** From 91ffc01a91bc5ba7f264c496586fd35755b344db Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 6 Jun 2023 09:31:55 -0300 Subject: [PATCH 07/12] Publish New Versions (v2) (#402) Co-authored-by: lucasfernog --- .changes/pre.json | 7 ++++++- examples/api/src-tauri/CHANGELOG.md | 6 ++++++ examples/api/src-tauri/Cargo.toml | 2 +- plugins/notification/CHANGELOG.md | 5 +++++ plugins/notification/Cargo.toml | 2 +- plugins/stronghold/CHANGELOG.md | 4 ++++ plugins/stronghold/package.json | 2 +- 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.changes/pre.json b/.changes/pre.json index 94ca7d1f..a95db7bb 100644 --- a/.changes/pre.json +++ b/.changes/pre.json @@ -1,4 +1,9 @@ { "tag": "alpha", - "changes": [".changes/persisted-scope-fix-oom.md", ".changes/v2-alpha.md"] + "changes": [ + ".changes/notification-init-script.md", + ".changes/notification-sound.md", + ".changes/stronghold-constructor.md", + ".changes/v2-alpha.md" + ] } diff --git a/examples/api/src-tauri/CHANGELOG.md b/examples/api/src-tauri/CHANGELOG.md index 4da28c4f..22d9cf7a 100644 --- a/examples/api/src-tauri/CHANGELOG.md +++ b/examples/api/src-tauri/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## \[2.0.0-alpha.1] + +### Dependencies + +- Updated to latest `notification` + ## \[2.0.0-alpha.0] ### Dependencies diff --git a/examples/api/src-tauri/Cargo.toml b/examples/api/src-tauri/Cargo.toml index 06428b8e..2431dc2f 100644 --- a/examples/api/src-tauri/Cargo.toml +++ b/examples/api/src-tauri/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "api" publish = false -version = "2.0.0-alpha.0" +version = "2.0.0-alpha.1" description = "An example Tauri Application showcasing the api" edition = "2021" rust-version = "1.65" diff --git a/plugins/notification/CHANGELOG.md b/plugins/notification/CHANGELOG.md index a70b10ec..263a20f0 100644 --- a/plugins/notification/CHANGELOG.md +++ b/plugins/notification/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## \[2.0.0-alpha.1] + +- [`d8b4aca`](https://github.com/tauri-apps/plugins-workspace/commit/d8b4aca69f628b170804ecb982e2c319d026ef47)([#414](https://github.com/tauri-apps/plugins-workspace/pull/414)) Use `window.__TAURI_INVOKE__` instead of `window.__TAURI__` in init.js, fixes usage in apps without `withGlobalTauri` enabled. +- [`7d71ad4`](https://github.com/tauri-apps/plugins-workspace/commit/7d71ad4e587bcf47ea34645f5b226945e487b765) Play a default sound when showing a notification on Windows. + ## \[2.0.0-alpha.0] - [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release! diff --git a/plugins/notification/Cargo.toml b/plugins/notification/Cargo.toml index a89a731f..fddbde5c 100644 --- a/plugins/notification/Cargo.toml +++ b/plugins/notification/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tauri-plugin-notification" -version = "2.0.0-alpha.0" +version = "2.0.0-alpha.1" description = "Send desktop and mobile notifications on your Tauri application." edition = { workspace = true } authors = { workspace = true } diff --git a/plugins/stronghold/CHANGELOG.md b/plugins/stronghold/CHANGELOG.md index a70b10ec..ae13dabe 100644 --- a/plugins/stronghold/CHANGELOG.md +++ b/plugins/stronghold/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## \[2.0.0-alpha.1] + +- [`b3d7d11`](https://github.com/tauri-apps/plugins-workspace/commit/b3d7d11ae32e0970184f53be26e2c5530f78cdf0)([#416](https://github.com/tauri-apps/plugins-workspace/pull/416)) Added `Stronghold.load` and removed its constructor. + ## \[2.0.0-alpha.0] - [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release! diff --git a/plugins/stronghold/package.json b/plugins/stronghold/package.json index e4c7fc2d..fcb1364e 100644 --- a/plugins/stronghold/package.json +++ b/plugins/stronghold/package.json @@ -1,6 +1,6 @@ { "name": "@tauri-apps/plugin-stronghold", - "version": "2.0.0-alpha.0", + "version": "2.0.0-alpha.1", "description": "Store secrets and keys using the IOTA Stronghold encrypted database.", "license": "MIT or APACHE-2.0", "authors": [ From 1091d6d6ac5081f2c7526b0f492ae4f34b306f1d Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 7 Jun 2023 14:13:31 +0300 Subject: [PATCH 08/12] feat(os): refactor and improvemnts (#419) --- .changes/os-plugin-refactor.md | 11 ++++ Cargo.lock | 17 +++++- plugins/os/Cargo.toml | 1 + plugins/os/guest-js/index.ts | 87 ++++++++++++++++++++-------- plugins/os/src/api-iife.js | 2 +- plugins/os/src/commands.rs | 20 +++++-- plugins/os/src/lib.rs | 73 ++++++++++++++--------- plugins/stronghold/guest-js/index.ts | 10 ++-- 8 files changed, 156 insertions(+), 65 deletions(-) create mode 100644 .changes/os-plugin-refactor.md diff --git a/.changes/os-plugin-refactor.md b/.changes/os-plugin-refactor.md new file mode 100644 index 00000000..63cd5bdd --- /dev/null +++ b/.changes/os-plugin-refactor.md @@ -0,0 +1,11 @@ +--- +"os": minor +"os-js": minor +--- + +The os plugin is recieving a few changes to improve consistency and add new features: + +- Renamed `Kind` enum to `OsType` and `kind()` function to `os_type()`. +- 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` diff --git a/Cargo.lock b/Cargo.lock index 5fe18839..5fb1c522 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -206,7 +206,7 @@ checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" [[package]] name = "api" -version = "2.0.0-alpha.0" +version = "2.0.0-alpha.1" dependencies = [ "log", "serde", @@ -1854,6 +1854,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "gethostname" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0176e0459c2e4a1fe232f984bca6890e681076abb9934f6cea7c326f3fc47818" +dependencies = [ + "libc", + "windows-targets 0.48.0", +] + [[package]] name = "getrandom" version = "0.1.16" @@ -5263,7 +5273,7 @@ dependencies = [ [[package]] name = "tauri-plugin-notification" -version = "2.0.0-alpha.0" +version = "2.0.0-alpha.1" dependencies = [ "log", "notify-rust", @@ -5283,6 +5293,7 @@ dependencies = [ name = "tauri-plugin-os" version = "2.0.0-alpha.0" dependencies = [ + "gethostname 0.4.3", "log", "os_info", "serde", @@ -6886,7 +6897,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" dependencies = [ - "gethostname", + "gethostname 0.2.3", "nix 0.24.3", "winapi", "winapi-wsapoll", diff --git a/plugins/os/Cargo.toml b/plugins/os/Cargo.toml index 2890d540..ef2f8a6d 100644 --- a/plugins/os/Cargo.toml +++ b/plugins/os/Cargo.toml @@ -14,3 +14,4 @@ log = { workspace = true } thiserror = { workspace = true } os_info = "3" sys-locale = "0.3" +gethostname = "0.4" diff --git a/plugins/os/guest-js/index.ts b/plugins/os/guest-js/index.ts index 2b4806b2..2b94895d 100644 --- a/plugins/os/guest-js/index.ts +++ b/plugins/os/guest-js/index.ts @@ -16,7 +16,7 @@ declare global { type Platform = | "linux" - | "darwin" + | "macos" | "ios" | "freebsd" | "dragonfly" @@ -24,9 +24,9 @@ type Platform = | "openbsd" | "solaris" | "android" - | "win32"; + | "windows"; -type OsType = "Linux" | "Darwin" | "Windows_NT"; +type OsType = "linux" | "windows" | "macss" | "ios" | "android"; type Arch = | "x86" @@ -55,8 +55,9 @@ function isWindows(): boolean { const EOL = isWindows() ? "\r\n" : "\n"; /** - * Returns a string identifying the operating system platform. - * The value is set at compile time. Possible values are `'linux'`, `'darwin'`, `'ios'`, `'freebsd'`, `'dragonfly'`, `'netbsd'`, `'openbsd'`, `'solaris'`, `'android'`, `'win32'` + * Returns a string describing the specific operating system in use. + * The value is set at compile time. Possible values are `'linux'`, `'macos'`, `'ios'`, `'freebsd'`, `'dragonfly'`, `'netbsd'`, `'openbsd'`, `'solaris'`, `'android'`, `'windows'` + * * @example * ```typescript * import { platform } from '@tauri-apps/plugin-os'; @@ -71,7 +72,7 @@ async function platform(): Promise { } /** - * Returns a string identifying the kernel version. + * Returns the current operating system version. * @example * ```typescript * import { version } from '@tauri-apps/plugin-os'; @@ -84,47 +85,49 @@ async function version(): Promise { return window.__TAURI_INVOKE__("plugin:os|version"); } +type Family = "unix" | "windows"; + /** - * Returns `'Linux'` on Linux, `'Darwin'` on macOS, and `'Windows_NT'` on Windows. + * Returns the current operating system family. Possible values are `'unix'`, `'windows'`. * @example * ```typescript - * import { type } from '@tauri-apps/plugin-os'; - * const osType = await type(); + * import { family } from '@tauri-apps/plugin-os'; + * const family = await family(); * ``` * * @since 2.0.0 */ -async function type(): Promise { - return window.__TAURI_INVOKE__("plugin:os|kind"); +async function family(): Promise { + return window.__TAURI_INVOKE__("plugin:os|family"); } /** - * Returns the operating system CPU architecture for which the tauri app was compiled. - * Possible values are `'x86'`, `'x86_64'`, `'arm'`, `'aarch64'`, `'mips'`, `'mips64'`, `'powerpc'`, `'powerpc64'`, `'riscv64'`, `'s390x'`, `'sparc64'`. + * Returns the current operating system type. Returns `'linux'` on Linux, `'macos'` on macOS, `'windows'` on Windows, `'ios'` on iOS and `'android'` on Android. * @example * ```typescript - * import { arch } from '@tauri-apps/plugin-os'; - * const archName = await arch(); + * import { type } from '@tauri-apps/plugin-os'; + * const osType = await type(); * ``` * * @since 2.0.0 */ -async function arch(): Promise { - return window.__TAURI_INVOKE__("plugin:os|arch"); +async function type(): Promise { + return window.__TAURI_INVOKE__("plugin:os|os_type"); } /** - * Returns the operating system's default directory for temporary files as a string. + * Returns the current operating system architecture. + * Possible values are `'x86'`, `'x86_64'`, `'arm'`, `'aarch64'`, `'mips'`, `'mips64'`, `'powerpc'`, `'powerpc64'`, `'riscv64'`, `'s390x'`, `'sparc64'`. * @example * ```typescript - * import { tempdir } from '@tauri-apps/plugin-os'; - * const tempdirPath = await tempdir(); + * import { arch } from '@tauri-apps/plugin-os'; + * const archName = await arch(); * ``` * * @since 2.0.0 */ -async function tempdir(): Promise { - return window.__TAURI_INVOKE__("plugin:os|tempdir"); +async function arch(): Promise { + return window.__TAURI_INVOKE__("plugin:os|arch"); } /** @@ -144,5 +147,41 @@ async function locale(): Promise { return window.__TAURI_INVOKE__("plugin:os|locale"); } -export { EOL, platform, version, type, arch, tempdir, locale }; -export type { Platform, OsType, Arch }; +/** + * Returns the file extension, if any, used for executable binaries on this platform. Possible values are `'exe'` and `''` (empty string). + * @example + * ```typescript + * import { exeExtension } from '@tauri-apps/plugin-os'; + * const exeExt = await exeExtension(); + * ``` + * + * @since 2.0.0 + */ +async function exeExtension(): Promise { + return window.__TAURI_INVOKE__("plugin:os|exe_extension"); +} + +/** + * Returns the host name of the operating system. + * @example + * ```typescript + * import { hostname } from '@tauri-apps/api/os'; + * const hostname = await hostname(); + * ``` + */ +async function hostname(): Promise { + return window.__TAURI_INVOKE__("plugin:os|hostname"); +} + +export { + EOL, + platform, + family, + version, + type, + arch, + locale, + exeExtension, + hostname, +}; +export type { Platform, OsType, Arch, Family }; diff --git a/plugins/os/src/api-iife.js b/plugins/os/src/api-iife.js index 3e754051..382e6d15 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.locale=async function(){return window.__TAURI_INVOKE__("plugin:os|locale")},n.platform=async function(){return window.__TAURI_INVOKE__("plugin:os|platform")},n.tempdir=async function(){return window.__TAURI_INVOKE__("plugin:os|tempdir")},n.type=async function(){return window.__TAURI_INVOKE__("plugin:os|kind")},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";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__})} diff --git a/plugins/os/src/commands.rs b/plugins/os/src/commands.rs index 668fa82a..fdfa09a0 100644 --- a/plugins/os/src/commands.rs +++ b/plugins/os/src/commands.rs @@ -2,8 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -use std::path::PathBuf; - #[tauri::command] pub fn platform() -> &'static str { crate::platform() @@ -15,8 +13,13 @@ pub fn version() -> String { } #[tauri::command] -pub fn kind() -> String { - crate::kind().to_string() +pub fn os_type() -> String { + crate::type_().to_string() +} + +#[tauri::command] +pub fn family() -> &'static str { + crate::family() } #[tauri::command] @@ -25,11 +28,16 @@ pub fn arch() -> &'static str { } #[tauri::command] -pub fn tempdir() -> PathBuf { - crate::tempdir() +pub fn exe_extension() -> &'static str { + crate::exe_extension() } #[tauri::command] pub fn locale() -> Option { crate::locale() } + +#[tauri::command] +pub fn hostname() -> String { + crate::hostname() +} diff --git a/plugins/os/src/lib.rs b/plugins/os/src/lib.rs index 4060c679..ccbbdfef 100644 --- a/plugins/os/src/lib.rs +++ b/plugins/os/src/lib.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -use std::{fmt::Display, path::PathBuf}; +use std::fmt::Display; pub use os_info::Version; use tauri::{ @@ -15,74 +15,93 @@ mod error; pub use error::Error; -pub enum Kind { +pub enum OsType { Linux, Windows, - Darwin, + Macos, IOS, Android, } -impl Display for Kind { +impl Display for OsType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Linux => write!(f, "Linux"), - Self::Windows => write!(f, "Linux_NT"), - Self::Darwin => write!(f, "Darwin"), - Self::IOS => write!(f, "iOS"), - Self::Android => write!(f, "Android"), + Self::Linux => write!(f, "linux"), + Self::Windows => write!(f, "windows"), + Self::Macos => write!(f, "macos"), + Self::IOS => write!(f, "ios"), + Self::Android => write!(f, "android"), } } } +/// Returns a string describing the specific operating system in use, see [std::env::consts::OS]. pub fn platform() -> &'static str { - match std::env::consts::OS { - "windows" => "win32", - "macos" => "darwin", - _ => std::env::consts::OS, - } + std::env::consts::OS } +/// Returns the current operating system version. pub fn version() -> Version { os_info::get().version().clone() } -pub fn kind() -> Kind { - #[cfg(target_os = "linux")] - return Kind::Linux; +/// Returns the current operating system type. +pub fn type_() -> OsType { + #[cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ))] + return OsType::Linux; #[cfg(target_os = "windows")] - return Kind::Windows; + return OsType::Windows; #[cfg(target_os = "macos")] - return Kind::Darwin; + return OsType::Macos; #[cfg(target_os = "ios")] - return Kind::IOS; + return OsType::IOS; #[cfg(target_os = "android")] - return Kind::Android; + return OsType::Android; +} + +/// Returns the current operating system family, see [std::env::consts::FAMILY]. +pub fn family() -> &'static str { + std::env::consts::FAMILY } +/// Returns the current operating system architecture, see [std::env::consts::ARCH]. pub fn arch() -> &'static str { std::env::consts::ARCH } -pub fn tempdir() -> PathBuf { - std::env::temp_dir() +/// Returns the file extension, if any, used for executable binaries on this platform. Example value is `exe`, see [std::env::consts::EXE_EXTENSION]. +pub fn exe_extension() -> &'static str { + std::env::consts::EXE_EXTENSION } -/// Returns the locale with the `BCP-47` language tag. If the locale couldn’t be obtained, `None` is returned instead. +/// Returns the current operating system locale with the `BCP-47` language tag. If the locale couldn’t be obtained, `None` is returned instead. pub fn locale() -> Option { sys_locale::get_locale() } +/// Returns the current operating system hostname. +pub fn hostname() -> String { + gethostname::gethostname().to_string_lossy().to_string() +} + pub fn init() -> TauriPlugin { Builder::new("os") .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![ commands::platform, commands::version, - commands::kind, + commands::os_type, + commands::family, commands::arch, - commands::tempdir, - commands::locale + commands::exe_extension, + commands::locale, + commands::hostname ]) .build() } diff --git a/plugins/stronghold/guest-js/index.ts b/plugins/stronghold/guest-js/index.ts index 933543dc..1b28f4f1 100644 --- a/plugins/stronghold/guest-js/index.ts +++ b/plugins/stronghold/guest-js/index.ts @@ -436,10 +436,12 @@ export class Stronghold { * @returns */ static async load(path: string, password: string): Promise { - return await window.__TAURI_INVOKE__("plugin:stronghold|initialize", { - snapshotPath: path, - password, - }).then(() => new Stronghold(path)); + return await window + .__TAURI_INVOKE__("plugin:stronghold|initialize", { + snapshotPath: path, + password, + }) + .then(() => new Stronghold(path)); } /** From c73049d3edf267aed147735a5d9789ef53866baf Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Fri, 9 Jun 2023 03:17:53 +0300 Subject: [PATCH 09/12] fix: remove tsconfig symlink (#429) * fix: remove tsconfig symlink * one more tsconfig --- plugins/authenticator/tsconfig.json | 5 ++++- plugins/autostart/tsconfig.json | 5 ++++- plugins/fs/tsconfig.json | 5 ++++- plugins/log/tsconfig.json | 5 ++++- plugins/positioner/tsconfig.json | 5 ++++- plugins/sql/tsconfig.json | 5 ++++- plugins/store/tsconfig.json | 5 ++++- plugins/stronghold/tsconfig.json | 5 ++++- plugins/upload/guest-js/index.ts | 1 - plugins/upload/src/api-iife.js | 2 +- plugins/upload/tsconfig.json | 5 ++++- plugins/websocket/tsconfig.json | 5 ++++- plugins/window-state/tsconfig.json | 5 ++++- shared/template/tsconfig.json | 5 ++++- 14 files changed, 49 insertions(+), 14 deletions(-) diff --git a/plugins/authenticator/tsconfig.json b/plugins/authenticator/tsconfig.json index 7cd38da8..5098169a 120000 --- a/plugins/authenticator/tsconfig.json +++ b/plugins/authenticator/tsconfig.json @@ -1 +1,4 @@ -../../shared/tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/autostart/tsconfig.json b/plugins/autostart/tsconfig.json index 7cd38da8..5098169a 120000 --- a/plugins/autostart/tsconfig.json +++ b/plugins/autostart/tsconfig.json @@ -1 +1,4 @@ -../../shared/tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/fs/tsconfig.json b/plugins/fs/tsconfig.json index 7cd38da8..5098169a 120000 --- a/plugins/fs/tsconfig.json +++ b/plugins/fs/tsconfig.json @@ -1 +1,4 @@ -../../shared/tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/log/tsconfig.json b/plugins/log/tsconfig.json index 7cd38da8..5098169a 120000 --- a/plugins/log/tsconfig.json +++ b/plugins/log/tsconfig.json @@ -1 +1,4 @@ -../../shared/tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/positioner/tsconfig.json b/plugins/positioner/tsconfig.json index 7cd38da8..5098169a 120000 --- a/plugins/positioner/tsconfig.json +++ b/plugins/positioner/tsconfig.json @@ -1 +1,4 @@ -../../shared/tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/sql/tsconfig.json b/plugins/sql/tsconfig.json index 7cd38da8..5098169a 120000 --- a/plugins/sql/tsconfig.json +++ b/plugins/sql/tsconfig.json @@ -1 +1,4 @@ -../../shared/tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/store/tsconfig.json b/plugins/store/tsconfig.json index 7cd38da8..5098169a 120000 --- a/plugins/store/tsconfig.json +++ b/plugins/store/tsconfig.json @@ -1 +1,4 @@ -../../shared/tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/stronghold/tsconfig.json b/plugins/stronghold/tsconfig.json index 7cd38da8..5098169a 120000 --- a/plugins/stronghold/tsconfig.json +++ b/plugins/stronghold/tsconfig.json @@ -1 +1,4 @@ -../../shared/tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/upload/guest-js/index.ts b/plugins/upload/guest-js/index.ts index d220af04..29c25a98 100644 --- a/plugins/upload/guest-js/index.ts +++ b/plugins/upload/guest-js/index.ts @@ -63,5 +63,4 @@ async function download( }); } -export default upload; export { download, upload }; diff --git a/plugins/upload/src/api-iife.js b/plugins/upload/src/api-iife.js index b42588ae..210ee0d9 100644 --- a/plugins/upload/src/api-iife.js +++ b/plugins/upload/src/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_UPLOAD__=function(e){"use strict";var n=Object.defineProperty,t=(e,n,t)=>{if(!n.has(e))throw TypeError("Cannot "+t)},r=(e,n,r)=>(t(e,n,"read from private field"),r?r.call(e):n.get(e)),o=(e,n,r,o)=>(t(e,n,"write to private field"),o?o.call(e,r):n.set(e,r),r);function a(e,n=!1){let t=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${t}`;return Object.defineProperty(window,r,{value:t=>(n&&Reflect.deleteProperty(window,r),e?.(t)),writable:!1,configurable:!0}),t}((e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})})({},{Channel:()=>l,PluginListener:()=>s,addPluginListener:()=>d,convertFileSrc:()=>u,invoke:()=>c,transformCallback:()=>a});var i,l=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,t)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,t)})(this,i,(()=>{})),this.id=a((e=>{r(this,i).call(this,e)}))}set onmessage(e){o(this,i,e)}get onmessage(){return r(this,i)}toJSON(){return`__CHANNEL__:${this.id}`}};i=new WeakMap;var s=class{constructor(e,n,t){this.plugin=e,this.event=n,this.channelId=t}async unregister(){return c(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function d(e,n,t){let r=new l;return r.onmessage=t,c(`plugin:${e}|register_listener`,{event:n,handler:r}).then((()=>new s(e,n,r.id)))}async function c(e,n={}){return new Promise(((t,r)=>{let o=a((e=>{t(e),Reflect.deleteProperty(window,`_${i}`)}),!0),i=a((e=>{r(e),Reflect.deleteProperty(window,`_${o}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:o,error:i,...n})}))}function u(e,n="asset"){let t=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${t}`:`${n}://localhost/${t}`}async function _(e,n,t,r){const o=new Uint32Array(1);window.crypto.getRandomValues(o);const a=o[0],i=new l;null!=t&&(i.onmessage=t),await c("plugin:upload|upload",{id:a,url:e,filePath:n,headers:null!=r?r:{},onProgress:i})}return e.default=_,e.download=async function(e,n,t,r){const o=new Uint32Array(1);window.crypto.getRandomValues(o);const a=o[0],i=new l;null!=t&&(i.onmessage=t),await c("plugin:upload|download",{id:a,url:e,filePath:n,headers:null!=r?r:{},onProgress:i})},e.upload=_,Object.defineProperty(e,"__esModule",{value:!0}),e}({});Object.defineProperty(window.__TAURI__,"upload",{value:__TAURI_UPLOAD__})} +if("__TAURI__"in window){var __TAURI_UPLOAD__=function(e){"use strict";var n=Object.defineProperty,t=(e,n,t)=>{if(!n.has(e))throw TypeError("Cannot "+t)},r=(e,n,r)=>(t(e,n,"read from private field"),r?r.call(e):n.get(e)),o=(e,n,r,o)=>(t(e,n,"write to private field"),o?o.call(e,r):n.set(e,r),r);function a(e,n=!1){let t=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${t}`;return Object.defineProperty(window,r,{value:t=>(n&&Reflect.deleteProperty(window,r),e?.(t)),writable:!1,configurable:!0}),t}((e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})})({},{Channel:()=>s,PluginListener:()=>l,addPluginListener:()=>d,convertFileSrc:()=>u,invoke:()=>c,transformCallback:()=>a});var i,s=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,t)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,t)})(this,i,(()=>{})),this.id=a((e=>{r(this,i).call(this,e)}))}set onmessage(e){o(this,i,e)}get onmessage(){return r(this,i)}toJSON(){return`__CHANNEL__:${this.id}`}};i=new WeakMap;var l=class{constructor(e,n,t){this.plugin=e,this.event=n,this.channelId=t}async unregister(){return c(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function d(e,n,t){let r=new s;return r.onmessage=t,c(`plugin:${e}|register_listener`,{event:n,handler:r}).then((()=>new l(e,n,r.id)))}async function c(e,n={}){return new Promise(((t,r)=>{let o=a((e=>{t(e),Reflect.deleteProperty(window,`_${i}`)}),!0),i=a((e=>{r(e),Reflect.deleteProperty(window,`_${o}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:o,error:i,...n})}))}function u(e,n="asset"){let t=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${t}`:`${n}://localhost/${t}`}return e.download=async function(e,n,t,r){const o=new Uint32Array(1);window.crypto.getRandomValues(o);const a=o[0],i=new s;null!=t&&(i.onmessage=t),await c("plugin:upload|download",{id:a,url:e,filePath:n,headers:null!=r?r:{},onProgress:i})},e.upload=async function(e,n,t,r){const o=new Uint32Array(1);window.crypto.getRandomValues(o);const a=o[0],i=new s;null!=t&&(i.onmessage=t),await c("plugin:upload|upload",{id:a,url:e,filePath:n,headers:null!=r?r:{},onProgress:i})},e}({});Object.defineProperty(window.__TAURI__,"upload",{value:__TAURI_UPLOAD__})} diff --git a/plugins/upload/tsconfig.json b/plugins/upload/tsconfig.json index 7cd38da8..5098169a 120000 --- a/plugins/upload/tsconfig.json +++ b/plugins/upload/tsconfig.json @@ -1 +1,4 @@ -../../shared/tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/websocket/tsconfig.json b/plugins/websocket/tsconfig.json index 7cd38da8..5098169a 120000 --- a/plugins/websocket/tsconfig.json +++ b/plugins/websocket/tsconfig.json @@ -1 +1,4 @@ -../../shared/tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/window-state/tsconfig.json b/plugins/window-state/tsconfig.json index 7cd38da8..5098169a 120000 --- a/plugins/window-state/tsconfig.json +++ b/plugins/window-state/tsconfig.json @@ -1 +1,4 @@ -../../shared/tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/shared/template/tsconfig.json b/shared/template/tsconfig.json index 4ec6ff6a..5098169a 120000 --- a/shared/template/tsconfig.json +++ b/shared/template/tsconfig.json @@ -1 +1,4 @@ -../tsconfig.json \ No newline at end of file +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} From 84b3612393e3d0d4faeebe1e61cb7d7973556503 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Tue, 13 Jun 2023 23:30:39 +0300 Subject: [PATCH 10/12] fix(window-state): port fixes from v1 (#436) * fix(window-state): correctly set decoration state if no saved state exists, fixes #421 (#424) * fix(window-state): propagate promise (#435) closes #432 * fix(window-state): manual default implentation (#425) * fix(window-state): manual default implentation, closes #421 * Update lib.rs * change file * generated files * fix symlinks? --------- Co-authored-by: Fabian-Lars --- .changes/window-state-decorated.md | 5 +++++ .changes/window-state-promise.md | 5 +++++ plugins/authenticator/tsconfig.json | 0 plugins/autostart/tsconfig.json | 0 plugins/fs/tsconfig.json | 0 plugins/log/tsconfig.json | 0 plugins/positioner/tsconfig.json | 0 plugins/sql/tsconfig.json | 0 plugins/store/tsconfig.json | 0 plugins/stronghold/tsconfig.json | 0 plugins/upload/tsconfig.json | 0 plugins/websocket/tsconfig.json | 0 plugins/window-state/guest-js/index.ts | 14 ++++++++------ plugins/window-state/src/api-iife.js | 2 +- plugins/window-state/src/lib.rs | 19 +++++++++++++++++-- plugins/window-state/tsconfig.json | 0 16 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 .changes/window-state-decorated.md create mode 100644 .changes/window-state-promise.md mode change 120000 => 100644 plugins/authenticator/tsconfig.json mode change 120000 => 100644 plugins/autostart/tsconfig.json mode change 120000 => 100644 plugins/fs/tsconfig.json mode change 120000 => 100644 plugins/log/tsconfig.json mode change 120000 => 100644 plugins/positioner/tsconfig.json mode change 120000 => 100644 plugins/sql/tsconfig.json mode change 120000 => 100644 plugins/store/tsconfig.json mode change 120000 => 100644 plugins/stronghold/tsconfig.json mode change 120000 => 100644 plugins/upload/tsconfig.json mode change 120000 => 100644 plugins/websocket/tsconfig.json mode change 120000 => 100644 plugins/window-state/tsconfig.json diff --git a/.changes/window-state-decorated.md b/.changes/window-state-decorated.md new file mode 100644 index 00000000..191ec5c2 --- /dev/null +++ b/.changes/window-state-decorated.md @@ -0,0 +1,5 @@ +--- +"window-state": "patch" +--- + +Correctly set decoration state if no saved state xists diff --git a/.changes/window-state-promise.md b/.changes/window-state-promise.md new file mode 100644 index 00000000..f97c43df --- /dev/null +++ b/.changes/window-state-promise.md @@ -0,0 +1,5 @@ +--- +"window-state-js": "patch" +--- + +Correctly propagate the promise inside `saveWindowState`, `restoreState` and `restoreStateCurrent` so callers can choose to `await` them. diff --git a/plugins/authenticator/tsconfig.json b/plugins/authenticator/tsconfig.json deleted file mode 120000 index 5098169a..00000000 --- a/plugins/authenticator/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/authenticator/tsconfig.json b/plugins/authenticator/tsconfig.json new file mode 100644 index 00000000..5098169a --- /dev/null +++ b/plugins/authenticator/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/autostart/tsconfig.json b/plugins/autostart/tsconfig.json deleted file mode 120000 index 5098169a..00000000 --- a/plugins/autostart/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/autostart/tsconfig.json b/plugins/autostart/tsconfig.json new file mode 100644 index 00000000..5098169a --- /dev/null +++ b/plugins/autostart/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/fs/tsconfig.json b/plugins/fs/tsconfig.json deleted file mode 120000 index 5098169a..00000000 --- a/plugins/fs/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/fs/tsconfig.json b/plugins/fs/tsconfig.json new file mode 100644 index 00000000..5098169a --- /dev/null +++ b/plugins/fs/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/log/tsconfig.json b/plugins/log/tsconfig.json deleted file mode 120000 index 5098169a..00000000 --- a/plugins/log/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/log/tsconfig.json b/plugins/log/tsconfig.json new file mode 100644 index 00000000..5098169a --- /dev/null +++ b/plugins/log/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/positioner/tsconfig.json b/plugins/positioner/tsconfig.json deleted file mode 120000 index 5098169a..00000000 --- a/plugins/positioner/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/positioner/tsconfig.json b/plugins/positioner/tsconfig.json new file mode 100644 index 00000000..5098169a --- /dev/null +++ b/plugins/positioner/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/sql/tsconfig.json b/plugins/sql/tsconfig.json deleted file mode 120000 index 5098169a..00000000 --- a/plugins/sql/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/sql/tsconfig.json b/plugins/sql/tsconfig.json new file mode 100644 index 00000000..5098169a --- /dev/null +++ b/plugins/sql/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/store/tsconfig.json b/plugins/store/tsconfig.json deleted file mode 120000 index 5098169a..00000000 --- a/plugins/store/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/store/tsconfig.json b/plugins/store/tsconfig.json new file mode 100644 index 00000000..5098169a --- /dev/null +++ b/plugins/store/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/stronghold/tsconfig.json b/plugins/stronghold/tsconfig.json deleted file mode 120000 index 5098169a..00000000 --- a/plugins/stronghold/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/stronghold/tsconfig.json b/plugins/stronghold/tsconfig.json new file mode 100644 index 00000000..5098169a --- /dev/null +++ b/plugins/stronghold/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/upload/tsconfig.json b/plugins/upload/tsconfig.json deleted file mode 120000 index 5098169a..00000000 --- a/plugins/upload/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/upload/tsconfig.json b/plugins/upload/tsconfig.json new file mode 100644 index 00000000..5098169a --- /dev/null +++ b/plugins/upload/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/websocket/tsconfig.json b/plugins/websocket/tsconfig.json deleted file mode 120000 index 5098169a..00000000 --- a/plugins/websocket/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/websocket/tsconfig.json b/plugins/websocket/tsconfig.json new file mode 100644 index 00000000..5098169a --- /dev/null +++ b/plugins/websocket/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/window-state/guest-js/index.ts b/plugins/window-state/guest-js/index.ts index 706e3cbf..31d88f9a 100644 --- a/plugins/window-state/guest-js/index.ts +++ b/plugins/window-state/guest-js/index.ts @@ -34,15 +34,17 @@ export enum StateFlags { /** * Save the state of all open windows to disk. */ -async function saveWindowState(flags: StateFlags) { - window.__TAURI_INVOKE__("plugin:window-state|save_window_state", { flags }); +async function saveWindowState(flags: StateFlags): Promise { + return window.__TAURI_INVOKE__("plugin:window-state|save_window_state", { + flags, + }); } /** * Restore the state for the specified window from disk. */ -async function restoreState(label: string, flags: StateFlags) { - window.__TAURI_INVOKE__("plugin:window-state|restore_state", { +async function restoreState(label: string, flags: StateFlags): Promise { + return window.__TAURI_INVOKE__("plugin:window-state|restore_state", { label, flags, }); @@ -51,8 +53,8 @@ async function restoreState(label: string, flags: StateFlags) { /** * Restore the state for the current window from disk. */ -async function restoreStateCurrent(flags: StateFlags) { - restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags); +async function restoreStateCurrent(flags: StateFlags): Promise { + return restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags); } export { restoreState, restoreStateCurrent, saveWindowState }; diff --git a/plugins/window-state/src/api-iife.js b/plugins/window-state/src/api-iife.js index 86c310f8..3ded95ac 100644 --- a/plugins/window-state/src/api-iife.js +++ b/plugins/window-state/src/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_WINDOWSTATE__=function(_){"use strict";var t;async function e(_,t){window.__TAURI_INVOKE__("plugin:window-state|restore_state",{label:_,flags:t})}return _.StateFlags=void 0,(t=_.StateFlags||(_.StateFlags={}))[t.SIZE=1]="SIZE",t[t.POSITION=2]="POSITION",t[t.MAXIMIZED=4]="MAXIMIZED",t[t.VISIBLE=8]="VISIBLE",t[t.DECORATIONS=16]="DECORATIONS",t[t.FULLSCREEN=32]="FULLSCREEN",t[t.ALL=63]="ALL",_.restoreState=e,_.restoreStateCurrent=async function(_){e(window.__TAURI_METADATA__.__currentWindow.label,_)},_.saveWindowState=async function(_){window.__TAURI_INVOKE__("plugin:window-state|save_window_state",{flags:_})},_}({});Object.defineProperty(window.__TAURI__,"windowState",{value:__TAURI_WINDOWSTATE__})} +if("__TAURI__"in window){var __TAURI_WINDOWSTATE__=function(t){"use strict";var _;async function e(t,_){return window.__TAURI_INVOKE__("plugin:window-state|restore_state",{label:t,flags:_})}return t.StateFlags=void 0,(_=t.StateFlags||(t.StateFlags={}))[_.SIZE=1]="SIZE",_[_.POSITION=2]="POSITION",_[_.MAXIMIZED=4]="MAXIMIZED",_[_.VISIBLE=8]="VISIBLE",_[_.DECORATIONS=16]="DECORATIONS",_[_.FULLSCREEN=32]="FULLSCREEN",_[_.ALL=63]="ALL",t.restoreState=e,t.restoreStateCurrent=async function(t){return e(window.__TAURI_METADATA__.__currentWindow.label,t)},t.saveWindowState=async function(t){return window.__TAURI_INVOKE__("plugin:window-state|save_window_state",{flags:t})},t}({});Object.defineProperty(window.__TAURI__,"windowState",{value:__TAURI_WINDOWSTATE__})} diff --git a/plugins/window-state/src/lib.rs b/plugins/window-state/src/lib.rs index 28e00b35..fa88be3b 100644 --- a/plugins/window-state/src/lib.rs +++ b/plugins/window-state/src/lib.rs @@ -55,7 +55,7 @@ impl Default for StateFlags { } } -#[derive(Debug, Default, Deserialize, Serialize, PartialEq)] +#[derive(Debug, Deserialize, Serialize, PartialEq)] struct WindowState { width: f64, height: f64, @@ -67,6 +67,21 @@ struct WindowState { fullscreen: bool, } +impl Default for WindowState { + fn default() -> Self { + Self { + width: Default::default(), + height: Default::default(), + x: Default::default(), + y: Default::default(), + maximized: Default::default(), + visible: true, + decorated: true, + fullscreen: Default::default(), + } + } +} + struct WindowStateCache(Arc>>); pub trait AppHandleExt { /// Saves all open windows state to disk @@ -177,7 +192,7 @@ impl WindowExt for Window { } if flags.contains(StateFlags::DECORATIONS) { - metadata.visible = self.is_visible()?; + metadata.decorated = self.is_decorated()?; } if flags.contains(StateFlags::FULLSCREEN) { diff --git a/plugins/window-state/tsconfig.json b/plugins/window-state/tsconfig.json deleted file mode 120000 index 5098169a..00000000 --- a/plugins/window-state/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/window-state/tsconfig.json b/plugins/window-state/tsconfig.json new file mode 100644 index 00000000..5098169a --- /dev/null +++ b/plugins/window-state/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} From 9359b5b138a2aa03ff824474849ddb2c8df3f685 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Fri, 16 Jun 2023 08:05:55 -0700 Subject: [PATCH 11/12] fix(examples): adjust layout for iOS (#439) --- examples/api/index.html | 5 ++++- examples/api/src/App.svelte | 2 +- examples/api/src/app.css | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/examples/api/index.html b/examples/api/index.html index 3b39b0f6..81b6f92e 100644 --- a/examples/api/index.html +++ b/examples/api/index.html @@ -2,7 +2,10 @@ - + Svelte + Vite App diff --git a/examples/api/src/App.svelte b/examples/api/src/App.svelte index 1b3c9b71..dd0df993 100644 --- a/examples/api/src/App.svelte +++ b/examples/api/src/App.svelte @@ -354,7 +354,7 @@