settings.ts
TLDR
The settings.ts
file in the experiments/webext/src/utils
directory contains functions for loading and storing settings using the browser's storage API.
Methods
loadSettings
This method retrieves the host
, username
, token
, and boardId
settings from the browser's storage and returns them as an object.
storeSettings
This method stores the host
, username
, token
, and boardId
settings in the browser's storage. It takes the values for these settings as parameters and returns a promise that resolves when the settings are successfully stored.
storeToken
This method stores the token
setting in the browser's storage. It takes the value
for the token
setting as a parameter and returns a promise that resolves when the token
is successfully stored.
storeBoardId
This method stores the boardId
setting in the browser's storage. It takes the value
for the boardId
setting as a parameter and returns a promise that resolves when the boardId
is successfully stored.
// Copyright (c) 2021-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import browser from 'webextension-polyfill'
interface Settings {
host: string | null
username: string | null
token: string | null
boardId: string | null
}
export function loadSettings(): Settings {
return browser.storage.sync.get(['host', 'username', 'token', 'boardId'])
}
export function storeSettings(host: string, username: string, token: string | null, boardId: string | null) {
console.log(`storing host ${host}`)
return browser.storage.sync.set({ host: host, username: username, token: token, boardId: boardId })
}
export function storeToken(value: string | null) {
return browser.storage.sync.set({ token: value })
}
export function storeBoardId(value: string | null) {
return browser.storage.sync.set({ boardId: value })
}