-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MNT/FEAT migrate to Tauri v2 & stay-on-bottom + click-through #49
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Charlie-XIAO
changed the title
MAINT migrate to Tauri v2
MNT/FEAT migrate to Tauri v2 & stay-on-bottom + click-through
Apr 28, 2024
Xinyu-Li-123
approved these changes
Apr 29, 2024
Merging on CI green. This is a blocking PR, and none of the remaining issues listed in the top comment can be solved immediately, so we shall leave them to later PRs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #39.
Closes #43 (superceded), thanks @Xinyu-Li-123.
This PR bumps Tauri to v2. Run
npm run setup
to install the beta versions of dependencies and build for tooling. On Linux, additionally update tolibwebkit2gtk-4.1-dev
.Reworking inlined plugins
Inlined plugins are only recently supported in v2 (due to the permission system) and do not have documentations yet; the only reference available is tauri-apps/tauri#8781. It seems that there are constraints that the only acceptable separator is
-
. To keep the namespace-like naming for our widget APIs, I decided to useapis-${module}
to replace the originalwidget_api|${module}
.To extend widget APIs in the future, one need to go through the following steps:
src-tauri/src/apis/${module}/
, wheremod.rs
defines aninit
function to build the plugin andapis.rs
implements the actual commands. Other utility files are optional.tooling/apis/src/${module}.ts
that defines the frontend invokers of the commands.src-tauri/build.rs
, addconst WIDGET_APIS_${MODULE}_COMMANDS: &[&str] = &[...]
, then call an additional.plugin("apis-${module}", InlinedPlugin::new().commands(WIDGET_APIS_${MODULE}_COMMANDS))
on the build attributes.src-tauri/permissions/apis-${module}/default.toml
and include adefault
preset that allows all commands. Refer to the existingfs
module if confused. Note that the underscores in commands should be changed to hyphens, e.g., a commandhello_world
should correspond toallow-hello-world
in the permissions.src-tauri/capabilities/canvas.json
, and addapis-${module}:default
topermissions
.Reworking internal commands
With the changes above to support inlined plugins, internal commands seem to lose their permissions which should have been granted by default. To work around, one need to go through the following steps to create a new internal command:
src-tauri/src/commands.rs
. Make sure to place only commands in this file and separate utility functions elsewhere.src-tauri/src/main.rs
and add the command name ingenerate_handler!
.src-tauri/build.rs
and add the command name inINTERNAL_COMMANDS
. This should automatically generate the corresponding permission filesrc-tauri/permissions/autogenerated/${cmd}.toml
becauseINTERNAL_COMMANDS
are set in the application permission manifest. Consequently we are usingtauri_build_context
instead ofgenerate_context
now.src-tauri/capabilities/
, find the correct ACL configuration file and addallow-${xxx}
topermissions
, wherexxx
iscmd
with underlines converted to hyphens, as mentioned above.Feature: always on bottom
This is the main reason why we migrated to Tauri v2.
always_on_bottom
is easy to implement for Linux and macOS with some platform-specific code, but for Windows this is hard because it does not provide an intrinsic API and have to interact with the lifecycle which we do not have full control of. In particular, the following is a working implementation:Implementation
The problem is that it can break other important properties of the canvas because of interfering with TAO implementations, unless we implement everything directly with Windows API which is clearly infeasible.
Back to the topic, we currently implement the switch between click-through (can interact with desktop but cannot interact with widgets) and non-click-through (can interact with widgets but cannot interact with desktop). The toggling can be achieved in the following ways:
Ctrl/Cmd + Shift + H
. We many support shortcut customization in the future, in case people need this shortcut for other usages.Remaining issues
always_on_bottom
fails to set window to bottom when created on Windows tauri-apps/tauri#9597400 bad request
message that does not seem to affect logic.