mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
feat(window): add plugin (#352)
This commit is contained in:
committed by
GitHub
parent
a95fb473a2
commit
bb26f7d710
@@ -22,7 +22,8 @@
|
||||
"tauri-plugin-os-api": "0.0.0",
|
||||
"tauri-plugin-process-api": "0.0.0",
|
||||
"tauri-plugin-shell-api": "0.0.0",
|
||||
"tauri-plugin-updater-api": "0.0.0"
|
||||
"tauri-plugin-updater-api": "0.0.0",
|
||||
"tauri-plugin-window-api": "0.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@iconify-json/codicon": "^1.1.10",
|
||||
|
||||
Generated
+17
-7
@@ -180,6 +180,7 @@ dependencies = [
|
||||
"tauri-plugin-process",
|
||||
"tauri-plugin-shell",
|
||||
"tauri-plugin-updater",
|
||||
"tauri-plugin-window",
|
||||
"tiny_http",
|
||||
"window-shadows",
|
||||
]
|
||||
@@ -3603,7 +3604,7 @@ checksum = "fd1ba337640d60c3e96bc6f0638a939b9c9a7f2c316a1598c279828b3d1dc8c5"
|
||||
[[package]]
|
||||
name = "tauri"
|
||||
version = "2.0.0-alpha.8"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#0ab5f40d3a4207f20e4440587b41c4e78f91d233"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
@@ -3659,7 +3660,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-build"
|
||||
version = "2.0.0-alpha.4"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#0ab5f40d3a4207f20e4440587b41c4e78f91d233"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cargo_toml",
|
||||
@@ -3680,7 +3681,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-codegen"
|
||||
version = "2.0.0-alpha.4"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#0ab5f40d3a4207f20e4440587b41c4e78f91d233"
|
||||
dependencies = [
|
||||
"base64 0.21.0",
|
||||
"brotli",
|
||||
@@ -3705,7 +3706,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-macros"
|
||||
version = "2.0.0-alpha.4"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#0ab5f40d3a4207f20e4440587b41c4e78f91d233"
|
||||
dependencies = [
|
||||
"heck 0.4.1",
|
||||
"proc-macro2",
|
||||
@@ -3894,10 +3895,19 @@ dependencies = [
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-window"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"tauri",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime"
|
||||
version = "0.13.0-alpha.4"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#0ab5f40d3a4207f20e4440587b41c4e78f91d233"
|
||||
dependencies = [
|
||||
"gtk",
|
||||
"http",
|
||||
@@ -3918,7 +3928,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-runtime-wry"
|
||||
version = "0.13.0-alpha.4"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#0ab5f40d3a4207f20e4440587b41c4e78f91d233"
|
||||
dependencies = [
|
||||
"cocoa",
|
||||
"gtk",
|
||||
@@ -3938,7 +3948,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-utils"
|
||||
version = "2.0.0-alpha.4"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#0ab5f40d3a4207f20e4440587b41c4e78f91d233"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"brotli",
|
||||
|
||||
@@ -28,6 +28,7 @@ tauri-plugin-os = { path = "../../../plugins/os" }
|
||||
tauri-plugin-process = { path = "../../../plugins/process" }
|
||||
tauri-plugin-shell = { path = "../../../plugins/shell" }
|
||||
tauri-plugin-updater = { path = "../../../plugins/updater" }
|
||||
tauri-plugin-window = { path = "../../../plugins/window" }
|
||||
|
||||
[patch.crates-io]
|
||||
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "next" }
|
||||
|
||||
@@ -41,6 +41,7 @@ pub fn run() {
|
||||
.plugin(tauri_plugin_process::init())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.plugin(tauri_plugin_window::init())
|
||||
.setup(move |app| {
|
||||
#[cfg(desktop)]
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import { writable } from "svelte/store";
|
||||
import { open } from "tauri-plugin-shell-api";
|
||||
import { appWindow, getCurrent } from "@tauri-apps/api/window";
|
||||
import { appWindow, getCurrent } from "tauri-plugin-window-api";
|
||||
import * as os from "tauri-plugin-os-api";
|
||||
|
||||
import Welcome from "./views/Welcome.svelte";
|
||||
@@ -20,7 +20,6 @@
|
||||
import App from "./views/App.svelte";
|
||||
|
||||
import { onMount } from "svelte";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { ask } from "tauri-plugin-dialog-api";
|
||||
|
||||
if (appWindow.label !== "main") {
|
||||
@@ -124,7 +123,7 @@
|
||||
onMount(async () => {
|
||||
const window = getCurrent();
|
||||
isWindowMaximized = await window.isMaximized();
|
||||
listen("tauri://resize", async () => {
|
||||
window.onResized(async () => {
|
||||
isWindowMaximized = await window.isMaximized();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
<script>
|
||||
import { listen, emit } from '@tauri-apps/api/event'
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
import { onMount, onDestroy } from 'svelte'
|
||||
import { appWindow } from "tauri-plugin-window-api";
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
import { onMount, onDestroy } from "svelte";
|
||||
|
||||
export let onMessage
|
||||
let unlisten
|
||||
export let onMessage;
|
||||
let unlisten;
|
||||
|
||||
onMount(async () => {
|
||||
unlisten = await listen('rust-event', onMessage)
|
||||
})
|
||||
unlisten = await appWindow.listen("rust-event", onMessage);
|
||||
});
|
||||
onDestroy(() => {
|
||||
if (unlisten) {
|
||||
unlisten()
|
||||
unlisten();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
function log() {
|
||||
invoke('log_operation', {
|
||||
event: 'tauri-click',
|
||||
payload: 'this payload is optional because we used Option in Rust'
|
||||
})
|
||||
invoke("log_operation", {
|
||||
event: "tauri-click",
|
||||
payload: "this payload is optional because we used Option in Rust",
|
||||
});
|
||||
}
|
||||
|
||||
function performRequest() {
|
||||
invoke('perform_request', {
|
||||
endpoint: 'dummy endpoint arg',
|
||||
invoke("perform_request", {
|
||||
endpoint: "dummy endpoint arg",
|
||||
body: {
|
||||
id: 5,
|
||||
name: 'test'
|
||||
}
|
||||
name: "test",
|
||||
},
|
||||
})
|
||||
.then(onMessage)
|
||||
.catch(onMessage)
|
||||
.catch(onMessage);
|
||||
}
|
||||
|
||||
function emitEvent() {
|
||||
emit('js-event', 'this is the payload string')
|
||||
appWindow.emit("js-event", "this is the payload string");
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -5,217 +5,217 @@
|
||||
LogicalSize,
|
||||
UserAttentionType,
|
||||
PhysicalSize,
|
||||
PhysicalPosition
|
||||
} from '@tauri-apps/api/window'
|
||||
import { open as openDialog } from 'tauri-plugin-dialog-api'
|
||||
import { open } from 'tauri-plugin-shell-api'
|
||||
PhysicalPosition,
|
||||
} from "tauri-plugin-window-api";
|
||||
import { open as openDialog } from "tauri-plugin-dialog-api";
|
||||
import { open } from "tauri-plugin-shell-api";
|
||||
|
||||
let selectedWindow = appWindow.label
|
||||
let selectedWindow = appWindow.label;
|
||||
const windowMap = {
|
||||
[appWindow.label]: appWindow
|
||||
}
|
||||
[appWindow.label]: appWindow,
|
||||
};
|
||||
|
||||
const cursorIconOptions = [
|
||||
'default',
|
||||
'crosshair',
|
||||
'hand',
|
||||
'arrow',
|
||||
'move',
|
||||
'text',
|
||||
'wait',
|
||||
'help',
|
||||
'progress',
|
||||
"default",
|
||||
"crosshair",
|
||||
"hand",
|
||||
"arrow",
|
||||
"move",
|
||||
"text",
|
||||
"wait",
|
||||
"help",
|
||||
"progress",
|
||||
// something cannot be done
|
||||
'notAllowed',
|
||||
'contextMenu',
|
||||
'cell',
|
||||
'verticalText',
|
||||
'alias',
|
||||
'copy',
|
||||
'noDrop',
|
||||
"notAllowed",
|
||||
"contextMenu",
|
||||
"cell",
|
||||
"verticalText",
|
||||
"alias",
|
||||
"copy",
|
||||
"noDrop",
|
||||
// something can be grabbed
|
||||
'grab',
|
||||
"grab",
|
||||
/// something is grabbed
|
||||
'grabbing',
|
||||
'allScroll',
|
||||
'zoomIn',
|
||||
'zoomOut',
|
||||
"grabbing",
|
||||
"allScroll",
|
||||
"zoomIn",
|
||||
"zoomOut",
|
||||
// edge is to be moved
|
||||
'eResize',
|
||||
'nResize',
|
||||
'neResize',
|
||||
'nwResize',
|
||||
'sResize',
|
||||
'seResize',
|
||||
'swResize',
|
||||
'wResize',
|
||||
'ewResize',
|
||||
'nsResize',
|
||||
'neswResize',
|
||||
'nwseResize',
|
||||
'colResize',
|
||||
'rowResize'
|
||||
]
|
||||
"eResize",
|
||||
"nResize",
|
||||
"neResize",
|
||||
"nwResize",
|
||||
"sResize",
|
||||
"seResize",
|
||||
"swResize",
|
||||
"wResize",
|
||||
"ewResize",
|
||||
"nsResize",
|
||||
"neswResize",
|
||||
"nwseResize",
|
||||
"colResize",
|
||||
"rowResize",
|
||||
];
|
||||
|
||||
export let onMessage
|
||||
export let onMessage;
|
||||
|
||||
let newWindowLabel
|
||||
let newWindowLabel;
|
||||
|
||||
let urlValue = 'https://tauri.app'
|
||||
let resizable = true
|
||||
let maximized = false
|
||||
let decorations = true
|
||||
let alwaysOnTop = false
|
||||
let contentProtected = true
|
||||
let fullscreen = false
|
||||
let width = null
|
||||
let height = null
|
||||
let minWidth = null
|
||||
let minHeight = null
|
||||
let maxWidth = null
|
||||
let maxHeight = null
|
||||
let x = null
|
||||
let y = null
|
||||
let scaleFactor = 1
|
||||
let innerPosition = new PhysicalPosition(x, y)
|
||||
let outerPosition = new PhysicalPosition(x, y)
|
||||
let innerSize = new PhysicalSize(width, height)
|
||||
let outerSize = new PhysicalSize(width, height)
|
||||
let resizeEventUnlisten
|
||||
let moveEventUnlisten
|
||||
let cursorGrab = false
|
||||
let cursorVisible = true
|
||||
let cursorX = null
|
||||
let cursorY = null
|
||||
let cursorIcon = 'default'
|
||||
let cursorIgnoreEvents = false
|
||||
let windowTitle = 'Awesome Tauri Example!'
|
||||
let urlValue = "https://tauri.app";
|
||||
let resizable = true;
|
||||
let maximized = false;
|
||||
let decorations = true;
|
||||
let alwaysOnTop = false;
|
||||
let contentProtected = true;
|
||||
let fullscreen = false;
|
||||
let width = null;
|
||||
let height = null;
|
||||
let minWidth = null;
|
||||
let minHeight = null;
|
||||
let maxWidth = null;
|
||||
let maxHeight = null;
|
||||
let x = null;
|
||||
let y = null;
|
||||
let scaleFactor = 1;
|
||||
let innerPosition = new PhysicalPosition(x, y);
|
||||
let outerPosition = new PhysicalPosition(x, y);
|
||||
let innerSize = new PhysicalSize(width, height);
|
||||
let outerSize = new PhysicalSize(width, height);
|
||||
let resizeEventUnlisten;
|
||||
let moveEventUnlisten;
|
||||
let cursorGrab = false;
|
||||
let cursorVisible = true;
|
||||
let cursorX = null;
|
||||
let cursorY = null;
|
||||
let cursorIcon = "default";
|
||||
let cursorIgnoreEvents = false;
|
||||
let windowTitle = "Awesome Tauri Example!";
|
||||
|
||||
function openUrl() {
|
||||
open(urlValue)
|
||||
open(urlValue);
|
||||
}
|
||||
|
||||
function setTitle_() {
|
||||
windowMap[selectedWindow].setTitle(windowTitle)
|
||||
windowMap[selectedWindow].setTitle(windowTitle);
|
||||
}
|
||||
|
||||
function hide_() {
|
||||
windowMap[selectedWindow].hide()
|
||||
setTimeout(windowMap[selectedWindow].show, 2000)
|
||||
windowMap[selectedWindow].hide();
|
||||
setTimeout(windowMap[selectedWindow].show, 2000);
|
||||
}
|
||||
|
||||
function minimize_() {
|
||||
windowMap[selectedWindow].minimize()
|
||||
setTimeout(windowMap[selectedWindow].unminimize, 2000)
|
||||
windowMap[selectedWindow].minimize();
|
||||
setTimeout(windowMap[selectedWindow].unminimize, 2000);
|
||||
}
|
||||
|
||||
function getIcon() {
|
||||
openDialog({
|
||||
multiple: false
|
||||
multiple: false,
|
||||
}).then((path) => {
|
||||
if (typeof path === 'string') {
|
||||
windowMap[selectedWindow].setIcon(path)
|
||||
if (typeof path === "string") {
|
||||
windowMap[selectedWindow].setIcon(path);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
if (!newWindowLabel) return
|
||||
if (!newWindowLabel) return;
|
||||
|
||||
const webview = new WebviewWindow(newWindowLabel)
|
||||
windowMap[newWindowLabel] = webview
|
||||
webview.once('tauri://error', function () {
|
||||
onMessage('Error creating new webview')
|
||||
})
|
||||
const webview = new WebviewWindow(newWindowLabel);
|
||||
windowMap[newWindowLabel] = webview;
|
||||
webview.once("tauri://error", function () {
|
||||
onMessage("Error creating new webview");
|
||||
});
|
||||
}
|
||||
|
||||
function loadWindowSize() {
|
||||
windowMap[selectedWindow].innerSize().then((response) => {
|
||||
innerSize = response
|
||||
width = innerSize.width
|
||||
height = innerSize.height
|
||||
})
|
||||
innerSize = response;
|
||||
width = innerSize.width;
|
||||
height = innerSize.height;
|
||||
});
|
||||
windowMap[selectedWindow].outerSize().then((response) => {
|
||||
outerSize = response
|
||||
})
|
||||
outerSize = response;
|
||||
});
|
||||
}
|
||||
|
||||
function loadWindowPosition() {
|
||||
windowMap[selectedWindow].innerPosition().then((response) => {
|
||||
innerPosition = response
|
||||
})
|
||||
innerPosition = response;
|
||||
});
|
||||
windowMap[selectedWindow].outerPosition().then((response) => {
|
||||
outerPosition = response
|
||||
x = outerPosition.x
|
||||
y = outerPosition.y
|
||||
})
|
||||
outerPosition = response;
|
||||
x = outerPosition.x;
|
||||
y = outerPosition.y;
|
||||
});
|
||||
}
|
||||
|
||||
async function addWindowEventListeners(window) {
|
||||
if (!window) return
|
||||
if (!window) return;
|
||||
if (resizeEventUnlisten) {
|
||||
resizeEventUnlisten()
|
||||
resizeEventUnlisten();
|
||||
}
|
||||
if (moveEventUnlisten) {
|
||||
moveEventUnlisten()
|
||||
moveEventUnlisten();
|
||||
}
|
||||
moveEventUnlisten = await window.listen('tauri://move', loadWindowPosition)
|
||||
resizeEventUnlisten = await window.listen('tauri://resize', loadWindowSize)
|
||||
moveEventUnlisten = await window.listen("tauri://move", loadWindowPosition);
|
||||
resizeEventUnlisten = await window.listen("tauri://resize", loadWindowSize);
|
||||
}
|
||||
|
||||
async function requestUserAttention_() {
|
||||
await windowMap[selectedWindow].minimize()
|
||||
await windowMap[selectedWindow].minimize();
|
||||
await windowMap[selectedWindow].requestUserAttention(
|
||||
UserAttentionType.Critical
|
||||
)
|
||||
await new Promise((resolve) => setTimeout(resolve, 3000))
|
||||
await windowMap[selectedWindow].requestUserAttention(null)
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||
await windowMap[selectedWindow].requestUserAttention(null);
|
||||
}
|
||||
|
||||
$: {
|
||||
windowMap[selectedWindow]
|
||||
loadWindowPosition()
|
||||
loadWindowSize()
|
||||
windowMap[selectedWindow];
|
||||
loadWindowPosition();
|
||||
loadWindowSize();
|
||||
}
|
||||
$: windowMap[selectedWindow]?.setResizable(resizable)
|
||||
$: windowMap[selectedWindow]?.setResizable(resizable);
|
||||
$: maximized
|
||||
? windowMap[selectedWindow]?.maximize()
|
||||
: windowMap[selectedWindow]?.unmaximize()
|
||||
$: windowMap[selectedWindow]?.setDecorations(decorations)
|
||||
$: windowMap[selectedWindow]?.setAlwaysOnTop(alwaysOnTop)
|
||||
$: windowMap[selectedWindow]?.setContentProtected(contentProtected)
|
||||
$: windowMap[selectedWindow]?.setFullscreen(fullscreen)
|
||||
: windowMap[selectedWindow]?.unmaximize();
|
||||
$: windowMap[selectedWindow]?.setDecorations(decorations);
|
||||
$: windowMap[selectedWindow]?.setAlwaysOnTop(alwaysOnTop);
|
||||
$: windowMap[selectedWindow]?.setContentProtected(contentProtected);
|
||||
$: windowMap[selectedWindow]?.setFullscreen(fullscreen);
|
||||
|
||||
$: width &&
|
||||
height &&
|
||||
windowMap[selectedWindow]?.setSize(new PhysicalSize(width, height))
|
||||
windowMap[selectedWindow]?.setSize(new PhysicalSize(width, height));
|
||||
$: minWidth && minHeight
|
||||
? windowMap[selectedWindow]?.setMinSize(
|
||||
new LogicalSize(minWidth, minHeight)
|
||||
)
|
||||
: windowMap[selectedWindow]?.setMinSize(null)
|
||||
: windowMap[selectedWindow]?.setMinSize(null);
|
||||
$: maxWidth > 800 && maxHeight > 400
|
||||
? windowMap[selectedWindow]?.setMaxSize(
|
||||
new LogicalSize(maxWidth, maxHeight)
|
||||
)
|
||||
: windowMap[selectedWindow]?.setMaxSize(null)
|
||||
: windowMap[selectedWindow]?.setMaxSize(null);
|
||||
$: x !== null &&
|
||||
y !== null &&
|
||||
windowMap[selectedWindow]?.setPosition(new PhysicalPosition(x, y))
|
||||
windowMap[selectedWindow]?.setPosition(new PhysicalPosition(x, y));
|
||||
$: windowMap[selectedWindow]
|
||||
?.scaleFactor()
|
||||
.then((factor) => (scaleFactor = factor))
|
||||
$: addWindowEventListeners(windowMap[selectedWindow])
|
||||
.then((factor) => (scaleFactor = factor));
|
||||
$: addWindowEventListeners(windowMap[selectedWindow]);
|
||||
|
||||
$: windowMap[selectedWindow]?.setCursorGrab(cursorGrab)
|
||||
$: windowMap[selectedWindow]?.setCursorVisible(cursorVisible)
|
||||
$: windowMap[selectedWindow]?.setCursorIcon(cursorIcon)
|
||||
$: windowMap[selectedWindow]?.setCursorGrab(cursorGrab);
|
||||
$: windowMap[selectedWindow]?.setCursorVisible(cursorVisible);
|
||||
$: windowMap[selectedWindow]?.setCursorIcon(cursorIcon);
|
||||
$: cursorX !== null &&
|
||||
cursorY !== null &&
|
||||
windowMap[selectedWindow]?.setCursorPosition(
|
||||
new PhysicalPosition(cursorX, cursorY)
|
||||
)
|
||||
$: windowMap[selectedWindow]?.setIgnoreCursorEvents(cursorIgnoreEvents)
|
||||
);
|
||||
$: windowMap[selectedWindow]?.setIgnoreCursorEvents(cursorIgnoreEvents);
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col children:grow gap-2">
|
||||
|
||||
Reference in New Issue
Block a user