diff --git a/CHANGES.md b/CHANGES.md index 6c32a325e..600dd2ec3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index a1f2cdbcb..0d072bd2a 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -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 `_. + +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 ---------------- diff --git a/package.json b/package.json index 5d261060a..dce238502 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/headless/converse-core.js b/src/headless/converse-core.js index 030c882b7..44541498b 100644 --- a/src/headless/converse-core.js +++ b/src/headless/converse-core.js @@ -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