When Converse runs inside a browser extension, enable browser sync and local storage for persistent storage
This commit is contained in:
Dele Olajide 2020-10-30 11:51:55 +00:00 committed by GitHub
parent 4f7ff1f3cf
commit 285bbbc2f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 1 deletions

View File

@ -40,6 +40,7 @@ Soon we'll deprecate the latter, so prepare now.
- #2304: Custom emojis (stickers) images not shown
- #2307: BootstrapModal is not accessible to plugins
- #2308: Allow getHats method to be overriden in the `overrides` object in plugins.
- #2321: When Converse runs inside a browser extension, enable browser sync and local storage for persistent storage
- The `trusted` configuration setting has been removed in favor of two new settings:
[allow_user_trust_override](https://conversejs.org/docs/html/configuration.html#allow-user-trust-override)
[clear_cache_on_logout](https://conversejs.org/docs/html/configuration.html#clear-cache-on-logout)

View File

@ -1587,7 +1587,7 @@ persistent_store
----------------
* Default: ``localStorage``
* Valid options: ``localStorage``, ``IndexedDB``, ``sessionStorage``
* Valid options: ``localStorage``, ``IndexedDB``, ``sessionStorage``, ``BrowserExtLocal``, ``BrowserExtSync``
Determines which store is used for storing persistent data.
@ -1598,6 +1598,17 @@ IndexedDB is not subjected to the same space constraints as localStorage and is
also a requirement for progressive web apps which don't need persistent a
internet connectivity to be functional.
From version 7.0.0 onwards, Converse supports storing data in
`Browser Extension storage <https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage#Example_extensions>`_.
When Converse is running inside a web browser extension, it can now take advantage of storage optimized to meet the specific storage needs of extensions.
BrowserExtSync represents the sync storage area.
Items in sync storage are synced by the browser and are available across all instances of that browser that the user is logged into, across different devices.
BrowserExtLocal represents the local storage area.
Items in local storage are local to the machine the extension was installed on
push_app_servers
----------------

View File

@ -96,6 +96,7 @@
"lerna": "^3.22.1",
"lit-element": "^2.3.1",
"lit-html": "^1.2.1",
"localforage-webextensionstorage-driver": "^2.0.0",
"lodash-template-webpack-loader": "jcbrand/lodash-template-webpack-loader",
"mini-css-extract-plugin": "^0.9.0",
"minimist": "^1.2.3",

View File

@ -10,6 +10,8 @@ import advancedFormat from 'dayjs/plugin/advancedFormat';
import dayjs from 'dayjs';
import log from '@converse/headless/log';
import pluggable from 'pluggable.js/src/pluggable';
import syncDriver from 'localforage-webextensionstorage-driver/sync';
import localDriver from 'localforage-webextensionstorage-driver/local';
import sizzle from 'sizzle';
import stanza_utils from "@converse/headless/utils/stanza";
import u from '@converse/headless/utils/core';
@ -976,7 +978,17 @@ async function initSessionStorage () {
function initPersistentStorage () {
if (api.settings.get('persistent_store') === 'sessionStorage') {
return;
} else if (_converse.api.settings.get("persistent_store") === 'BrowserExtLocal') {
Storage.localForage.defineDriver(localDriver).then(() => Storage.localForage.setDriver('webExtensionLocalStorage'));
_converse.storage['persistent'] = Storage.localForage;
return;
} else if (_converse.api.settings.get("persistent_store") === 'BrowserExtSync') {
Storage.localForage.defineDriver(syncDriver).then(() => Storage.localForage.setDriver('webExtensionSyncStorage'));
_converse.storage['persistent'] = Storage.localForage;
return;
}
const config = {
'name': _converse.isTestEnv() ? 'converse-test-persistent' : 'converse-persistent',
'storeName': _converse.bare_jid