mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
copy plugin sources
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "tauri-plugin-positioner"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
tauri.workspace = true
|
||||
log.workspace = true
|
||||
thiserror.workspace = true
|
||||
|
||||
[features]
|
||||
system-tray = [ "tauri/system-tray" ]
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
var d=Object.defineProperty;var e=(c,a)=>{for(var b in a)d(c,b,{get:a[b],enumerable:!0});};
|
||||
|
||||
var f={};e(f,{convertFileSrc:()=>w,invoke:()=>c,transformCallback:()=>s});function u(){return window.crypto.getRandomValues(new Uint32Array(1))[0]}function s(e,r=!1){let n=u(),t=`_${n}`;return Object.defineProperty(window,t,{value:o=>(r&&Reflect.deleteProperty(window,t),e==null?void 0:e(o)),writable:!1,configurable:!0}),n}async function c(e,r={}){return new Promise((n,t)=>{let o=s(i=>{n(i),Reflect.deleteProperty(window,`_${a}`);},!0),a=s(i=>{t(i),Reflect.deleteProperty(window,`_${o}`);},!0);window.__TAURI_IPC__({cmd:e,callback:o,error:a,...r});})}function w(e,r="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${r}.localhost/${n}`:`${r}://localhost/${n}`}
|
||||
|
||||
// Copyright 2021 Jonas Kruckenberg
|
||||
/**
|
||||
* Well known window positions.
|
||||
*/
|
||||
var Position;
|
||||
(function (Position) {
|
||||
Position[Position["TopLeft"] = 0] = "TopLeft";
|
||||
Position[Position["TopRight"] = 1] = "TopRight";
|
||||
Position[Position["BottomLeft"] = 2] = "BottomLeft";
|
||||
Position[Position["BottomRight"] = 3] = "BottomRight";
|
||||
Position[Position["TopCenter"] = 4] = "TopCenter";
|
||||
Position[Position["BottomCenter"] = 5] = "BottomCenter";
|
||||
Position[Position["LeftCenter"] = 6] = "LeftCenter";
|
||||
Position[Position["RightCenter"] = 7] = "RightCenter";
|
||||
Position[Position["Center"] = 8] = "Center";
|
||||
Position[Position["TrayLeft"] = 9] = "TrayLeft";
|
||||
Position[Position["TrayBottomLeft"] = 10] = "TrayBottomLeft";
|
||||
Position[Position["TrayRight"] = 11] = "TrayRight";
|
||||
Position[Position["TrayBottomRight"] = 12] = "TrayBottomRight";
|
||||
Position[Position["TrayCenter"] = 13] = "TrayCenter";
|
||||
Position[Position["TrayBottomCenter"] = 14] = "TrayBottomCenter";
|
||||
})(Position || (Position = {}));
|
||||
/**
|
||||
* Moves the `Window` to the given {@link Position} using `WindowExt.move_window()`
|
||||
* All positions are relative to the **current** screen.
|
||||
*
|
||||
* @param to The {@link Position} to move to.
|
||||
*/
|
||||
async function moveWindow(to) {
|
||||
await c("plugin:positioner|move_window", {
|
||||
position: to,
|
||||
});
|
||||
}
|
||||
|
||||
export { Position, moveWindow };
|
||||
//# sourceMappingURL=index.min.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.min.js","sources":["../../../../node_modules/.pnpm/@tauri-apps+api@1.2.0/node_modules/@tauri-apps/api/chunk-FEIY7W7S.js","../../../../node_modules/.pnpm/@tauri-apps+api@1.2.0/node_modules/@tauri-apps/api/chunk-RCPA6UVN.js","../index.ts"],"sourcesContent":["var d=Object.defineProperty;var e=(c,a)=>{for(var b in a)d(c,b,{get:a[b],enumerable:!0})};export{e as a};\n","import{a as d}from\"./chunk-FEIY7W7S.js\";var f={};d(f,{convertFileSrc:()=>w,invoke:()=>c,transformCallback:()=>s});function u(){return window.crypto.getRandomValues(new Uint32Array(1))[0]}function s(e,r=!1){let n=u(),t=`_${n}`;return Object.defineProperty(window,t,{value:o=>(r&&Reflect.deleteProperty(window,t),e==null?void 0:e(o)),writable:!1,configurable:!0}),n}async function c(e,r={}){return new Promise((n,t)=>{let o=s(i=>{n(i),Reflect.deleteProperty(window,`_${a}`)},!0),a=s(i=>{t(i),Reflect.deleteProperty(window,`_${o}`)},!0);window.__TAURI_IPC__({cmd:e,callback:o,error:a,...r})})}function w(e,r=\"asset\"){let n=encodeURIComponent(e);return navigator.userAgent.includes(\"Windows\")?`https://${r}.localhost/${n}`:`${r}://localhost/${n}`}export{s as a,c as b,w as c,f as d};\n",null],"names":["d","invoke"],"mappings":"AAAA,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC;;ACAjD,IAAI,CAAC,CAAC,EAAE,CAACA,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC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Ae,UAAU,CAAC,EAAY,EAAA;IAC3C,MAAMC,CAAM,CAAC,+BAA+B,EAAE;AAC5C,QAAA,QAAQ,EAAE,EAAE;AACb,KAAA,CAAC,CAAC;AACL;;;;"}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
|
||||
// Copyright 2021 Jonas Kruckenberg
|
||||
/**
|
||||
* Well known window positions.
|
||||
*/
|
||||
var Position;
|
||||
(function (Position) {
|
||||
Position[Position["TopLeft"] = 0] = "TopLeft";
|
||||
Position[Position["TopRight"] = 1] = "TopRight";
|
||||
Position[Position["BottomLeft"] = 2] = "BottomLeft";
|
||||
Position[Position["BottomRight"] = 3] = "BottomRight";
|
||||
Position[Position["TopCenter"] = 4] = "TopCenter";
|
||||
Position[Position["BottomCenter"] = 5] = "BottomCenter";
|
||||
Position[Position["LeftCenter"] = 6] = "LeftCenter";
|
||||
Position[Position["RightCenter"] = 7] = "RightCenter";
|
||||
Position[Position["Center"] = 8] = "Center";
|
||||
Position[Position["TrayLeft"] = 9] = "TrayLeft";
|
||||
Position[Position["TrayBottomLeft"] = 10] = "TrayBottomLeft";
|
||||
Position[Position["TrayRight"] = 11] = "TrayRight";
|
||||
Position[Position["TrayBottomRight"] = 12] = "TrayBottomRight";
|
||||
Position[Position["TrayCenter"] = 13] = "TrayCenter";
|
||||
Position[Position["TrayBottomCenter"] = 14] = "TrayBottomCenter";
|
||||
})(Position || (Position = {}));
|
||||
/**
|
||||
* Moves the `Window` to the given {@link Position} using `WindowExt.move_window()`
|
||||
* All positions are relative to the **current** screen.
|
||||
*
|
||||
* @param to The {@link Position} to move to.
|
||||
*/
|
||||
async function moveWindow(to) {
|
||||
await invoke("plugin:positioner|move_window", {
|
||||
position: to,
|
||||
});
|
||||
}
|
||||
|
||||
export { Position, moveWindow };
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.mjs","sources":["../index.ts"],"sourc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A,CAAA,GAAA,YAAU,CAAA;AACV,IAAA,QAAA,CAAA,QAAA,CAAA,kBAAA,CAAA,GAAA,EAAA,CAAA,GAAA,kBAAgB,CAAA;AAClB,CAAC,EAhBW,QAAQ,KAAR,QAAQ,GAgBnB,EAAA,CAAA,CAAA,CAAA;AAED;;;;;AAKG;AACI,eAAe,UAAU,CAAC,EAAY,EAAA;IAC3C,MAAM,MAAM,CAAC,+BAA+B,EAAE;AAC5C,QAAA,QAAQ,EAAE,EAAE;AACb,KAAA,CAAC,CAAC;AACL;;;;"}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2021 Jonas Kruckenberg
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
|
||||
/**
|
||||
* Well known window positions.
|
||||
*/
|
||||
export enum Position {
|
||||
TopLeft = 0,
|
||||
TopRight,
|
||||
BottomLeft,
|
||||
BottomRight,
|
||||
TopCenter,
|
||||
BottomCenter,
|
||||
LeftCenter,
|
||||
RightCenter,
|
||||
Center,
|
||||
TrayLeft,
|
||||
TrayBottomLeft,
|
||||
TrayRight,
|
||||
TrayBottomRight,
|
||||
TrayCenter,
|
||||
TrayBottomCenter,
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the `Window` to the given {@link Position} using `WindowExt.move_window()`
|
||||
* All positions are relative to the **current** screen.
|
||||
*
|
||||
* @param to The {@link Position} to move to.
|
||||
*/
|
||||
export async function moveWindow(to: Position): Promise<void> {
|
||||
await invoke("plugin:positioner|move_window", {
|
||||
position: to,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "tauri-plugin-positioner-api",
|
||||
"version": "0.0.0",
|
||||
"license": "MIT or APACHE-2.0",
|
||||
"type": "module",
|
||||
"browser": "dist/index.min.js",
|
||||
"module": "dist/index.mjs",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
"import": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"browser": "./dist/index.min.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"!dist/**/*.map",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"devDependencies": {
|
||||
"tslib": "^2.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^1.2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
import { createConfig } from "../../../shared/rollup.config.mjs";
|
||||
|
||||
export default createConfig({
|
||||
pkg: JSON.parse(
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8")
|
||||
),
|
||||
external: [/^@tauri-apps\/api/],
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
../../../shared/tsconfig.json
|
||||
@@ -0,0 +1,182 @@
|
||||
// Copyright 2021 Jonas Kruckenberg
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#[cfg(feature = "system-tray")]
|
||||
use crate::Tray;
|
||||
use serde_repr::Deserialize_repr;
|
||||
#[cfg(feature = "system-tray")]
|
||||
use tauri::Manager;
|
||||
use tauri::{PhysicalPosition, PhysicalSize, Result, Runtime, Window};
|
||||
|
||||
/// Well known window positions.
|
||||
#[derive(Debug, Deserialize_repr)]
|
||||
#[repr(u16)]
|
||||
pub enum Position {
|
||||
TopLeft = 0,
|
||||
TopRight,
|
||||
BottomLeft,
|
||||
BottomRight,
|
||||
TopCenter,
|
||||
BottomCenter,
|
||||
LeftCenter,
|
||||
RightCenter,
|
||||
Center,
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayLeft,
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayBottomLeft,
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayRight,
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayBottomRight,
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayCenter,
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayBottomCenter,
|
||||
}
|
||||
|
||||
/// A [`Window`] extension that provides extra methods related to positioning.
|
||||
pub trait WindowExt {
|
||||
/// Moves the [`Window`] to the given [`Position`]
|
||||
///
|
||||
/// All positions are relative to the **current** screen.
|
||||
fn move_window(&self, position: Position) -> Result<()>;
|
||||
}
|
||||
|
||||
impl<R: Runtime> WindowExt for Window<R> {
|
||||
fn move_window(&self, pos: Position) -> Result<()> {
|
||||
use Position::*;
|
||||
|
||||
let screen = self.current_monitor()?.unwrap();
|
||||
let screen_position = screen.position();
|
||||
let screen_size = PhysicalSize::<i32> {
|
||||
width: screen.size().width as i32,
|
||||
height: screen.size().height as i32,
|
||||
};
|
||||
let window_size = PhysicalSize::<i32> {
|
||||
width: self.outer_size()?.width as i32,
|
||||
height: self.outer_size()?.height as i32,
|
||||
};
|
||||
#[cfg(feature = "system-tray")]
|
||||
let (tray_position, tray_size) = self
|
||||
.state::<Tray>()
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.map(|(pos, size)| {
|
||||
(
|
||||
Some((pos.x as i32, pos.y as i32)),
|
||||
Some((size.width as i32, size.height as i32)),
|
||||
)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
let physical_pos = match pos {
|
||||
TopLeft => *screen_position,
|
||||
TopRight => PhysicalPosition {
|
||||
x: screen_position.x + (screen_size.width - window_size.width),
|
||||
y: screen_position.y,
|
||||
},
|
||||
BottomLeft => PhysicalPosition {
|
||||
x: screen_position.x,
|
||||
y: screen_size.height - (window_size.height - screen_position.y),
|
||||
},
|
||||
BottomRight => PhysicalPosition {
|
||||
x: screen_position.x + (screen_size.width - window_size.width),
|
||||
y: screen_size.height - (window_size.height - screen_position.y),
|
||||
},
|
||||
TopCenter => PhysicalPosition {
|
||||
x: screen_position.x + ((screen_size.width / 2) - (window_size.width / 2)),
|
||||
y: screen_position.y,
|
||||
},
|
||||
BottomCenter => PhysicalPosition {
|
||||
x: screen_position.x + ((screen_size.width / 2) - (window_size.width / 2)),
|
||||
y: screen_size.height - (window_size.height - screen_position.y),
|
||||
},
|
||||
LeftCenter => PhysicalPosition {
|
||||
x: screen_position.x,
|
||||
y: screen_position.y + (screen_size.height / 2) - (window_size.height / 2),
|
||||
},
|
||||
RightCenter => PhysicalPosition {
|
||||
x: screen_position.x + (screen_size.width - window_size.width),
|
||||
y: screen_position.y + (screen_size.height / 2) - (window_size.height / 2),
|
||||
},
|
||||
Center => PhysicalPosition {
|
||||
x: screen_position.x + ((screen_size.width / 2) - (window_size.width / 2)),
|
||||
y: screen_position.y + (screen_size.height / 2) - (window_size.height / 2),
|
||||
},
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayLeft => {
|
||||
if let Some((tray_x, tray_y)) = tray_position {
|
||||
PhysicalPosition {
|
||||
x: tray_x,
|
||||
y: tray_y - window_size.height,
|
||||
}
|
||||
} else {
|
||||
panic!("tray position not set");
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayBottomLeft => {
|
||||
if let Some((tray_x, tray_y)) = tray_position {
|
||||
PhysicalPosition {
|
||||
x: tray_x,
|
||||
y: tray_y,
|
||||
}
|
||||
} else {
|
||||
panic!("Tray position not set");
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayRight => {
|
||||
if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size)
|
||||
{
|
||||
PhysicalPosition {
|
||||
x: tray_x + tray_width,
|
||||
y: tray_y - window_size.height,
|
||||
}
|
||||
} else {
|
||||
panic!("Tray position not set");
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayBottomRight => {
|
||||
if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size)
|
||||
{
|
||||
PhysicalPosition {
|
||||
x: tray_x + tray_width,
|
||||
y: tray_y,
|
||||
}
|
||||
} else {
|
||||
panic!("Tray position not set");
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayCenter => {
|
||||
if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size)
|
||||
{
|
||||
PhysicalPosition {
|
||||
x: tray_x + (tray_width / 2) - (window_size.width / 2),
|
||||
y: tray_y - window_size.height,
|
||||
}
|
||||
} else {
|
||||
panic!("Tray position not set");
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "system-tray")]
|
||||
TrayBottomCenter => {
|
||||
if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size)
|
||||
{
|
||||
PhysicalPosition {
|
||||
x: tray_x + (tray_width / 2) - (window_size.width / 2),
|
||||
y: tray_y,
|
||||
}
|
||||
} else {
|
||||
panic!("Tray position not set");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.set_position(tauri::Position::Physical(physical_pos))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright 2021 Jonas Kruckenberg
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//! A plugin for Tauri that helps position your windows at well-known locations.
|
||||
//!
|
||||
//! # Cargo features
|
||||
//!
|
||||
//! - **system-tray**: Enables system-tray-relative positions.
|
||||
//!
|
||||
//! Note: This requires attaching the Tauri plugin, *even* when using the trait extension only.
|
||||
|
||||
mod ext;
|
||||
|
||||
pub use ext::*;
|
||||
use tauri::{
|
||||
plugin::{self, TauriPlugin},
|
||||
Result, Runtime,
|
||||
};
|
||||
|
||||
#[cfg(feature = "system-tray")]
|
||||
use tauri::{AppHandle, Manager, PhysicalPosition, PhysicalSize, SystemTrayEvent};
|
||||
|
||||
#[cfg(feature = "system-tray")]
|
||||
struct Tray(std::sync::Mutex<Option<(PhysicalPosition<f64>, PhysicalSize<f64>)>>);
|
||||
|
||||
#[cfg(feature = "system-tray")]
|
||||
pub fn on_tray_event<R: Runtime>(app: &AppHandle<R>, event: &SystemTrayEvent) {
|
||||
match event {
|
||||
SystemTrayEvent::LeftClick { position, size, .. } => {
|
||||
app.state::<Tray>()
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.replace((*position, *size));
|
||||
}
|
||||
SystemTrayEvent::RightClick { position, size, .. } => {
|
||||
app.state::<Tray>()
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.replace((*position, *size));
|
||||
}
|
||||
SystemTrayEvent::DoubleClick { position, size, .. } => {
|
||||
app.state::<Tray>()
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.replace((*position, *size));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn move_window<R: Runtime>(window: tauri::Window<R>, position: Position) -> Result<()> {
|
||||
window.move_window(position)
|
||||
}
|
||||
|
||||
/// The Tauri plugin that exposes [`WindowExt::move_window`] to the webview.
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
let plugin =
|
||||
plugin::Builder::new("positioner").invoke_handler(tauri::generate_handler![move_window]);
|
||||
|
||||
#[cfg(feature = "system-tray")]
|
||||
let plugin = plugin.setup(|app_handle| {
|
||||
app_handle.manage(Tray(std::sync::Mutex::new(None)));
|
||||
Ok(())
|
||||
});
|
||||
|
||||
plugin.build()
|
||||
}
|
||||
Reference in New Issue
Block a user