2021-04-28 00:09:26 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
2021-10-16 18:36:03 +02:00
|
|
|
import {IAppWindow} from './types'
|
2021-08-15 12:51:19 +02:00
|
|
|
import {exportUserSettingsBlob, importUserSettingsBlob} from './userSettings'
|
2021-04-28 00:09:26 +02:00
|
|
|
|
|
|
|
declare interface INativeApp {
|
|
|
|
settingsBlob: string | null;
|
|
|
|
}
|
|
|
|
|
|
|
|
declare const NativeApp: INativeApp
|
2021-10-16 18:36:03 +02:00
|
|
|
declare let window: IAppWindow
|
2021-04-28 00:09:26 +02:00
|
|
|
|
2021-09-30 01:58:36 +02:00
|
|
|
export function importNativeAppSettings(): void {
|
2021-04-28 00:09:26 +02:00
|
|
|
if (typeof NativeApp === 'undefined' || !NativeApp.settingsBlob) {
|
|
|
|
return
|
|
|
|
}
|
2021-08-15 12:51:19 +02:00
|
|
|
const importedKeys = importUserSettingsBlob(NativeApp.settingsBlob)
|
|
|
|
const messageType = importedKeys.length ? 'didImportUserSettings' : 'didNotImportUserSettings'
|
|
|
|
postWebKitMessage({type: messageType, settingsBlob: exportUserSettingsBlob(), keys: importedKeys})
|
2021-04-28 00:09:26 +02:00
|
|
|
NativeApp.settingsBlob = null
|
|
|
|
}
|
|
|
|
|
2021-09-30 01:58:36 +02:00
|
|
|
export function notifySettingsChanged(key: string): void {
|
2021-08-15 12:51:19 +02:00
|
|
|
postWebKitMessage({type: 'didChangeUserSettings', settingsBlob: exportUserSettingsBlob(), key})
|
|
|
|
}
|
|
|
|
|
2021-10-16 18:36:03 +02:00
|
|
|
function postWebKitMessage<T>(message: T) {
|
|
|
|
window.webkit?.messageHandlers.nativeApp?.postMessage(message)
|
2021-04-28 00:09:26 +02:00
|
|
|
}
|