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

Added a basic example of how to use webview with VTray to create a de… #28

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Ouri028
Copy link
Contributor

@Ouri028 Ouri028 commented Sep 26, 2023

Added a basic example of how to use webview with VTray to create a desktop app with a custom notification tray icon with menus.

…sktop app with a custom notification tray icon with menus.
@ttytm
Copy link
Owner

ttytm commented Sep 27, 2023

Thanks for the PR @Ouri028. Good joob with the lib. Since webview is a cross-platform library, I would like to wait until VTray supports at least two of the major OSes before adding it as example to the repo. Also, I'm currently not able to test Windows things as I'm only having a mac arm machine available where I cannot virtualise x64 architecture on and V is not running on windows arm.

@Ouri028
Copy link
Contributor Author

Ouri028 commented Sep 27, 2023

Thanks for the PR @Ouri028. Good joob with the lib. Since webview is a cross-platform library, I would like to wait until VTray supports at least two of the major OSes before adding it as example to the repo. Also, I'm currently not able to test Windows things as I'm only having a mac arm machine available where I cannot virtualise x64 architecture on and V is not running on windows arm.

Hey man,

That's fine, I just pushed a new version that supports Linux, I am currently working on the MacOS version (managed to secure myself a Mac :D), currently working off the example that was on the V repo to display the Mac tray, but will let you know as soon as MacOS is also supported.

Please keep in mind that the Linux version was only tested on Debian based images (Ubuntu, Lubuntu, etc), so no idea if it will work with all distros.

To be honest, I do not plan to support a large amount of distros as it can get a bit much.

@ttytm
Copy link
Owner

ttytm commented Sep 27, 2023

Nice to hear about the linux support. Covering the main desktop environments like Gnome and Plasma is totally sufficient imho. Extended support can come over time. Also good to hear about the mac situation 😁.

When I have a Windows device available for checking I'll add a review, so we can come to merge this. Thanks already!

@Ouri028
Copy link
Contributor Author

Ouri028 commented Sep 30, 2023

Added MacOS support for VTray.

I only tested it on macos ventura, since that's what I currently use.

image5

@ttytm
Copy link
Owner

ttytm commented Oct 1, 2023

Trying to run the example on macOS ventrua I'm encountering:

2023-10-01 20:14:13.888 app-with-systray[59082:3120931] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the 
Main Thread!'
*** First throw call stack:
(
        0   CoreFoundation                      0x000000019a05b154 __exceptionPreprocess + 176
        1   libobjc.A.dylib                     0x0000000199b7a4d4 objc_exception_throw + 60
        2   CoreFoundation                      0x000000019a0843a0 _CFBundleGetValueForInfoKey + 0
        3   AppKit                              0x000000019d22a638 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 320
        4   AppKit                              0x000000019d21890c -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 816
        5   AppKit                              0x000000019d2185d0 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 48
        6   AppKit                              0x000000019d89f69c -[NSStatusBarWindow initForStatusItem:] + 112
        7   AppKit                              0x000000019d8a2068 -[NSStatusItem _initWithStatusBar:length:priority:systemInsertOrder:] + 312
        8   AppKit                              0x000000019d426010 -[NSStatusBar _statusItemWithLength:withPriority:] + 64
        9   app-with-systray                    0x0000000104b39484 -[AppDelegate initTrayMenuItem] + 56
        10  app-with-systray                    0x0000000104b39694 vtray_init_mac + 128
        11  app-with-systray                    0x0000000104b638e8 vtray__VTrayApp_vtray_init + 268
        12  app-with-systray                    0x0000000104b650a4 main__create_tray + 344
        13  app-with-systray                    0x0000000104b39868 main__create_tray_thread_wrapper + 28
        14  app-with-systray                    0x0000000104b73910 GC_pthread_start + 104
        15  libsystem_pthread.dylib             0x0000000199f03fa8 _pthread_start + 148
        16  libsystem_pthread.dylib             0x0000000199efeda0 thread_start + 8
)
libc++abi: terminating due to uncaught exception of type NSException

@Ouri028
Copy link
Contributor Author

Ouri028 commented Oct 1, 2023

Trying to run the example on macOS ventrua I'm encountering:

