snapshot of https://github.com/tauri-apps/plugins-workspace.git (v2, 2026-09-23; blobs > 131072B omitted)
Some checks failed
integration tests / run-integration-tests (windows-latest) (push) Has been cancelled
Test Rust / test (push) Has been cancelled
test plugins e2e (mobile) / ios (push) Has been cancelled
test plugins e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test plugins e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
integration tests / run-integration-tests (macos-latest) (push) Has been cancelled
version or publish / version-or-publish (push) Failing after 0s
integration tests / run-integration-tests (ubuntu-22.04) (push) Failing after 0s
Lint JavaScript / eslint (push) Failing after 0s
Sync / sync-to-mirrors (push) Failing after 0s
test plugins e2e (mobile) / android (push) Failing after 0s
test plugins e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
Test Rust / changes (push) Failing after 0s
Lint Rust / changes (push) Failing after 0s
Lint Rust / clippy (push) Has been skipped
Audit Rust / audit-rust (push) Failing after 1s
Audit JavaScript / audit-js (push) Failing after 1s
Some checks failed
integration tests / run-integration-tests (windows-latest) (push) Has been cancelled
Test Rust / test (push) Has been cancelled
test plugins e2e (mobile) / ios (push) Has been cancelled
test plugins e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test plugins e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
integration tests / run-integration-tests (macos-latest) (push) Has been cancelled
version or publish / version-or-publish (push) Failing after 0s
integration tests / run-integration-tests (ubuntu-22.04) (push) Failing after 0s
Lint JavaScript / eslint (push) Failing after 0s
Sync / sync-to-mirrors (push) Failing after 0s
test plugins e2e (mobile) / android (push) Failing after 0s
test plugins e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
Test Rust / changes (push) Failing after 0s
Lint Rust / changes (push) Failing after 0s
Lint Rust / clippy (push) Has been skipped
Audit Rust / audit-rust (push) Failing after 1s
Audit JavaScript / audit-js (push) Failing after 1s
This commit is contained in:
187
plugins/positioner/CHANGELOG.md
Normal file
187
plugins/positioner/CHANGELOG.md
Normal file
@@ -0,0 +1,187 @@
|
||||
# Changelog
|
||||
|
||||
## [2.3.4]
|
||||
|
||||
- [`f8053e65`](https://github.com/tauri-apps/plugins-workspace/commit/f8053e659e4ccd85c1f52833411ff8417cbc5e69) ([#3527](https://github.com/tauri-apps/plugins-workspace/pull/3527) by [@Legend-Master](https://github.com/tauri-apps/plugins-workspace/../../Legend-Master)) Documented Cargo feature flags in each plugin's crate-level documentation.
|
||||
|
||||
## \[2.3.3]
|
||||
|
||||
- [`4be76900`](https://github.com/tauri-apps/plugins-workspace/commit/4be76900854cae3dc91363dea71b54505896e928) ([#3449](https://github.com/tauri-apps/plugins-workspace/pull/3449) by [@skkap](https://github.com/tauri-apps/plugins-workspace/../../skkap)) Replaced a panic in `calculate_position` with an error return when the window has no associated monitor (e.g. during display sleep or monitor reconfiguration).
|
||||
|
||||
## \[2.3.2]
|
||||
|
||||
- [`c0d64bf7`](https://github.com/tauri-apps/plugins-workspace/commit/c0d64bf7d9c0f2c8ed1d2614745e15bbb3cde6a7) ([#3420](https://github.com/tauri-apps/plugins-workspace/pull/3420) by [@UrsDeSwardt](https://github.com/tauri-apps/plugins-workspace/../../UrsDeSwardt)) Removed panics and replaced them with error handling.
|
||||
|
||||
## \[2.3.1]
|
||||
|
||||
- [`93426f85`](https://github.com/tauri-apps/plugins-workspace/commit/93426f85120f49beb9f40222bff45185a32d54a9) Fixed an issue that caused docs.rs builds to fail. No user facing changes.
|
||||
|
||||
## \[2.3.0]
|
||||
|
||||
- [`f209b2f2`](https://github.com/tauri-apps/plugins-workspace/commit/f209b2f23cb29133c97ad5961fb46ef794dbe063) ([#2804](https://github.com/tauri-apps/plugins-workspace/pull/2804) by [@renovate](https://github.com/tauri-apps/plugins-workspace/../../renovate)) Updated tauri to 2.6
|
||||
|
||||
## \[2.2.1]
|
||||
|
||||
- [`f634e524`](https://github.com/tauri-apps/plugins-workspace/commit/f634e5248ebe428f8305a59f74c13fc15147fb8e) This is an "empty" release to update the plugins' source files on crates.io and docs.rs. This should fix docs.rs build failures for projects using tauri plugins as dependencies.
|
||||
|
||||
## \[2.2.0]
|
||||
|
||||
- [`3a79266b`](https://github.com/tauri-apps/plugins-workspace/commit/3a79266b8cf96a55b1ae6339d725567d45a44b1d) ([#2173](https://github.com/tauri-apps/plugins-workspace/pull/2173) by [@FabianLars](https://github.com/tauri-apps/plugins-workspace/../../FabianLars)) Bumped all plugins to `v2.2.0`. From now, the versions for the Rust and JavaScript packages of each plugin will be in sync with each other.
|
||||
|
||||
## \[2.1.0]
|
||||
|
||||
- [`4db62635`](https://github.com/tauri-apps/plugins-workspace/commit/4db626354c8e29e37bedcf94787a8dd36ce21c55) ([#2076](https://github.com/tauri-apps/plugins-workspace/pull/2076) by [@jakobwesthoff](https://github.com/tauri-apps/plugins-workspace/../../jakobwesthoff)) Add `moveWindowConstrained` function that is similar to `moveWindow` but constrains the window to the screen dimensions in case of tray icon positions.
|
||||
|
||||
## \[2.0.1]
|
||||
|
||||
- [`3c1f3874`](https://github.com/tauri-apps/plugins-workspace/commit/3c1f3874f4c828637b3aa983cba13c77427faf58) ([#1911](https://github.com/tauri-apps/plugins-workspace/pull/1911) by [@lucasfernog](https://github.com/tauri-apps/plugins-workspace/../../lucasfernog)) Added missing permission for `handleIconState` and fixed its event processing logic.
|
||||
|
||||
## \[2.0.1]
|
||||
|
||||
- [`a1a82208`](https://github.com/tauri-apps/plugins-workspace/commit/a1a82208ed4ab87f83310be0dc95428aec9ab241) ([#1873](https://github.com/tauri-apps/plugins-workspace/pull/1873) by [@lucasfernog](https://github.com/tauri-apps/plugins-workspace/../../lucasfernog)) Downgrade MSRV to 1.77.2 to support Windows 7.
|
||||
|
||||
## \[2.0.0]
|
||||
|
||||
- [`e2c4dfb6`](https://github.com/tauri-apps/plugins-workspace/commit/e2c4dfb6af43e5dd8d9ceba232c315f5febd55c1) Update to tauri v2 stable release.
|
||||
|
||||
## \[2.0.0-rc.2]
|
||||
|
||||
- [`2f7e32b5`](https://github.com/tauri-apps/plugins-workspace/commit/2f7e32b5e07454d6c0cf3ab03f8af8da74c4a8a7) ([#1822](https://github.com/tauri-apps/plugins-workspace/pull/1822) by [@jbolda](https://github.com/tauri-apps/plugins-workspace/../../jbolda)) `handleIconState` function for use in JavaScript event handlers. This allows one to update the TrayIcon state through JavaScript and fully create and handle the TrayIcon without requiring Rust (and the side-effect of creating a TrayIcon).
|
||||
|
||||
## \[2.0.0-rc.1]
|
||||
|
||||
- [`e2e97db5`](https://github.com/tauri-apps/plugins-workspace/commit/e2e97db51983267f5be84d4f6f0278d58834d1f5) ([#1701](https://github.com/tauri-apps/plugins-workspace/pull/1701) by [@lucasfernog](https://github.com/tauri-apps/plugins-workspace/../../lucasfernog)) Update to tauri 2.0.0-rc.8
|
||||
|
||||
## \[2.0.0-rc.0]
|
||||
|
||||
- [`9887d1`](https://github.com/tauri-apps/plugins-workspace/commit/9887d14bd0e971c4c0f5c1188fc4005d3fc2e29e) Update to tauri RC.
|
||||
|
||||
## \[2.0.0-beta.8]
|
||||
|
||||
- [`99d6ac0f`](https://github.com/tauri-apps/plugins-workspace/commit/99d6ac0f9506a6a4a1aa59c728157190a7441af6) ([#1606](https://github.com/tauri-apps/plugins-workspace/pull/1606) by [@FabianLars](https://github.com/tauri-apps/plugins-workspace/../../FabianLars)) The JS packages now specify the *minimum* `@tauri-apps/api` version instead of a single exact version.
|
||||
- [`6de87966`](https://github.com/tauri-apps/plugins-workspace/commit/6de87966ecc00ad9d91c25be452f1f46bd2b7e1f) ([#1597](https://github.com/tauri-apps/plugins-workspace/pull/1597) by [@Legend-Master](https://github.com/tauri-apps/plugins-workspace/../../Legend-Master)) Update to tauri beta.25.
|
||||
|
||||
## \[2.0.0-beta.7]
|
||||
|
||||
- [`22a17980`](https://github.com/tauri-apps/plugins-workspace/commit/22a17980ff4f6f8c40adb1b8f4ffc6dae2fe7e30) ([#1537](https://github.com/tauri-apps/plugins-workspace/pull/1537) by [@lucasfernog](https://github.com/tauri-apps/plugins-workspace/../../lucasfernog)) Update to tauri beta.24.
|
||||
|
||||
## \[2.0.0-beta.6]
|
||||
|
||||
- [`76daee7a`](https://github.com/tauri-apps/plugins-workspace/commit/76daee7aafece34de3092c86e531cf9eb1138989) ([#1512](https://github.com/tauri-apps/plugins-workspace/pull/1512) by [@renovate](https://github.com/tauri-apps/plugins-workspace/../../renovate)) Update to tauri beta.23.
|
||||
|
||||
## \[2.0.0-beta.5]
|
||||
|
||||
- [`9013854f`](https://github.com/tauri-apps/plugins-workspace/commit/9013854f42a49a230b9dbb9d02774765528a923f)([#1382](https://github.com/tauri-apps/plugins-workspace/pull/1382)) Update to tauri beta.22.
|
||||
|
||||
## \[2.0.0-beta.4]
|
||||
|
||||
- [`430bd6f4`](https://github.com/tauri-apps/plugins-workspace/commit/430bd6f4f379bee5d232ae6b098ae131db7f178a)([#1363](https://github.com/tauri-apps/plugins-workspace/pull/1363)) Update to tauri beta.20.
|
||||
|
||||
## \[2.0.0-beta.5]
|
||||
|
||||
- [`d9de5b19`](https://github.com/tauri-apps/plugins-workspace/commit/d9de5b19d1e950c06f0915ae92a862acb266d108)([#1283](https://github.com/tauri-apps/plugins-workspace/pull/1283)) Implement `WindowExt` for `WebviewWindow`.
|
||||
|
||||
## \[2.0.0-beta.3]
|
||||
|
||||
- [`bd1ed590`](https://github.com/tauri-apps/plugins-workspace/commit/bd1ed5903ffcce5500310dac1e59e8c67674ef1e)([#1237](https://github.com/tauri-apps/plugins-workspace/pull/1237)) Update to tauri beta.17.
|
||||
|
||||
## \[2.0.0-beta.3]
|
||||
|
||||
- [`a04ea2f`](https://github.com/tauri-apps/plugins-workspace/commit/a04ea2f38294d5a3987578283badc8eec87a7752)([#1071](https://github.com/tauri-apps/plugins-workspace/pull/1071)) The global API script is now only added to the binary when the `withGlobalTauri` config is true.
|
||||
|
||||
## \[2.0.0-beta.2]
|
||||
|
||||
- [`99bea25`](https://github.com/tauri-apps/plugins-workspace/commit/99bea2559c2c0648c2519c50a18cd124dacef57b)([#1005](https://github.com/tauri-apps/plugins-workspace/pull/1005)) Update to tauri beta.8.
|
||||
|
||||
## \[2.0.0-beta.1]
|
||||
|
||||
- [`569defb`](https://github.com/tauri-apps/plugins-workspace/commit/569defbe9492e38938554bb7bdc1be9151456d21) Update to tauri beta.4.
|
||||
|
||||
## \[2.0.0-beta.0]
|
||||
|
||||
- [`d198c01`](https://github.com/tauri-apps/plugins-workspace/commit/d198c014863ee260cb0de88a14b7fc4356ef7474)([#862](https://github.com/tauri-apps/plugins-workspace/pull/862)) Update to tauri beta.
|
||||
|
||||
## \[2.0.0-alpha.5]
|
||||
|
||||
- [`387c2f9`](https://github.com/tauri-apps/plugins-workspace/commit/387c2f9e0ce4c75c07ffa3fd76391a25b58f5daf)([#802](https://github.com/tauri-apps/plugins-workspace/pull/802)) Update to @tauri-apps/api v2.0.0-alpha.13.
|
||||
|
||||
## \[2.0.0-alpha.4]
|
||||
|
||||
- [`387c2f9`](https://github.com/tauri-apps/plugins-workspace/commit/387c2f9e0ce4c75c07ffa3fd76391a25b58f5daf)([#802](https://github.com/tauri-apps/plugins-workspace/pull/802)) Update to @tauri-apps/api v2.0.0-alpha.12.
|
||||
|
||||
## \[2.0.0-alpha.3]
|
||||
|
||||
- [`e438e0a`](https://github.com/tauri-apps/plugins-workspace/commit/e438e0a62d4b430a5159f05f13ecd397dd891a0d)([#676](https://github.com/tauri-apps/plugins-workspace/pull/676)) Update to @tauri-apps/api v2.0.0-alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.2]
|
||||
|
||||
- [`5c13736`](https://github.com/tauri-apps/plugins-workspace/commit/5c137365c60790e8d4037d449e8237aa3fffdab0)([#673](https://github.com/tauri-apps/plugins-workspace/pull/673)) Update to @tauri-apps/api v2.0.0-alpha.9.
|
||||
|
||||
## \[2.0.0-alpha.2]
|
||||
|
||||
- [`4e2cef9`](https://github.com/tauri-apps/plugins-workspace/commit/4e2cef9b702bbbb9cf4ee17de50791cb21f1b2a4)([#593](https://github.com/tauri-apps/plugins-workspace/pull/593)) Update to alpha.12.
|
||||
|
||||
## \[2.0.0-alpha.1]
|
||||
|
||||
- [`d74fc0a`](https://github.com/tauri-apps/plugins-workspace/commit/d74fc0a097996e90a37be8f57d50b7d1f6ca616f)([#555](https://github.com/tauri-apps/plugins-workspace/pull/555)) Update to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
|
||||
## \[1.0.5]
|
||||
|
||||
- `TrayLeft`, `TrayRight` and `TrayCenter` will now position the window according to the tray position relative to the monitor dimensions to prevent windows being displayed partially off-screen.
|
||||
- [3d27909](https://github.com/tauri-apps/plugins-workspace/commit/3d279094d44be78cdc5d1de3938f1414e13db6b0) fix(positioner): Prevent tray relative windows from being moved off-screen ([#291](https://github.com/tauri-apps/plugins-workspace/pull/291)) on 2023-09-27
|
||||
|
||||
## \[0.2.7]
|
||||
|
||||
- Update Tauri to v1.0.0
|
||||
- Bumped due to a bump in tauri-plugin-positioner.
|
||||
- [0bb73eb](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/commit/0bb73eb20dae87f730c0b5f4cc08e6689e25fdba) Create tauri-v1.md on 2022-06-16
|
||||
|
||||
## \[0.2.6]
|
||||
|
||||
- Update Tauri to v1.0.0-rc.12
|
||||
- Bumped due to a bump in tauri-plugin-positioner.
|
||||
- [de6d76f](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/commit/de6d76f3a96a68e88a7ac434d65df4dbc82af122) Create update-tauri.md on 2022-05-25
|
||||
|
||||
## \[0.2.5]
|
||||
|
||||
- Update deps
|
||||
- Bumped due to a bump in tauri-plugin-positioner.
|
||||
- [a8d3f73](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/commit/a8d3f73b74829ef5d53d4fb028e59d09e8946399) Create chore-update-deps.md on 2022-05-18
|
||||
|
||||
## \[0.2.4]
|
||||
|
||||
- Update Tauri dependencies
|
||||
- [2095b6a](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/commit/2095b6a4a4ab5590add099ddb2b1e8118e3496e4) add dep update changefile on 2022-02-14
|
||||
- [53d3a50](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/commit/53d3a501776f16741124aa961f521b9d7798c878) publish new versions ([#42](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/pull/42)) on 2022-02-14
|
||||
- [9f32726](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/commit/9f32726ede38bb9b2711f738a2f9fee7f0da2d73) Create update-deps.md on 2022-05-11
|
||||
|
||||
## \[0.2.3]
|
||||
|
||||
- **Breaking Change**: Uses the new Tauri plugin builder pattern. Use `tauri_plugin_positioner::init()` instead of `tauri_plugin_positioner::Positioner::default()`.
|
||||
- Bumped due to a bump in tauri-plugin-positioner.
|
||||
- [14837a8](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/commit/14837a8d9cecdd6014867d4ef00fb98f21b2249d) refactor: use new builder pattern on 2022-02-26
|
||||
- [59874d8](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/commit/59874d827471dfb889662fadc74fec1f2243b89e) fix typo on 2022-02-26
|
||||
|
||||
## \[0.2.2]
|
||||
|
||||
- Update README.md
|
||||
- Bumped due to a bump in tauri-plugin-positioner.
|
||||
- [92d6c3d](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/commit/92d6c3dca00a6b3562682804a649c0023831ce2b) Create docs-update-readme.md on 2022-02-17
|
||||
|
||||
## \[0.2.1]
|
||||
|
||||
- Update `tauri` to `1.0.0-rc.1`, `serde` to `1.0.136` and `serde_json` to `1.0.79`.
|
||||
- [2095b6a](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/commit/2095b6a4a4ab5590add099ddb2b1e8118e3496e4) add dep update changefile on 2022-02-14
|
||||
|
||||
## \[0.2.0]
|
||||
|
||||
- Add SystemTray relative positions.
|
||||
- [765b3ed](https://www.github.com/JonasKruckenberg/tauri-plugin-positioner/commit/765b3ed90056d85ae88b0852b7107ff2b84a6c3a) Create feat-tray-pos.md on 2022-01-19
|
||||
|
||||
## \[0.1.0]
|
||||
|
||||
- Update package/crate metadata
|
||||
38
plugins/positioner/Cargo.toml
Normal file
38
plugins/positioner/Cargo.toml
Normal file
@@ -0,0 +1,38 @@
|
||||
[package]
|
||||
name = "tauri-plugin-positioner"
|
||||
version = "2.3.4"
|
||||
description = "Position your windows at well-known locations."
|
||||
authors = { workspace = true }
|
||||
license = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
rust-version = { workspace = true }
|
||||
repository = { workspace = true }
|
||||
links = "tauri-plugin-positioner"
|
||||
exclude = [
|
||||
"/banner.png",
|
||||
"/guest-js",
|
||||
"/package.json",
|
||||
"/rollup.config.js",
|
||||
"/tsconfig.json",
|
||||
]
|
||||
|
||||
[package.metadata.platforms.support]
|
||||
windows = { level = "full", notes = "" }
|
||||
linux = { level = "full", notes = "" }
|
||||
macos = { level = "full", notes = "" }
|
||||
android = { level = "none", notes = "" }
|
||||
ios = { level = "none", notes = "" }
|
||||
|
||||
[build-dependencies]
|
||||
tauri-plugin = { workspace = true, features = ["build"] }
|
||||
|
||||
[dependencies]
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
tauri = { workspace = true }
|
||||
log = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
serde_repr = "0.1"
|
||||
|
||||
[features]
|
||||
tray-icon = ["tauri/tray-icon"]
|
||||
20
plugins/positioner/LICENSE.spdx
Normal file
20
plugins/positioner/LICENSE.spdx
Normal file
@@ -0,0 +1,20 @@
|
||||
SPDXVersion: SPDX-2.1
|
||||
DataLicense: CC0-1.0
|
||||
PackageName: tauri
|
||||
DataFormat: SPDXRef-1
|
||||
PackageSupplier: Organization: The Tauri Programme in the Commons Conservancy
|
||||
PackageHomePage: https://tauri.app
|
||||
PackageLicenseDeclared: Apache-2.0
|
||||
PackageLicenseDeclared: MIT
|
||||
PackageCopyrightText: 2019-2022, The Tauri Programme in the Commons Conservancy
|
||||
PackageSummary: <text>Tauri is a rust project that enables developers to make secure
|
||||
and small desktop applications using a web frontend.
|
||||
</text>
|
||||
PackageComment: <text>The package includes the following libraries; see
|
||||
Relationship information.
|
||||
</text>
|
||||
Created: 2019-05-20T09:00:00Z
|
||||
PackageDownloadLocation: git://github.com/tauri-apps/tauri
|
||||
PackageDownloadLocation: git+https://github.com/tauri-apps/tauri.git
|
||||
PackageDownloadLocation: git+ssh://github.com/tauri-apps/tauri.git
|
||||
Creator: Person: Daniel Thompson-Yvetot
|
||||
177
plugins/positioner/LICENSE_APACHE-2.0
Normal file
177
plugins/positioner/LICENSE_APACHE-2.0
Normal file
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
21
plugins/positioner/LICENSE_MIT
Normal file
21
plugins/positioner/LICENSE_MIT
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 - Present Tauri Apps Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
148
plugins/positioner/README.md
Normal file
148
plugins/positioner/README.md
Normal file
@@ -0,0 +1,148 @@
|
||||

|
||||
|
||||
Position your windows at well-known locations.
|
||||
|
||||
This plugin is a port of [electron-positioner](https://github.com/jenslind/electron-positioner) for Tauri.
|
||||
|
||||
| Platform | Supported |
|
||||
| -------- | --------- |
|
||||
| Linux | ✓ |
|
||||
| Windows | ✓ |
|
||||
| macOS | ✓ |
|
||||
| Android | x |
|
||||
| iOS | x |
|
||||
|
||||
## Install
|
||||
|
||||
_This plugin requires a Rust version of at least **1.77.2**_
|
||||
|
||||
There are three general methods of installation that we can recommend.
|
||||
|
||||
1. Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
|
||||
2. Pull sources directly from Github using git tags / revision hashes (most secure)
|
||||
3. Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use)
|
||||
|
||||
Install the Core plugin by adding the following to your `Cargo.toml` file:
|
||||
|
||||
`src-tauri/Cargo.toml`
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
tauri-plugin-positioner = "2.0.0"
|
||||
# alternatively with Git:
|
||||
tauri-plugin-positioner = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
```
|
||||
|
||||
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
|
||||
|
||||
```sh
|
||||
pnpm add @tauri-apps/plugin-positioner
|
||||
# or
|
||||
npm add @tauri-apps/plugin-positioner
|
||||
# or
|
||||
yarn add @tauri-apps/plugin-positioner
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
First you need to register the core plugin with Tauri:
|
||||
|
||||
`src-tauri/src/lib.rs`
|
||||
|
||||
```rust
|
||||
use tauri::tray::TrayIconBuilder;
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_positioner::init())
|
||||
// This is required to get tray-relative positions to work
|
||||
.setup(|app| {
|
||||
// note that this will create a new TrayIcon
|
||||
TrayIconBuilder::new()
|
||||
.on_tray_icon_event(|app, event| {
|
||||
tauri_plugin_positioner::on_tray_event(app.app_handle(), &event);
|
||||
})
|
||||
.build(app)?;
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
```
|
||||
|
||||
Alternatively, you may handle the tray events through JavaScript. Register the plugin as previously noted.
|
||||
|
||||
```rust
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_positioner::init())
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
```
|
||||
|
||||
And in JavaScript, the `action` passed to the TrayIcon should include the handler.
|
||||
|
||||
```javascript
|
||||
import {
|
||||
moveWindow,
|
||||
Position,
|
||||
handleIconState,
|
||||
} from "@tauri-apps/plugin-positioner";
|
||||
|
||||
const action = async (event: TrayIconEvent) => {
|
||||
// add the handle in the action to update the state
|
||||
await handleIconState(event);
|
||||
|
||||
if (event.type === "Click") {
|
||||
// note this option requires enabling the `tray-icon`
|
||||
// feature in the Cargo.toml
|
||||
await moveWindow(Position.TrayLeft);
|
||||
}
|
||||
};
|
||||
|
||||
const tray = await TrayIcon.new({ id: "main", action });
|
||||
```
|
||||
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
import { moveWindow, Position } from '@tauri-apps/plugin-positioner'
|
||||
|
||||
moveWindow(Position.TopRight)
|
||||
```
|
||||
|
||||
If you only intend on moving the window from rust code, you can import the Window trait extension instead of registering the plugin:
|
||||
|
||||
```rust
|
||||
use tauri_plugin_positioner::{WindowExt, Position};
|
||||
|
||||
let mut win = app.get_window("main").unwrap();
|
||||
let _ = win.move_window(Position::TopRight);
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
|
||||
|
||||
## Partners
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://crabnebula.dev" target="_blank">
|
||||
<img src="https://github.com/tauri-apps/plugins-workspace/raw/v2/.github/sponsors/crabnebula.svg" alt="CrabNebula" width="283">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
For the complete list of sponsors please visit our [website](https://tauri.app#sponsors) and [Open Collective](https://opencollective.com/tauri).
|
||||
|
||||
## License
|
||||
|
||||
Code: (c) 2021 - Jonas Kruckenberg. 2021 - Present - The Tauri Programme within The Commons Conservancy.
|
||||
|
||||
MIT or MIT/Apache 2.0 where applicable.
|
||||
23
plugins/positioner/SECURITY.md
Normal file
23
plugins/positioner/SECURITY.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Security Policy
|
||||
|
||||
**Do not report security vulnerabilities through public GitHub issues.**
|
||||
|
||||
**Please use the [Private Vulnerability Disclosure](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/privately-reporting-a-security-vulnerability#privately-reporting-a-security-vulnerability) feature of GitHub.**
|
||||
|
||||
Include as much of the following information:
|
||||
|
||||
- Type of issue (e.g. improper input parsing, privilege escalation, etc.)
|
||||
- The location of the affected source code (tag/branch/commit or direct URL)
|
||||
- Any special configuration required to reproduce the issue
|
||||
- The distribution affected or used to help us with reproduction of the issue
|
||||
- Step-by-step instructions to reproduce the issue
|
||||
- Ideally a reproduction repository
|
||||
- Impact of the issue, including how an attacker might exploit the issue
|
||||
|
||||
We prefer to receive reports in English.
|
||||
|
||||
## Contact
|
||||
|
||||
Please disclose a vulnerability or security relevant issue here: [https://github.com/tauri-apps/plugins-workspace/security/advisories/new](https://github.com/tauri-apps/plugins-workspace/security/advisories/new).
|
||||
|
||||
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
|
||||
1
plugins/positioner/api-iife.js
Normal file
1
plugins/positioner/api-iife.js
Normal file
@@ -0,0 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_PLUGIN_POSITIONER__=function(t,o){"use strict";var e;return t.Position=void 0,(e=t.Position||(t.Position={}))[e.TopLeft=0]="TopLeft",e[e.TopRight=1]="TopRight",e[e.BottomLeft=2]="BottomLeft",e[e.BottomRight=3]="BottomRight",e[e.TopCenter=4]="TopCenter",e[e.BottomCenter=5]="BottomCenter",e[e.LeftCenter=6]="LeftCenter",e[e.RightCenter=7]="RightCenter",e[e.Center=8]="Center",e[e.TrayLeft=9]="TrayLeft",e[e.TrayBottomLeft=10]="TrayBottomLeft",e[e.TrayRight=11]="TrayRight",e[e.TrayBottomRight=12]="TrayBottomRight",e[e.TrayCenter=13]="TrayCenter",e[e.TrayBottomCenter=14]="TrayBottomCenter",t.handleIconState=async function(t){await o.invoke("plugin:positioner|set_tray_icon_state",{position:t.rect.position,size:t.rect.size})},t.moveWindow=async function(t){await o.invoke("plugin:positioner|move_window",{position:t})},t.moveWindowConstrained=async function(t){await o.invoke("plugin:positioner|move_window_constrained",{position:t})},t}({},window.__TAURI__.core);Object.defineProperty(window.__TAURI__,"positioner",{value:__TAURI_PLUGIN_POSITIONER__})}
|
||||
BIN
plugins/positioner/banner.png
Normal file
BIN
plugins/positioner/banner.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
15
plugins/positioner/build.rs
Normal file
15
plugins/positioner/build.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
const COMMANDS: &[&str] = &[
|
||||
"move_window",
|
||||
"move_window_constrained",
|
||||
"set_tray_icon_state",
|
||||
];
|
||||
|
||||
fn main() {
|
||||
tauri_plugin::Builder::new(COMMANDS)
|
||||
.global_api_script_path("./api-iife.js")
|
||||
.build();
|
||||
}
|
||||
140
plugins/positioner/guest-js/index.ts
Normal file
140
plugins/positioner/guest-js/index.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
// Copyright 2021 Jonas Kruckenberg
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/**
|
||||
* Move the window to well-known positions, including positions relative to the tray icon.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import type { TrayIconEvent } from '@tauri-apps/api/tray'
|
||||
|
||||
/**
|
||||
* Well known window positions.
|
||||
*/
|
||||
export enum Position {
|
||||
/** Top left corner of the screen. */
|
||||
TopLeft = 0,
|
||||
/** Top right corner of the screen. */
|
||||
TopRight,
|
||||
/** Bottom left corner of the screen. */
|
||||
BottomLeft,
|
||||
/** Bottom right corner of the screen. */
|
||||
BottomRight,
|
||||
/** Top center of the screen. */
|
||||
TopCenter,
|
||||
/** Bottom center of the screen. */
|
||||
BottomCenter,
|
||||
/** Vertically centered on the left edge of the screen. */
|
||||
LeftCenter,
|
||||
/** Vertically centered on the right edge of the screen. */
|
||||
RightCenter,
|
||||
/** Center of the screen. */
|
||||
Center,
|
||||
/**
|
||||
* Above the tray icon, aligned with its left edge. Requires the `tray-icon` feature and the
|
||||
* tray icon's events to be forwarded through {@link handleIconState}.
|
||||
*/
|
||||
TrayLeft,
|
||||
/**
|
||||
* Directly below the tray icon, aligned with its left edge. Requires the `tray-icon` feature
|
||||
* and the tray icon's events to be forwarded through {@link handleIconState}.
|
||||
*/
|
||||
TrayBottomLeft,
|
||||
/**
|
||||
* Above the tray icon, aligned with its right edge. Requires the `tray-icon` feature and the
|
||||
* tray icon's events to be forwarded through {@link handleIconState}.
|
||||
*/
|
||||
TrayRight,
|
||||
/**
|
||||
* Directly below the tray icon, aligned with its right edge. Requires the `tray-icon` feature
|
||||
* and the tray icon's events to be forwarded through {@link handleIconState}.
|
||||
*/
|
||||
TrayBottomRight,
|
||||
/**
|
||||
* Above the tray icon, horizontally centered on it. Requires the `tray-icon` feature and the
|
||||
* tray icon's events to be forwarded through {@link handleIconState}.
|
||||
*/
|
||||
TrayCenter,
|
||||
/**
|
||||
* Directly below the tray icon, horizontally centered on it. Requires the `tray-icon` feature
|
||||
* and the tray icon's events to be forwarded through {@link handleIconState}.
|
||||
*/
|
||||
TrayBottomCenter
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the `Window` to the given {@link Position} using `WindowExt.move_window()`
|
||||
* All positions are relative to the **current** screen.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { moveWindow, Position } from '@tauri-apps/plugin-positioner'
|
||||
*
|
||||
* await moveWindow(Position.TopRight)
|
||||
* ```
|
||||
*
|
||||
* @param to The {@link Position} to move to.
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export async function moveWindow(to: Position): Promise<void> {
|
||||
await invoke('plugin:positioner|move_window', {
|
||||
position: to
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the `Window` to the given {@link Position} using `WindowExt.move_window_constrained()`
|
||||
*
|
||||
* This move operation constrains the window to the screen dimensions in case of
|
||||
* tray-icon positions.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { moveWindowConstrained, Position } from '@tauri-apps/plugin-positioner'
|
||||
*
|
||||
* await moveWindowConstrained(Position.TrayCenter)
|
||||
* ```
|
||||
*
|
||||
* @param to The (tray) {@link Position} to move to.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
export async function moveWindowConstrained(to: Position): Promise<void> {
|
||||
await invoke('plugin:positioner|move_window_constrained', {
|
||||
position: to
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports the tray icon's current position and size so the `Tray*` {@link Position} variants
|
||||
* can be resolved.
|
||||
*
|
||||
* This is an internal helper meant to be called from the tray icon's event handler (the
|
||||
* `action` callback passed to `TrayIcon.new()`), forwarding every {@link TrayIconEvent} it
|
||||
* receives so that {@link moveWindow} and {@link moveWindowConstrained} can later position the
|
||||
* window relative to the tray icon.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { handleIconState } from '@tauri-apps/plugin-positioner'
|
||||
* import { TrayIcon, type TrayIconEvent } from '@tauri-apps/api/tray'
|
||||
*
|
||||
* const action = async (event: TrayIconEvent) => {
|
||||
* await handleIconState(event)
|
||||
* }
|
||||
*
|
||||
* const tray = await TrayIcon.new({ id: 'main', action })
|
||||
* ```
|
||||
*
|
||||
* @param event The tray icon event to read the position and size from.
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export async function handleIconState(event: TrayIconEvent): Promise<void> {
|
||||
await invoke('plugin:positioner|set_tray_icon_state', {
|
||||
position: event.rect.position,
|
||||
size: event.rect.size
|
||||
})
|
||||
}
|
||||
30
plugins/positioner/package.json
Normal file
30
plugins/positioner/package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "@tauri-apps/plugin-positioner",
|
||||
"version": "2.3.4",
|
||||
"description": "Position your windows at well-known locations.",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"authors": [
|
||||
"Tauri Programme within The Commons Conservancy"
|
||||
],
|
||||
"repository": "https://github.com/tauri-apps/plugins-workspace",
|
||||
"type": "module",
|
||||
"types": "./dist-js/index.d.ts",
|
||||
"main": "./dist-js/index.cjs",
|
||||
"module": "./dist-js/index.js",
|
||||
"exports": {
|
||||
"types": "./dist-js/index.d.ts",
|
||||
"import": "./dist-js/index.js",
|
||||
"require": "./dist-js/index.cjs"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c"
|
||||
},
|
||||
"files": [
|
||||
"dist-js",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.11.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
# Automatically generated - DO NOT EDIT!
|
||||
|
||||
"$schema" = "../../schemas/schema.json"
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-move-window"
|
||||
description = "Enables the move_window command without any pre-configured scope."
|
||||
commands.allow = ["move_window"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "deny-move-window"
|
||||
description = "Denies the move_window command without any pre-configured scope."
|
||||
commands.deny = ["move_window"]
|
||||
@@ -0,0 +1,13 @@
|
||||
# Automatically generated - DO NOT EDIT!
|
||||
|
||||
"$schema" = "../../schemas/schema.json"
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-move-window-constrained"
|
||||
description = "Enables the move_window_constrained command without any pre-configured scope."
|
||||
commands.allow = ["move_window_constrained"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "deny-move-window-constrained"
|
||||
description = "Denies the move_window_constrained command without any pre-configured scope."
|
||||
commands.deny = ["move_window_constrained"]
|
||||
@@ -0,0 +1,13 @@
|
||||
# Automatically generated - DO NOT EDIT!
|
||||
|
||||
"$schema" = "../../schemas/schema.json"
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-set-tray-icon-state"
|
||||
description = "Enables the set_tray_icon_state command without any pre-configured scope."
|
||||
commands.allow = ["set_tray_icon_state"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "deny-set-tray-icon-state"
|
||||
description = "Denies the set_tray_icon_state command without any pre-configured scope."
|
||||
commands.deny = ["set_tray_icon_state"]
|
||||
97
plugins/positioner/permissions/autogenerated/reference.md
Normal file
97
plugins/positioner/permissions/autogenerated/reference.md
Normal file
@@ -0,0 +1,97 @@
|
||||
## Default Permission
|
||||
|
||||
Allows the moveWindow and handleIconState APIs
|
||||
|
||||
#### This default permission set includes the following:
|
||||
|
||||
- `allow-move-window`
|
||||
- `allow-move-window-constrained`
|
||||
- `allow-set-tray-icon-state`
|
||||
|
||||
## Permission Table
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Identifier</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`positioner:allow-move-window`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Enables the move_window command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`positioner:deny-move-window`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Denies the move_window command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`positioner:allow-move-window-constrained`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Enables the move_window_constrained command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`positioner:deny-move-window-constrained`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Denies the move_window_constrained command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`positioner:allow-set-tray-icon-state`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Enables the set_tray_icon_state command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`positioner:deny-set-tray-icon-state`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Denies the set_tray_icon_state command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
8
plugins/positioner/permissions/default.toml
Normal file
8
plugins/positioner/permissions/default.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
"$schema" = "schemas/schema.json"
|
||||
[default]
|
||||
description = "Allows the moveWindow and handleIconState APIs"
|
||||
permissions = [
|
||||
"allow-move-window",
|
||||
"allow-move-window-constrained",
|
||||
"allow-set-tray-icon-state",
|
||||
]
|
||||
342
plugins/positioner/permissions/schemas/schema.json
Normal file
342
plugins/positioner/permissions/schemas/schema.json
Normal file
@@ -0,0 +1,342 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "PermissionFile",
|
||||
"description": "Permission file that can define a default permission, a set of permissions or a list of inlined permissions.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"default": {
|
||||
"description": "The default permission set for the plugin",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DefaultPermission"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"set": {
|
||||
"description": "A list of permissions sets defined",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/PermissionSet"
|
||||
}
|
||||
},
|
||||
"permission": {
|
||||
"description": "A list of inlined permissions",
|
||||
"default": [],
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Permission"
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"DefaultPermission": {
|
||||
"description": "The default permission set of the plugin.\n\nWorks similarly to a permission with the \"default\" identifier.",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"permissions"
|
||||
],
|
||||
"properties": {
|
||||
"version": {
|
||||
"description": "The version of the permission.",
|
||||
"type": [
|
||||
"integer",
|
||||
"null"
|
||||
],
|
||||
"format": "uint64",
|
||||
"minimum": 1.0
|
||||
},
|
||||
"description": {
|
||||
"description": "Human-readable description of what the permission does. Tauri convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"permissions": {
|
||||
"description": "All permissions this set contains.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"PermissionSet": {
|
||||
"description": "A set of direct permissions grouped together under a new name.",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"description",
|
||||
"identifier",
|
||||
"permissions"
|
||||
],
|
||||
"properties": {
|
||||
"identifier": {
|
||||
"description": "A unique identifier for the permission.",
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"description": "Human-readable description of what the permission does.",
|
||||
"type": "string"
|
||||
},
|
||||
"permissions": {
|
||||
"description": "All permissions this set contains.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/PermissionKind"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Permission": {
|
||||
"description": "Descriptions of explicit privileges of commands.\n\nIt can enable commands to be accessible in the frontend of the application.\n\nIf the scope is defined it can be used to fine grain control the access of individual or multiple commands.",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"identifier"
|
||||
],
|
||||
"properties": {
|
||||
"version": {
|
||||
"description": "The version of the permission.",
|
||||
"type": [
|
||||
"integer",
|
||||
"null"
|
||||
],
|
||||
"format": "uint64",
|
||||
"minimum": 1.0
|
||||
},
|
||||
"identifier": {
|
||||
"description": "A unique identifier for the permission.",
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"description": "Human-readable description of what the permission does. Tauri internal convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"commands": {
|
||||
"description": "Allowed or denied commands when using this permission.",
|
||||
"default": {
|
||||
"allow": [],
|
||||
"deny": []
|
||||
},
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Commands"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scope": {
|
||||
"description": "Allowed or denied scoped when using this permission.",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Scopes"
|
||||
}
|
||||
]
|
||||
},
|
||||
"platforms": {
|
||||
"description": "Target platforms this permission applies. By default all platforms are affected by this permission.",
|
||||
"type": [
|
||||
"array",
|
||||
"null"
|
||||
],
|
||||
"items": {
|
||||
"$ref": "#/definitions/Target"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Commands": {
|
||||
"description": "Allowed and denied commands inside a permission.\n\nIf two commands clash inside of `allow` and `deny`, it should be denied by default.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"allow": {
|
||||
"description": "Allowed command.",
|
||||
"default": [],
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"deny": {
|
||||
"description": "Denied command, which takes priority.",
|
||||
"default": [],
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Scopes": {
|
||||
"description": "An argument for fine grained behavior control of Tauri commands.\n\nIt can be of any serde serializable type and is used to allow or prevent certain actions inside a Tauri command. The configured scope is passed to the command and will be enforced by the command implementation.\n\n## Example\n\n```json { \"allow\": [{ \"path\": \"$HOME/**\" }], \"deny\": [{ \"path\": \"$HOME/secret.txt\" }] } ```",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"allow": {
|
||||
"description": "Data that defines what is allowed by the scope.",
|
||||
"type": [
|
||||
"array",
|
||||
"null"
|
||||
],
|
||||
"items": {
|
||||
"$ref": "#/definitions/Value"
|
||||
}
|
||||
},
|
||||
"deny": {
|
||||
"description": "Data that defines what is denied by the scope. This should be prioritized by validation logic.",
|
||||
"type": [
|
||||
"array",
|
||||
"null"
|
||||
],
|
||||
"items": {
|
||||
"$ref": "#/definitions/Value"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Value": {
|
||||
"description": "All supported ACL values.",
|
||||
"anyOf": [
|
||||
{
|
||||
"description": "Represents a null JSON value.",
|
||||
"type": "null"
|
||||
},
|
||||
{
|
||||
"description": "Represents a [`bool`].",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"description": "Represents a valid ACL [`Number`].",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Number"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Represents a [`String`].",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"description": "Represents a list of other [`Value`]s.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Value"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Represents a map of [`String`] keys to [`Value`]s.",
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/Value"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"Number": {
|
||||
"description": "A valid ACL number.",
|
||||
"anyOf": [
|
||||
{
|
||||
"description": "Represents an [`i64`].",
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
{
|
||||
"description": "Represents a [`f64`].",
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
}
|
||||
]
|
||||
},
|
||||
"Target": {
|
||||
"description": "Platform target.",
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "MacOS.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"macOS"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Windows.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"windows"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Linux.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"linux"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Android.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"android"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "iOS.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"iOS"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"PermissionKind": {
|
||||
"type": "string",
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "Enables the move_window command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "allow-move-window",
|
||||
"markdownDescription": "Enables the move_window command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Denies the move_window command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "deny-move-window",
|
||||
"markdownDescription": "Denies the move_window command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Enables the move_window_constrained command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "allow-move-window-constrained",
|
||||
"markdownDescription": "Enables the move_window_constrained command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Denies the move_window_constrained command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "deny-move-window-constrained",
|
||||
"markdownDescription": "Denies the move_window_constrained command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Enables the set_tray_icon_state command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "allow-set-tray-icon-state",
|
||||
"markdownDescription": "Enables the set_tray_icon_state command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Denies the set_tray_icon_state command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "deny-set-tray-icon-state",
|
||||
"markdownDescription": "Denies the set_tray_icon_state command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Allows the moveWindow and handleIconState APIs\n#### This default permission set includes:\n\n- `allow-move-window`\n- `allow-move-window-constrained`\n- `allow-set-tray-icon-state`",
|
||||
"type": "string",
|
||||
"const": "default",
|
||||
"markdownDescription": "Allows the moveWindow and handleIconState APIs\n#### This default permission set includes:\n\n- `allow-move-window`\n- `allow-move-window-constrained`\n- `allow-set-tray-icon-state`"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
7
plugins/positioner/rollup.config.js
Normal file
7
plugins/positioner/rollup.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { createConfig } from '../../shared/rollup.config.js'
|
||||
|
||||
export default createConfig()
|
||||
346
plugins/positioner/src/ext.rs
Normal file
346
plugins/positioner/src/ext.rs
Normal file
@@ -0,0 +1,346 @@
|
||||
// Copyright 2021 Jonas Kruckenberg
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#[cfg(feature = "tray-icon")]
|
||||
use crate::Tray;
|
||||
use serde_repr::Deserialize_repr;
|
||||
#[cfg(feature = "tray-icon")]
|
||||
use tauri::Manager;
|
||||
#[cfg(feature = "tray-icon")]
|
||||
use tauri::Monitor;
|
||||
use tauri::{PhysicalPosition, PhysicalSize, Result, Runtime, WebviewWindow, Window};
|
||||
|
||||
/// Well known window positions.
|
||||
///
|
||||
/// The `Tray*` variants require the `tray-icon` feature and only resolve once the tray icon has
|
||||
/// reported its position (see `on_tray_event`); using one before that happens returns an error.
|
||||
#[derive(Debug, Deserialize_repr)]
|
||||
#[repr(u16)]
|
||||
pub enum Position {
|
||||
/// Top left corner of the current screen.
|
||||
TopLeft = 0,
|
||||
/// Top right corner of the current screen.
|
||||
TopRight,
|
||||
/// Bottom left corner of the current screen.
|
||||
BottomLeft,
|
||||
/// Bottom right corner of the current screen.
|
||||
BottomRight,
|
||||
/// Top center of the current screen.
|
||||
TopCenter,
|
||||
/// Bottom center of the current screen.
|
||||
BottomCenter,
|
||||
/// Vertically centered on the left edge of the current screen.
|
||||
LeftCenter,
|
||||
/// Vertically centered on the right edge of the current screen.
|
||||
RightCenter,
|
||||
/// Center of the current screen.
|
||||
Center,
|
||||
/// Above the tray icon, aligning the window's left edge with the tray icon's left edge. On
|
||||
/// Windows and macOS the window moves below the icon instead when there is not enough room
|
||||
/// above.
|
||||
#[cfg(feature = "tray-icon")]
|
||||
TrayLeft,
|
||||
/// Directly below the tray icon, aligning the window's left edge with the tray icon's left
|
||||
/// edge.
|
||||
#[cfg(feature = "tray-icon")]
|
||||
TrayBottomLeft,
|
||||
/// Above the tray icon, aligning the window's left edge with the tray icon's right edge. On
|
||||
/// Windows and macOS the window moves below the icon instead when there is not enough room
|
||||
/// above.
|
||||
#[cfg(feature = "tray-icon")]
|
||||
TrayRight,
|
||||
/// Directly below the tray icon, aligning the window's left edge with the tray icon's right
|
||||
/// edge.
|
||||
#[cfg(feature = "tray-icon")]
|
||||
TrayBottomRight,
|
||||
/// Above the tray icon, horizontally centered on it. On Windows and macOS the window moves
|
||||
/// below the icon instead when there is not enough room above.
|
||||
#[cfg(feature = "tray-icon")]
|
||||
TrayCenter,
|
||||
/// Directly below the tray icon, horizontally centered on it.
|
||||
#[cfg(feature = "tray-icon")]
|
||||
TrayBottomCenter,
|
||||
}
|
||||
|
||||
/// A [`Window`] extension that provides extra methods related to positioning.
|
||||
pub trait WindowExt {
|
||||
/// Moves the [`Window`] to the given [`Position`]
|
||||
///
|
||||
/// All (non-tray) positions are relative to the **current** screen.
|
||||
fn move_window(&self, position: Position) -> Result<()>;
|
||||
#[cfg(feature = "tray-icon")]
|
||||
/// Moves the [`Window`] to the given [`Position`] while constraining Tray Positions to the dimensions of the screen.
|
||||
///
|
||||
/// All non-tray positions will not be constrained by this method.
|
||||
///
|
||||
/// This method allows you to position your Tray Windows without having them
|
||||
/// cut off on the screen borders.
|
||||
fn move_window_constrained(&self, position: Position) -> Result<()>;
|
||||
}
|
||||
|
||||
impl<R: Runtime> WindowExt for WebviewWindow<R> {
|
||||
fn move_window(&self, pos: Position) -> Result<()> {
|
||||
self.as_ref().window().move_window(pos)
|
||||
}
|
||||
|
||||
#[cfg(feature = "tray-icon")]
|
||||
fn move_window_constrained(&self, position: Position) -> Result<()> {
|
||||
self.as_ref().window().move_window_constrained(position)
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Runtime> WindowExt for Window<R> {
|
||||
#[cfg(feature = "tray-icon")]
|
||||
fn move_window_constrained(&self, position: Position) -> Result<()> {
|
||||
// Diverge to basic move_window, if the position is not a tray position
|
||||
if !matches!(
|
||||
position,
|
||||
Position::TrayLeft
|
||||
| Position::TrayBottomLeft
|
||||
| Position::TrayRight
|
||||
| Position::TrayBottomRight
|
||||
| Position::TrayCenter
|
||||
| Position::TrayBottomCenter
|
||||
) {
|
||||
return self.move_window(position);
|
||||
}
|
||||
|
||||
let window_position = calculate_position(self, position)?;
|
||||
let monitor = get_monitor_for_tray_icon(self)?;
|
||||
if let Some(monitor) = monitor {
|
||||
let monitor_size = monitor.size();
|
||||
let monitor_position = monitor.position();
|
||||
let window_size = self.outer_size()?;
|
||||
|
||||
let right_border_monitor = monitor_position.x as f64 + monitor_size.width as f64;
|
||||
let left_border_monitor = monitor_position.x as f64;
|
||||
let right_border_window = window_position.x as f64 + window_size.width as f64;
|
||||
let left_border_window = window_position.x as f64;
|
||||
|
||||
let constrained_x = if left_border_window < left_border_monitor {
|
||||
left_border_monitor
|
||||
} else if right_border_window > right_border_monitor {
|
||||
right_border_monitor - window_size.width as f64
|
||||
} else {
|
||||
window_position.x as f64
|
||||
};
|
||||
|
||||
let bottom_border_monitor = monitor_position.y as f64 + monitor_size.height as f64;
|
||||
let top_border_monitor = monitor_position.y as f64;
|
||||
let bottom_border_window = window_position.y as f64 + window_size.height as f64;
|
||||
let top_border_window = window_position.y as f64;
|
||||
|
||||
let constrained_y = if top_border_window < top_border_monitor {
|
||||
top_border_monitor
|
||||
} else if bottom_border_window > bottom_border_monitor {
|
||||
bottom_border_monitor - window_size.height as f64
|
||||
} else {
|
||||
window_position.y as f64
|
||||
};
|
||||
|
||||
self.set_position(PhysicalPosition::new(constrained_x, constrained_y))?;
|
||||
} else {
|
||||
// Fallback on non constrained positioning
|
||||
self.set_position(window_position)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn move_window(&self, pos: Position) -> Result<()> {
|
||||
let position = calculate_position(self, pos)?;
|
||||
self.set_position(position)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tray-icon")]
|
||||
/// Retrieve the monitor, where the tray icon is located on.
|
||||
fn get_monitor_for_tray_icon<R: Runtime>(window: &Window<R>) -> Result<Option<Monitor>> {
|
||||
let tray_position = window
|
||||
.state::<Tray>()
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.map(|(pos, _)| pos)
|
||||
.unwrap_or_default();
|
||||
|
||||
window.monitor_from_point(tray_position.x, tray_position.y)
|
||||
}
|
||||
|
||||
/// Calculate the top-left position of the window based on the given
|
||||
/// [`Position`].
|
||||
fn calculate_position<R: Runtime>(
|
||||
window: &Window<R>,
|
||||
pos: Position,
|
||||
) -> Result<PhysicalPosition<i32>> {
|
||||
use Position::*;
|
||||
|
||||
let screen = window.current_monitor()?.ok_or_else(|| {
|
||||
tauri::Error::Io(std::io::Error::other("No monitor found for the window"))
|
||||
})?;
|
||||
// Only use the screen_position for the Tray independent positioning,
|
||||
// because a tray event may not be called on the currently active monitor.
|
||||
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: window.outer_size()?.width as i32,
|
||||
height: window.outer_size()?.height as i32,
|
||||
};
|
||||
#[cfg(feature = "tray-icon")]
|
||||
let (tray_position, tray_size) = window
|
||||
.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 = "tray-icon")]
|
||||
TrayLeft => {
|
||||
if let (Some((tray_x, tray_y)), Some((_, _tray_height))) = (tray_position, tray_size) {
|
||||
let y = tray_y - window_size.height;
|
||||
// Choose y value based on the target OS
|
||||
#[cfg(target_os = "windows")]
|
||||
let y = if y < 0 { tray_y + _tray_height } else { y };
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let y = if y < 0 { tray_y } else { y };
|
||||
|
||||
PhysicalPosition { x: tray_x, y }
|
||||
} else {
|
||||
return Err(tauri::Error::Io(std::io::Error::other(
|
||||
"Tray position not set",
|
||||
)));
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "tray-icon")]
|
||||
TrayBottomLeft => {
|
||||
if let Some((tray_x, tray_y)) = tray_position {
|
||||
PhysicalPosition {
|
||||
x: tray_x,
|
||||
y: tray_y,
|
||||
}
|
||||
} else {
|
||||
return Err(tauri::Error::Io(std::io::Error::other(
|
||||
"Tray position not set",
|
||||
)));
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "tray-icon")]
|
||||
TrayRight => {
|
||||
if let (Some((tray_x, tray_y)), Some((tray_width, _tray_height))) =
|
||||
(tray_position, tray_size)
|
||||
{
|
||||
let y = tray_y - window_size.height;
|
||||
// Choose y value based on the target OS
|
||||
#[cfg(target_os = "windows")]
|
||||
let y = if y < 0 { tray_y + _tray_height } else { y };
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let y = if y < 0 { tray_y } else { y };
|
||||
|
||||
PhysicalPosition {
|
||||
x: tray_x + tray_width,
|
||||
y,
|
||||
}
|
||||
} else {
|
||||
return Err(tauri::Error::Io(std::io::Error::other(
|
||||
"Tray position not set",
|
||||
)));
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "tray-icon")]
|
||||
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 {
|
||||
return Err(tauri::Error::Io(std::io::Error::other(
|
||||
"Tray position not set",
|
||||
)));
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "tray-icon")]
|
||||
TrayCenter => {
|
||||
if let (Some((tray_x, tray_y)), Some((tray_width, _tray_height))) =
|
||||
(tray_position, tray_size)
|
||||
{
|
||||
let x = tray_x + tray_width / 2 - window_size.width / 2;
|
||||
let y = tray_y - window_size.height;
|
||||
// Choose y value based on the target OS
|
||||
#[cfg(target_os = "windows")]
|
||||
let y = if y < 0 { tray_y + _tray_height } else { y };
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let y = if y < 0 { tray_y } else { y };
|
||||
|
||||
PhysicalPosition { x, y }
|
||||
} else {
|
||||
return Err(tauri::Error::Io(std::io::Error::other(
|
||||
"Tray position not set",
|
||||
)));
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "tray-icon")]
|
||||
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 {
|
||||
return Err(tauri::Error::Io(std::io::Error::other(
|
||||
"Tray position not set",
|
||||
)));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(physical_pos)
|
||||
}
|
||||
114
plugins/positioner/src/lib.rs
Normal file
114
plugins/positioner/src/lib.rs
Normal file
@@ -0,0 +1,114 @@
|
||||
// Copyright 2021 Jonas Kruckenberg
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//! A plugin for Tauri that helps position your windows at well-known locations.
|
||||
//!
|
||||
//! ## Cargo features
|
||||
//!
|
||||
//! - **tray-icon**: Enables tray-icon-relative positions.
|
||||
//!
|
||||
//! Note: This requires attaching the Tauri plugin, *even* when using the trait extension only.
|
||||
|
||||
#![doc(
|
||||
html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
|
||||
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
|
||||
)]
|
||||
#![cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
|
||||
mod ext;
|
||||
|
||||
pub use ext::*;
|
||||
use tauri::{
|
||||
plugin::{self, TauriPlugin},
|
||||
Result, Runtime,
|
||||
};
|
||||
|
||||
#[cfg(feature = "tray-icon")]
|
||||
use tauri::{tray::TrayIconEvent, AppHandle, Manager, PhysicalPosition, PhysicalSize};
|
||||
|
||||
#[cfg(feature = "tray-icon")]
|
||||
struct Tray(std::sync::Mutex<Option<(PhysicalPosition<f64>, PhysicalSize<f64>)>>);
|
||||
|
||||
/// Records the tray icon's latest position and size so that the `Tray*` [`Position`] variants
|
||||
/// (e.g. [`Position::TrayLeft`]) can be resolved by [`WindowExt::move_window`] and
|
||||
/// [`WindowExt::move_window_constrained`].
|
||||
///
|
||||
/// Call this from your tray icon's event handler. Only [`TrayIconEvent::Click`],
|
||||
/// [`TrayIconEvent::Enter`], [`TrayIconEvent::Leave`] and [`TrayIconEvent::Move`] carry the
|
||||
/// icon's position and update the tracked value; other events are ignored. Until this has been
|
||||
/// called at least once, moving a window to a `Tray*` position fails.
|
||||
///
|
||||
/// Requires the `tray-icon` feature.
|
||||
#[cfg(feature = "tray-icon")]
|
||||
pub fn on_tray_event<R: Runtime>(app: &AppHandle<R>, event: &TrayIconEvent) {
|
||||
let (position, size) = {
|
||||
match event {
|
||||
TrayIconEvent::Click { rect, .. }
|
||||
| TrayIconEvent::Enter { rect, .. }
|
||||
| TrayIconEvent::Leave { rect, .. }
|
||||
| TrayIconEvent::Move { rect, .. } => {
|
||||
// tray-icon emits PhysicalSize so the scale factor should not matter.
|
||||
let size = rect.size.to_physical(1.0);
|
||||
let position = rect.position.to_physical(1.0);
|
||||
(position, size)
|
||||
}
|
||||
|
||||
_ => return,
|
||||
}
|
||||
};
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
#[cfg(feature = "tray-icon")]
|
||||
#[tauri::command]
|
||||
async fn move_window_constrained<R: Runtime>(
|
||||
window: tauri::Window<R>,
|
||||
position: Position,
|
||||
) -> Result<()> {
|
||||
window.move_window_constrained(position)
|
||||
}
|
||||
|
||||
#[cfg(feature = "tray-icon")]
|
||||
#[tauri::command]
|
||||
fn set_tray_icon_state<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
position: PhysicalPosition<f64>,
|
||||
size: PhysicalSize<f64>,
|
||||
) {
|
||||
app.state::<Tray>()
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.replace((position, size));
|
||||
}
|
||||
|
||||
/// 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 = "tray-icon")]
|
||||
move_window_constrained,
|
||||
#[cfg(feature = "tray-icon")]
|
||||
set_tray_icon_state
|
||||
]);
|
||||
|
||||
#[cfg(feature = "tray-icon")]
|
||||
let plugin = plugin.setup(|app_handle, _api| {
|
||||
app_handle.manage(Tray(std::sync::Mutex::new(None)));
|
||||
Ok(())
|
||||
});
|
||||
|
||||
plugin.build()
|
||||
}
|
||||
7
plugins/positioner/tsconfig.json
Normal file
7
plugins/positioner/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "guest-js"
|
||||
},
|
||||
"include": ["guest-js/*.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user