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

multi: Implement OSDesktopNotifier for MacOS and some refactoring #2631

Closed
wants to merge 3 commits into from

Conversation

ukane-philemon
Copy link
Contributor

@ukane-philemon ukane-philemon commented Dec 12, 2023

Screenshot 2023-12-12 at 12 09 48 PM

Depends on #2599

  1. Implement OSDesktopNotifier for MacOS and some refactoring
  2. Fix notification-related bugs and code refactoring.

client/webserver/site/src/js/locales.ts Outdated Show resolved Hide resolved
client/webserver/site/src/js/notifications.ts Show resolved Hide resolved
client/webserver/site/src/js/notifications.ts Outdated Show resolved Hide resolved

Doc.bind(enabledCheckbox, 'click', async (e: Event) => {
Copy link
Member

Choose a reason for hiding this comment

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

This bind() should not be necessary to change either, the frontend logic remains the same in webview or webkit.

client/cmd/dexc-desktop/go.mod Outdated Show resolved Hide resolved
client/webserver/site/src/js/locales.ts Outdated Show resolved Hide resolved
client/webserver/site/src/js/notifications.ts Outdated Show resolved Hide resolved
@ukane-philemon ukane-philemon marked this pull request as draft December 13, 2023 00:41
@ukane-philemon
Copy link
Contributor Author

Thanks @peterzen. Some of the changes here should proly come in another PR, I had them fixed since it was notification-related and wanted to put this up real quick so you can see the changes as requested.

Moving to draft for now.

@peterzen
Copy link
Member

Thanks @peterzen. Some of the changes here should proly come in another PR, I had them fixed since it was notification-related and wanted to put this up real quick so you can see the changes as requested.

Awesome, thanks a lot for figuring out the WKUserContentController! Cool stuff.

@ukane-philemon ukane-philemon marked this pull request as ready for review December 27, 2023 11:51
Copy link
Member

@peterzen peterzen left a comment

Choose a reason for hiding this comment

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

I think the refactoring is unnecessary and out of scope of this PR, as they are unrelated to the Darwin OS notification implementation. Could you please keep the code in app_darwin.go /registry.ts but the other changes don't really belong here.

@@ -203,8 +203,8 @@ export default class Application {
this.attachCommon(this.header)
this.attach({})
this.updateMenuItemsDisplay()
// initialize browser notifications
ntfn.fetchBrowserNtfnSettings()
// initialize desktop notifications
Copy link
Member

Choose a reason for hiding this comment

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

This code still manages the browser ntfn's - as well as the desktop toasts. Renaming these functions to suggest they handle desktop notifications only isn't warranted.

@@ -175,25 +175,23 @@ export default class SettingsPage extends BasePage {
this.renderDesktopNtfnSettings()
}

async updateNtfnSetting (e: Event) {
updateNtfnSetting (e: Event) {
Copy link
Member

Choose a reason for hiding this comment

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

No need for the async here - this is fixed in the parent PR.

@ukane-philemon
Copy link
Contributor Author

I think the refactoring is unnecessary and out of scope of this PR, as they are unrelated to the Darwin OS notification implementation. Could you please keep the code in app_darwin.go /registry.ts but the other changes don't really belong here.

Okay. I think you can just cherry-pick what you need for your PR since this builds on top of it. It’ll be easier for reviewers to test everything in one go then I can just close this, okay?

@peterzen
Copy link
Member

Okay. I think you can just cherry-pick what you need for your PR since this builds on top of it. It’ll be easier for reviewers to test everything in one go then I can just close this, okay?

Good idea, it's indeed more straightforward to test all 3 platforms together. Your changes are all in one commit though so I can't cherry-pick the Darwin related modifications - any chance you could maybe separate the core changes from the refactor stuff?

@ukane-philemon
Copy link
Contributor Author

@peterzen 6ee877f

@peterzen
Copy link
Member

@peterzen 6ee877f

Awesome, thank you!

static async sendDesktopNotification (title: string, body?: string): Promise<void> {
if (!desktopNtfnSettings.browserNtfnEnabled) return
if (window.webkit) await window.webkit.messageHandlers.dexcHandler.postMessage(['sendOSNotification', title, body]) // See: client/cmd/dexc-desktop/app_darwin.go#L673-#L697.
else await (window as any).sendOSNotification(title, body) // this calls a function exported via webview.Bind()
Copy link
Member

Choose a reason for hiding this comment

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

Instead of

window as any

add the method to the global Window definition.

sendOSNotification: (title: string, body?: string) => void

Copy link
Member

Choose a reason for hiding this comment

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

This PR was superseded by #2599, these changes were rolled into it.


static async sendDesktopNotification (title: string, body?: string): Promise<void> {
if (!desktopNtfnSettings.browserNtfnEnabled) return
if (window.webkit) await window.webkit.messageHandlers.dexcHandler.postMessage(['sendOSNotification', title, body]) // See: client/cmd/dexc-desktop/app_darwin.go#L673-#L697.
Copy link
Member

Choose a reason for hiding this comment

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

window.webkit is defined on Linux too, apparently, so this breaks Linux desktop notifications.

Copy link
Member

Choose a reason for hiding this comment

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

It works correctly because we test for webview first.
https://github.com/peterzen/dcrdex/blob/c509a3ffdb7a4ae626f395ef0f7ead3f9239f851/client/webserver/site/src/js/notifications.ts#L117-L120

But it did seem a bit brittle indeed, refactored the check to not rely on window.webkit in #2599. c509a3f

@ukane-philemon
Copy link
Contributor Author

@buck54321, I think @peterzen has merged these changes to his PR so we can close this now.

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.

3 participants