2021-04-28 00:09:26 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
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
|
|
|
|
|
|
|
|
export function importNativeAppSettings() {
|
|
|
|
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-08-15 12:51:19 +02:00
|
|
|
export function notifySettingsChanged(key: string) {
|
|
|
|
postWebKitMessage({type: 'didChangeUserSettings', settingsBlob: exportUserSettingsBlob(), key})
|
|
|
|
}
|
|
|
|
|
2021-04-28 00:09:26 +02:00
|
|
|
function postWebKitMessage(message: any) {
|
2021-08-15 12:51:19 +02:00
|
|
|
(window as any).webkit?.messageHandlers.nativeApp?.postMessage(message)
|
2021-04-28 00:09:26 +02:00
|
|
|
}
|