skiff-org / skiff-windows-app

Skiff's Windows app for privacy-first, end-to-end encrypted Mail, Drive, Calendar, and Pages.
https://skiff.com
GNU Affero General Public License v3.0
108 stars 70 forks source link

Added system tray icon #3

Closed Novack closed 1 year ago

Novack commented 1 year ago

Added TrayController class: • Handles system tray icon and menu. • Includes option for minimizing to tray (on/off). • Includes red dot drawer for unread emails (corresponding events and unread counter on C# side not yet updated, as there are no messages in place from webview - placeholder menu items will help for testing this). • Handles tooltip with unread mail counter.

Note: Added the existing logo image to the resources for using on the TrayController.

Novack commented 1 year ago

We need the messaging from skiff for informing and keeping updated the unread counter. Whenever that be in place, Im more than happy to use it on the unread counter and systry icon red dot.

In the same way, if we can have some messaging and RPCs for mail actions and info (ie: mark as read, delete, mark as spam, contact picture) I can do some work on adding some custom actions and enrichment to the toast notifications.

Edit: if you guys are busy, I will peek into the other projects to check if that is open source and if potentially I can give a hand with that.

amilich commented 1 year ago

Super exciting! Will review + test today.

amilich commented 1 year ago

Here's the code to send to Windows app - will be released today:

   const sendUnreadToWindowsApp = () => {
      if (!isWindowsDesktopApp()) {
        return;
      }
      try {
        const message = {
          type: 'unreadMailCount',
          data: { numUnread }
        };
        // Windows WebView2 injects a global `window.chrome` object
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
        chrome.webview.postMessage(JSON.stringify(message));
      } catch (error) {
        console.error('Failed to send data to Windows app', error);
      }
    };

    // Communicate with react-native and update about unread mail count (for updating iOS badge and macOS badge)
    // If we are on mobile app, send unread count to react-native
    sendRNWebviewMsg('unreadMailCount', { numUnread });
    // If we are on Windows app, send unread count to Windows app
    sendUnreadToWindowsApp();

    const interval = setInterval(() => {
      sendRNWebviewMsg('unreadMailCount', { numUnread });
      sendUnreadToWindowsApp();
    }, POLL_INTERVAL_IN_MS);
    return () => {
      clearInterval(interval);
    };
  }, [numUnread]);
Novack commented 1 year ago

This is awesome! Will check again later today then and add the necessary bindings. Much appreciated!

Novack commented 1 year ago

Implemented the new unreadMailCount message, and took the liberty to sort that message routing code into its own class in preparation for future messages. If the intention is to keep everything in the Windows class, let me know and I will change it back, (I would recomment following my propossed route).

You can check it out at https://github.com/skiff-org/skiff-windows-app/commit/b3e04dde144729dbbbd0da79f75480c95f4ce97c

Note that is not yet working, the message is not reaching the C# side yet.

Novack commented 1 year ago

Worth noting that notifications dont seem to be working, but looks like its not related to these changes, because its failing in my installed release as well. The internal flow processes the notification, but is never displayed. It looks like a lot of moving parts are involved in the toast messages, so not sure whats going on, probably worth simplifying a bit :)

Just in case, tomorrow will move to a previous commit and make sure I didnt broke anything.

Edit: looks like the issue is that the notifications wont display if the window is minimized, so not sure what was the intent.

Edit 2: it seems it was because I had the release 1.0.0.2. With the latest I do see the notifications, so will have to review whats going on. Will check later today.

amilich commented 1 year ago

Worth noting that notifications dont seem to be working, but looks like its not related to these changes, because its failing in my installed release as well. The internal flow processes the notification, but is never displayed. It looks like a lot of moving parts are involved in the toast messages, so not sure whats going on, probably worth simplifying a bit :)

Just in case, tomorrow will move to a previous commit and make sure I didnt broke anything.

Edit: looks like the issue is that the notifications wont display if the window is minimized, so not sure what was the intent.

Edit 2: it seems it was because I had the release 1.0.0.2. With the latest I do see the notifications, so will have to review whats going on. Will check later today.

Notifications should be fixed in latest push. Had to move the display to bottom right of screen instead of window.

Novack commented 1 year ago

Ok good news is, the unread counter code is working great, the tray icon is updated properly. I also sent a fix for an issue with the icon and removed some code used for demoing the unread dot, which is not required anymore. And sent a commit with the Skiff Desktop.csproj including the changes that are producing the conflict.

Still having issue with the notifications, but still not merged from your last cs yet.

Novack commented 1 year ago

Ok after merging from your last CS, I can confirm notifications are working as expected, with the window minimized and even with the window minimized to system tray.

There is another issue, where skiff announces a new email, but a few seconds pass until the mail (and the notification) actually appears in the list. This is an issue I have been experiencing from before all this, but is kind of more noticeable as the red dot also knows about the new email but is not yet there to see.

amilich commented 1 year ago

Ok after merging from your last CS, I can confirm notifications are working as expected, with the window minimized and even with the window minimized to system tray.

There is another issue, where skiff announces a new email, but a few seconds pass until the mail actually appears in the list. This is an issue I have been experiencing from before all this, but is kind of more noticeable as the red dot also knows about the new email but is not yet there to see.

Yep, we'll have to fix this. The issue is that unread count polling is faster than entire inbox polling.

Novack commented 1 year ago

Gotcha. Just for reference, the internal skiff UI counter and the messages to native interfaces like C# work faster, while the actual listing and the notification happen afterwards.

amilich commented 1 year ago

Gotcha. Just for reference, the internal skiff UI counter and the messages to native interfaces like C# work faster, while the actual listing and the notification happen afterwards.

Makes sense. That's consistent with not polling the actual messages more quickly.

Novack commented 1 year ago

Awesome! Thank you for such a great service.