Skip to content

Commit

Permalink
Update win-wpf app to persist user settings (issue mattermost-communi…
Browse files Browse the repository at this point in the history
  • Loading branch information
baong12 committed Oct 27, 2023
1 parent 134422d commit 60b2e2a
Show file tree
Hide file tree
Showing 11 changed files with 744 additions and 155 deletions.
6 changes: 6 additions & 0 deletions webapp/src/nativeApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ export function importNativeAppSettings(): void {
const importedKeys = importUserSettingsBlob(NativeApp.settingsBlob)
const messageType = importedKeys.length ? 'didImportUserSettings' : 'didNotImportUserSettings'
postWebKitMessage({type: messageType, settingsBlob: exportUserSettingsBlob(), keys: importedKeys})
postWebViewMessage({type: messageType, settingsBlob: exportUserSettingsBlob(), keys: importedKeys})
NativeApp.settingsBlob = null
}

export function notifySettingsChanged(key: string): void {
postWebKitMessage({type: 'didChangeUserSettings', settingsBlob: exportUserSettingsBlob(), key})
postWebViewMessage({type: 'didChangeUserSettings', settingsBlob: exportUserSettingsBlob(), key})
}

function postWebKitMessage<T>(message: T) {
window.webkit?.messageHandlers.nativeApp?.postMessage(message)
}

function postWebViewMessage<T>(message: T) {
window.chrome?.webview?.postMessage(message)
}
1 change: 1 addition & 0 deletions webapp/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface IAppWindow extends Window {
openInNewBrowser?: ((href: string) => void) | null
webkit?: {messageHandlers: {nativeApp?: {postMessage: <T>(message: T) => void}}}
openPricingModal?: () => (telemetry: TelemetryProps) => void
chrome?: {webview?: {postMessage: <T>(message: T) => void}}
}

// SuiteWindow documents all custom properties
Expand Down
Loading

0 comments on commit 60b2e2a

Please sign in to comment.