Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/fix-invoke-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"shell": patch
"dialog": patch
---

Fix invoke usage.
5 changes: 5 additions & 0 deletions .changes/fix-window-state-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"window-state-js": patch
---

Fix usage of no longer available `__TAURI_METADATA__` API.
7 changes: 1 addition & 6 deletions .github/workflows/test-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,12 @@ jobs:

- uses: Swatinem/rust-cache@v2
with:
key: cache-${{ matrix.package }}
key: cache-${{ matrix.package }}-${{ matrix.platform.target }}

- name: create dummy dist
working-directory: examples/api
run: mkdir dist

- name: Downgrade crates with MSRV conflict
# The --precise flag can only be used once per invocation.
run: |
cargo update -p time@0.3.24 --precise 0.3.23

- name: install cross
if: ${{ matrix.platform.runner == 'cross' }}
run: cargo install cross --git https://github.com/cross-rs/cross
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

window.alert = function (message) {
import { invoke } from "@tauri-apps/api/primitives";

window.alert = function (message: string) {
invoke("plugin:dialog|message", {
message: message.toString(),
});
};

window.confirm = function (message) {
// @ts-expect-error tauri does not have sync IPC :(
window.confirm = function (message: string) {
return invoke("plugin:dialog|confirm", {
message: message.toString(),
});
Expand Down
25 changes: 24 additions & 1 deletion plugins/dialog/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,33 @@ import { readFileSync } from "fs";

import { createConfig } from "../../shared/rollup.config.mjs";

export default createConfig({
import typescript from "@rollup/plugin-typescript";
import resolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";

const config = createConfig({
input: "guest-js/index.ts",
pkg: JSON.parse(
readFileSync(new URL("./package.json", import.meta.url), "utf8"),
),
external: [/^@tauri-apps\/api/],
});

config.push({
input: "guest-js/init.ts",
output: {
file: "src/init-iife.js",
format: "iife",
},
plugins: [
resolve(),
typescript({
sourceMap: false,
declaration: false,
declarationDir: undefined,
}),
terser(),
],
});

export default config;
1 change: 1 addition & 0 deletions plugins/dialog/src/init-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/dialog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
// Dialogs are implemented natively on Android
#[cfg(not(target_os = "android"))]
{
let mut init_script = include_str!("init.js").to_string();
let mut init_script = include_str!("init-iife.js").to_string();
init_script.push_str(include_str!("api-iife.js"));
builder = builder.js_init_script(init_script);
}
Expand Down
40 changes: 40 additions & 0 deletions plugins/shell/guest-js/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

import { invoke } from "@tauri-apps/api/primitives";

// open <a href="..."> links with the API
function openLinks() {
document.querySelector("body")?.addEventListener("click", function (e) {
let target = e.target as HTMLElement;
while (target != null) {
if (target.matches("a")) {
const t = target as HTMLAnchorElement;
if (
t.href &&
["http://", "https://", "mailto:", "tel:"].some((v) =>
t.href.startsWith(v),
) &&
t.target === "_blank"
) {
invoke("plugin:shell|open", {
path: t.href,
});
e.preventDefault();
}
break;
}
target = target.parentElement as HTMLElement;
}
});
}

if (
document.readyState === "complete" ||
document.readyState === "interactive"
) {
openLinks();
} else {
window.addEventListener("DOMContentLoaded", openLinks, true);
}
25 changes: 24 additions & 1 deletion plugins/shell/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,33 @@ import { readFileSync } from "fs";

import { createConfig } from "../../shared/rollup.config.mjs";

export default createConfig({
import typescript from "@rollup/plugin-typescript";
import resolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";

const config = createConfig({
input: "guest-js/index.ts",
pkg: JSON.parse(
readFileSync(new URL("./package.json", import.meta.url), "utf8"),
),
external: [/^@tauri-apps\/api/],
});

config.push({
input: "guest-js/init.ts",
output: {
file: "src/init-iife.js",
format: "iife",
},
plugins: [
resolve(),
typescript({
sourceMap: false,
declaration: false,
declarationDir: undefined,
}),
terser(),
],
});

export default config;
1 change: 1 addition & 0 deletions plugins/shell/src/init-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 0 additions & 39 deletions plugins/shell/src/init.js

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<R: Runtime, T: Manager<R>> ShellExt<R> for T {
}

pub fn init<R: Runtime>() -> TauriPlugin<R, Option<Config>> {
let mut init_script = include_str!("init.js").to_string();
let mut init_script = include_str!("init-iife.js").to_string();
init_script.push_str(include_str!("api-iife.js"));

Builder::<R, Option<Config>>::new("shell")
Expand Down
16 changes: 2 additions & 14 deletions plugins/window-state/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@
// SPDX-License-Identifier: MIT

import { invoke } from "@tauri-apps/api/primitives";

interface WindowDef {
label: string;
}

declare global {
interface Window {
__TAURI_METADATA__: {
__windows: WindowDef[];
__currentWindow: WindowDef;
};
}
}
import { getCurrent } from "@tauri-apps/api/window";

export enum StateFlags {
SIZE = 1 << 0,
Expand Down Expand Up @@ -50,7 +38,7 @@ async function restoreState(label: string, flags: StateFlags): Promise<void> {
* Restore the state for the current window from disk.
*/
async function restoreStateCurrent(flags: StateFlags): Promise<void> {
return restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags);
return restoreState(getCurrent().label, flags);
}

export { restoreState, restoreStateCurrent, saveWindowState };
Loading