-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[GH-314] Export native app user settings on change #380
[GH-314] Export native app user settings on change #380
Conversation
This switches from exporting the native app user settings on window close to exporting on settings change. This way the settings export remains independent of native application life-cycle events. This is a stop-gap towards enabling settings export on the native Linux app. The latter does not have an easy way to catch window close events. Relates to: mattermost-community#314
let timeout = DispatchTime.now() + .seconds(3) | ||
var result: DispatchTimeoutResult? | ||
|
||
// Busy wait because evaluateJavaScript can only be called from *and* signals on the main thread |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Busy wait be gone! 🎉
|
||
import './styles/variables.scss' | ||
import './styles/main.scss' | ||
import './styles/labels.scss' | ||
|
||
store.setHandlers({getter: UserSettings.getEmojiMartSetting, setter: UserSettings.setEmojiMartSetting}) | ||
importNativeAppSettings() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this here because the initThemes
call below already reads from localStorage.
|
||
const keys = ['language', 'theme', 'lastBoardId', 'lastViewId', 'emoji-mart.last', 'emoji-mart.frequently'] | ||
static getEmojiMartSetting(key: string): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method and the one below are a bit hairy. There's some documentation about the emoji-mart settings keys and values in the upstream README (see the "Storage" section).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thanks for parsing the Emojimart settings! We expect to refactor the emoji picker in the future, so this will likely change (not for a while though).
For some reason ESLint keeps rejecting the enum as a shadowing declaration.
I suspect this is a false positive as I can't see how this would shadow an existing declaration? EDIT: I added an inline comment to disable the rule on this line. |
Conflicts: webapp/src/userSettings.ts
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
Thanks so much @Johennes! I'm so sorry for the delay. Totally my fault for missing this on my todo list! Reviewing now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function notifySettingsChanged(key: string) { | ||
postWebKitMessage({type: 'didChangeUserSettings', key, settingsBlob: exportUserSettingsBlob()}) | ||
} | ||
|
||
function postWebKitMessage(message: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this construct - for extending webapp-to-native messaging in the future. We'll add a mental todo to also adapt this for Windows / Linux in the future.
|
||
const keys = ['language', 'theme', 'lastBoardId', 'lastViewId', 'emoji-mart.last', 'emoji-mart.frequently'] | ||
static getEmojiMartSetting(key: string): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thanks for parsing the Emojimart settings! We expect to refactor the emoji picker in the future, so this will likely change (not for a while though).
Ah, no worries at all @chenilim. I actually forgot that I did this myself until I received the notification about the "stale" label being added last night. 😅 I made the change to check the local storage keys. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the changes @Johennes! LGTM!
I thought about it a bit more, and it's probably less about being a security issue (if someone can inject JS, there's not much we can do), but this verification would help catch any code or typo errors in the future.
@chenilim Should this PR be reviewed by someone else? |
I rebased this on |
So this was one of these cases where a simple typo makes you go on a two-hour goose chase and lets you question God and the world until you finally realize that you fat-fingeredly used This is fixed now and things appear to work correctly again. I left some of the extended logging that I used to analyze the issue around as well. The interaction between the web view and the app is quite tedious to debug so this might come in handy in future. 🙂 |
cc @jespino on above |
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
Conflicts: webapp/src/app.tsx webapp/src/i18n.tsx webapp/src/main.tsx webapp/src/pages/boardPage.tsx
I'll review it ASAP. Thanks for all the effort and the patience @Johennes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
This switches from exporting the native app user settings on window close to exporting on settings change. This way the settings export remains independent of native application life-cycle events.
This is a stop-gap towards enabling settings export on the native Linux app. The latter does not have an easy way to catch window close events.
As a positive side-effect this also makes the settings export on the native macOS app more reliable and prevents settings loss when the app crashes or is force-killed. Additionally, the required code on the native app side is reduced.
On the negative side, the settings are still exported as blob which now causes more processing since the export happens more often. I already exposed the changed settings key in the script message so it should be relatively easy to switch to storing the settings individually in a follow-up change.
Ticket Link
Relates to #314