pull/426/head
Lucas Nogueira 2 years ago
parent b9720d634b
commit 23d3205d30
No known key found for this signature in database
GPG Key ID: FFEA6C72E73482F1

@ -1,7 +1,7 @@
<script> <script>
import { writable } from "svelte/store"; import { writable } from "svelte/store";
import { open } from "@tauri-apps/plugin-shell"; import { open } from "@tauri-apps/plugin-shell";
import { appWindow, getCurrent } from "@tauri-apps/plugin-window"; import { getCurrent } from "@tauri-apps/plugin-window";
import * as os from "@tauri-apps/plugin-os"; import * as os from "@tauri-apps/plugin-os";
import Welcome from "./views/Welcome.svelte"; import Welcome from "./views/Welcome.svelte";
@ -22,6 +22,8 @@
import { onMount } from "svelte"; import { onMount } from "svelte";
import { ask } from "@tauri-apps/plugin-dialog"; import { ask } from "@tauri-apps/plugin-dialog";
const appWindow = getCurrent();
if (appWindow.label !== "main") { if (appWindow.label !== "main") {
appWindow.onCloseRequested(async (event) => { appWindow.onCloseRequested(async (event) => {
const confirmed = await confirm("Are you sure?"); const confirmed = await confirm("Are you sure?");
@ -121,20 +123,20 @@
// Window controls // Window controls
let isWindowMaximized; let isWindowMaximized;
onMount(async () => { onMount(async () => {
const window = getCurrent(); isWindowMaximized = await appWindow.isMaximized();
isWindowMaximized = await window.isMaximized();
window.onResized(async () => { window.onResized(async () => {
isWindowMaximized = await window.isMaximized(); isWindowMaximized = await appWindow.isMaximized();
}); });
}); });
function minimize() { function minimize() {
getCurrent().minimize(); appWindow.minimize();
} }
async function toggleMaximize() { async function toggleMaximize() {
const window = getCurrent(); (await appWindow.isMaximized())
(await window.isMaximized()) ? window.unmaximize() : window.maximize(); ? appWindow.unmaximize()
: appWindow.maximize();
} }
let confirmed_close = false; let confirmed_close = false;
@ -147,7 +149,7 @@
} }
); );
if (confirmed_close) { if (confirmed_close) {
getCurrent().close(); appWindow.close();
} }
} }
} }

@ -1,8 +1,10 @@
<script> <script>
import { appWindow } from "@tauri-apps/plugin-window"; import { getCurrent } from "@tauri-apps/plugin-window";
import { invoke } from "@tauri-apps/api/tauri"; import { invoke } from "@tauri-apps/api/tauri";
import { onMount, onDestroy } from "svelte"; import { onMount, onDestroy } from "svelte";
const appWindow = getCurrent();
export let onMessage; export let onMessage;
let unlisten; let unlisten;

@ -1,7 +1,6 @@
<script> <script>
import { import {
appWindow, getCurrent,
WebviewWindow,
LogicalSize, LogicalSize,
UserAttentionType, UserAttentionType,
PhysicalSize, PhysicalSize,
@ -12,6 +11,8 @@
import { open as openDialog } from "@tauri-apps/plugin-dialog"; import { open as openDialog } from "@tauri-apps/plugin-dialog";
import { open } from "@tauri-apps/plugin-shell"; import { open } from "@tauri-apps/plugin-shell";
const appWindow = getCurrent();
let selectedWindow = appWindow.label; let selectedWindow = appWindow.label;
const windowMap = { const windowMap = {
[appWindow.label]: appWindow, [appWindow.label]: appWindow,

@ -60,18 +60,20 @@ fn main() {
Afterwards all the plugin's APIs are available through the JavaScript guest bindings: Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
```javascript ```javascript
import { appWindow, WebviewWindow } from "@tauri-apps/plugin-window"; import { getCurrent, Window } from "@tauri-apps/plugin-window";
const appWindow = getCurrent();
// manipulating this window // manipulating this window
await appWindow.setResizable(false); await appWindow.setResizable(false);
// Creating new windows: // Creating new windows:
// loading embedded asset: // loading embedded asset:
const webview = new WebviewWindow("theUniqueLabel", { const webview = new Window("theUniqueLabel", {
url: "path/to/page.html", url: "path/to/page.html",
}); });
// alternatively, load a remote URL: // alternatively, load a remote URL:
const webview = new WebviewWindow("theUniqueLabel", { const webview = new Window("theUniqueLabel", {
url: "https://github.com/tauri-apps/tauri", url: "https://github.com/tauri-apps/tauri",
}); });
``` ```

@ -335,7 +335,7 @@ class Window {
listeners: Record<string, Array<EventCallback<any>>>; listeners: Record<string, Array<EventCallback<any>>>;
/** /**
* Creates a new WebviewWindow. * Creates a new Window.
* @example * @example
* ```typescript * ```typescript
* import { Window } from '@tauri-apps/plugin-window'; * import { Window } from '@tauri-apps/plugin-window';
@ -374,22 +374,22 @@ class Window {
} }
/** /**
* Gets the WebviewWindow for the webview associated with the given label. * Gets the Window for the webview associated with the given label.
* @example * @example
* ```typescript * ```typescript
* import { WebviewWindow } from '@tauri-apps/plugin-window'; * import { Window } from '@tauri-apps/plugin-window';
* const mainWindow = WebviewWindow.getByLabel('main'); * const mainWindow = Window.getByLabel('main');
* ``` * ```
* *
* @param label The webview window label. * @param label The webview window label.
* @returns The WebviewWindow instance to communicate with the webview or null if the webview doesn't exist. * @returns The Window instance to communicate with the webview or null if the webview doesn't exist.
* *
* @since 2.0.0 * @since 2.0.0
*/ */
static getByLabel(label: string): Window | null { static getByLabel(label: string): Window | null {
if (getAll().some((w) => w.label === label)) { if (getAll().some((w) => w.label === label)) {
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
return new WebviewWindow(label, { skip: true }); return new Window(label, { skip: true });
} }
return null; return null;
} }

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save