2023-10-01 20:14:13.888 app-with-systray[59082:3120931] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the 
Main Thread!'
*** First throw call stack:
(
        0   CoreFoundation                      0x000000019a05b154 __exceptionPreprocess + 176
        1   libobjc.A.dylib                     0x0000000199b7a4d4 objc_exception_throw + 60
        2   CoreFoundation                      0x000000019a0843a0 _CFBundleGetValueForInfoKey + 0
        3   AppKit                              0x000000019d22a638 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 320
        4   AppKit                              0x000000019d21890c -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 816
        5   AppKit                              0x000000019d2185d0 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 48
        6   AppKit                              0x000000019d89f69c -[NSStatusBarWindow initForStatusItem:] + 112
        7   AppKit                              0x000000019d8a2068 -[NSStatusItem _initWithStatusBar:length:priority:systemInsertOrder:] + 312
        8   AppKit                              0x000000019d426010 -[NSStatusBar _statusItemWithLength:withPriority:] + 64
        9   app-with-systray                    0x0000000104b39484 -[AppDelegate initTrayMenuItem] + 56
        10  app-with-systray                    0x0000000104b39694 vtray_init_mac + 128
        11  app-with-systray                    0x0000000104b638e8 vtray__VTrayApp_vtray_init + 268
        12  app-with-systray                    0x0000000104b650a4 main__create_tray + 344
        13  app-with-systray                    0x0000000104b39868 main__create_tray_thread_wrapper + 28
        14  app-with-systray                    0x0000000104b73910 GC_pthread_start + 104
        15  libsystem_pthread.dylib             0x0000000199f03fa8 _pthread_start + 148
        16  libsystem_pthread.dylib             0x0000000199efeda0 thread_start + 8
)
libc++abi: terminating due to uncaught exception of type NSException

Hey man,

So, I had a look into this issue and it seems MacOS does not like running tray processes in other threads, but there is a fix for this, will post an update to the example a little later with the changes.

@Ouri028
Copy link
Contributor Author

Ouri028 commented Oct 1, 2023

Here is a screenshot of the working example.

image

@Ouri028
Copy link
Contributor Author

Ouri028 commented Oct 1, 2023

Updated the code example to include the fix for MacOS threading.

@ttytm
Copy link
Owner

ttytm commented Oct 1, 2023

Thanks for the update @Ouri028

Now it builds and runs! The things I'm noticing now:

  • The window has issues staying in the foreground unless it's directly clicked on else it will move back to the background, e.g., when it's clicked from mission control. Video example:

    vtray-mc.mp4

    It's probably a window hint that needs to be set for the NSApplication that vtray creates and handles.

  • The icon.png file is missing.

  • Now there are log messages whenever running a V app on macos which uses vtray, which probably shouldn't always be there. E.g.:

    2023-10-02 00:43:43.752 app-with-systray[91696:3401607] applicationWillFinishLaunching called
    2023-10-02 00:44:26.854 app-with-systray[91696:3401560] applicationShouldTerminate called
    2023-10-02 00:44:26.855 app-with-systray[91696:3401560] applicationWillTerminate called
    

Also updated example to switch between icons depending on OS.
@Ouri028
Copy link
Contributor Author

Ouri028 commented Oct 3, 2023

Thanks for the update @Ouri028

Now it builds and runs! The things I'm noticing now:

* The window has issues staying in the foreground unless it's directly clicked on else it will move back to the background, e.g., when it's clicked from mission control. Video example:
  
    
      
      
  
      vtray-mc.mp4
      
    
  
    
  
    
  
  
  It's probably a window hint that needs to be set for the NSApplication that vtray creates and handles.

* The `icon.png` file is missing.

* Now there are log messages whenever running a V app on macos which uses vtray, which probably shouldn't always be there. E.g.:
  ```
  2023-10-02 00:43:43.752 app-with-systray[91696:3401607] applicationWillFinishLaunching called
  2023-10-02 00:44:26.854 app-with-systray[91696:3401560] applicationShouldTerminate called
  2023-10-02 00:44:26.855 app-with-systray[91696:3401560] applicationWillTerminate called
  ```

Hey @ttytm ,

Thanks for the detailed issue, I have fixed them and pushed a new version of VTray and the example, please let me know if you encounter anything else. 😄

@ttytm
Copy link
Owner

ttytm commented May 16, 2024

PR is on hold:

[...] I will ask that you please put my PR on hold for the webview until the rework is done ☺️ [...]

ref: Ouri028/VTray#2 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants