Skip to content
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

feat: add tray and menu javascript APIs and events, closes #6617 #7709

Merged
merged 70 commits into from
Nov 19, 2023

Conversation

amrbashir
Copy link
Member

@amrbashir amrbashir commented Aug 29, 2023

closes #6617

TODOs:

  • JS docs

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

@amrbashir amrbashir requested a review from a team as a code owner August 29, 2023 14:33
@socket-security
Copy link

socket-security bot commented Aug 29, 2023

Updated and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@iconify-json/codicon 1.1.10...1.1.28 None +1/-0 246 kB cyberalien
@iconify-json/ph 1.1.1...1.1.6 None +1/-0 3.75 MB cyberalien
@tauri-apps/api 2.0.0-alpha.8...2.0.0-alpha.9 None +0/-0 227 kB tauri-apps-ci-user

🚮 Removed packages: [email protected]

@amrbashir
Copy link
Member Author

Now that the implementation is done without depending on the window plugin, I still believe the window plugin (plus some others) should be added back to core, also notice that the tray plugin is dependent on the menu plugin so both will need to be in coupled together.

Also the menu plugin ideally should use the Window and Position types from the window plugin and the window plugin should depend on the menu plugin so that we can provide a window config option to use a specific menu when creating the window.

All this could be solved by just adding them all into one single package in core. These are essential to any tauri app and so should be provided by default in core.

core/tauri-macros/src/lib.rs Outdated Show resolved Hide resolved
core/tauri-macros/src/lib.rs Outdated Show resolved Hide resolved
core/tauri-macros/src/lib.rs Outdated Show resolved Hide resolved
core/tauri-macros/src/lib.rs Outdated Show resolved Hide resolved
core/tauri-macros/src/menu.rs Outdated Show resolved Hide resolved
core/tauri/src/resources/mod.rs Outdated Show resolved Hide resolved
use super::ResourceId;

#[command(root = "crate")]
fn close<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> crate::Result<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is problematic, an attacker can close all resources by iterating on IDs until an error is returned.

maybe we should make the ID random instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing resource is not that bad right?

Also for reference, deno is using the same ID strategy and though they also provide .close() you can't really invoke the underlying mechanism of it (compared to invoke("plugin:resources|close").

So in order to simplify the implementation and keep using incrementing ID numbers, we can hide the invoke endpoint and randomize it on each launch of the app.

core/tauri/src/menu/plugin.rs Show resolved Hide resolved
core/tauri/src/tray/plugin.rs Outdated Show resolved Hide resolved
core/tauri/src/menu/plugin.rs Outdated Show resolved Hide resolved
amrbashir and others added 6 commits October 11, 2023 22:43
Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
lucasfernog and others added 17 commits October 29, 2023 08:55
allows something like:
```javascript
await Menu.new({
  items: [
    { item: 'Copy' },
    { text: 'Something', action: () => console.log('something clicked') },
    {
      id: 'x',
      icon: '/home/lucas/projects/tauri/tauri/examples/.icons/32x32.png',
      text: 'Tauris',
      action: () => console.log('tauri clicked')
    },
    {
      checked: true,
      text: 'chec',
      action: () => console.log('chec clicked')
    },
    {
      text: 'Sub',
      items: [
        {
          item: 'Paste'
        },
        { text: 'subsubsub', action: () => console.log('sub clicked') }
      ]
    }
  ]
})
```
@lucasfernog
Copy link
Member

We're missing a lot of documentation here, but I wanna merge it anyway because we need to do a complete pass on API examples.

I like how this can be dynamic with the MenuItem classes (so you can update, share items), or static with raw objects after d0eeaba

@lucasfernog lucasfernog merged commit f93148e into dev Nov 19, 2023
3 checks passed
@lucasfernog lucasfernog deleted the feat/tray-menu-js-apis branch November 19, 2023 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔎 In audit
Development

Successfully merging this pull request may close these issues.

[feat] JS window menu API
3 participants