Tauri mockWindows

2024-02-02 17:21 更新
mockWindows(: , ...: []): currentstringadditionalWindowsstringvoid

模擬一個或多個窗口標簽。 在非 tauri 上下文中,需要在使用模塊之前調(diào)用此函數(shù)。?@tauri-apps/api/window?

此函數(shù)僅模擬窗口的存在, 窗口屬性(例如寬度和高度)可以像使用該函數(shù)的常規(guī) IPC 調(diào)用一樣進行模擬。?mockIPC?

例子

import { mockWindows } from "@tauri-apps/api/mocks";
import { getCurrent } from "@tauri-apps/api/window";

mockWindows("main", "second", "third");

const win = getCurrent();

win.label // "main"
import { mockWindows } from "@tauri-apps/api/mocks";

mockWindows("main", "second", "third");

mockIPC((cmd, args) => {
if (cmd === "tauri") {
if (
args?.__tauriModule === "Window" &&
args?.message?.cmd === "manage" &&
args?.message?.data?.cmd?.type === "close"
) {
console.log('closing window!');
}
}
});

const { getCurrent } = await import("@tauri-apps/api/window");

const win = getCurrent();
await win.close(); // this will cause the mocked IPC handler to log to the console.

Since: 1.0.0

參數(shù)

名字類型描述
currentstring運行此 JavaScript 上下文的窗口的標簽。
...additionalWindowsstring[]應(yīng)用具有的其他窗口的標簽。

Returns: void


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號