TabsStore.sys.mjs (1454B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const lazy = {}; 6 7 ChromeUtils.defineESModuleGetters(lazy, { 8 AsyncShutdown: "resource://gre/modules/AsyncShutdown.sys.mjs", 9 TabsStore: 10 "moz-src:///toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustTabs.sys.mjs", 11 }); 12 13 var storePromise = null; 14 15 export async function getTabsStore() { 16 if (storePromise == null) { 17 const path = PathUtils.join(PathUtils.profileDir, "synced-tabs.db"); 18 storePromise = lazy.TabsStore.init(path); 19 20 lazy.AsyncShutdown.profileBeforeChange.addBlocker( 21 "TabsStore: shutdown", 22 async function blocker() { 23 try { 24 let store = await storePromise; 25 await store.closeConnection(); 26 storePromise = null; 27 } finally { 28 lazy.AsyncShutdown.profileBeforeChange.removeBlocker(blocker); 29 } 30 } 31 ); 32 } 33 return await storePromise; 34 } 35 36 export async function getRemoteCommandStore() { 37 const store = await getTabsStore(); 38 // creating a new remote command store is cheap (but not free, so maybe we should cache this in the future?) 39 return await store.newRemoteCommandStore(); 40 } 41 42 export { 43 RemoteCommand, 44 PendingCommand, 45 } from "moz-src:///toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustTabs.sys.mjs";