summaryrefslogtreecommitdiff
path: root/background/storage_server.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'background/storage_server.mjs')
-rw-r--r--background/storage_server.mjs58
1 files changed, 0 insertions, 58 deletions
diff --git a/background/storage_server.mjs b/background/storage_server.mjs
deleted file mode 100644
index 3a141ff..0000000
--- a/background/storage_server.mjs
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
-* Myext storage through connection (server side)
-*
-* Copyright (C) 2021 Wojtek Kosior
-*
-* Dual-licensed under:
-* - 0BSD license
-* - GPLv3 or (at your option) any later version
-*/
-
-import listen_for_connection from './message_server.mjs';
-import get_storage from './storage.mjs';
-import {TYPE_PREFIX} from '/common/stored_types.mjs';
-import CONNECTION_TYPE from '/common/connection_types.mjs';
-
-var storage;
-
-async function handle_remote_call(port, message)
-{
- let [call_id, func, args] = message;
-
- try {
- let result = await Promise.resolve(storage[func](...args));
- port.postMessage({call_id, result});
- } catch (error) {
- error = error + '';
- port.postMessage({call_id, error});
- }
-}
-
-function remove_storage_listener(cb) {
- storage.remove_change_listener(cb);
-}
-
-function new_connection(port)
-{
- console.log("new remote storage connection!");
-
- port.postMessage({
- [TYPE_PREFIX.SCRIPT] : storage.get_all(TYPE_PREFIX.SCRIPT),
- [TYPE_PREFIX.BUNDLE] : storage.get_all(TYPE_PREFIX.BUNDLE),
- [TYPE_PREFIX.PAGE] : storage.get_all(TYPE_PREFIX.PAGE)
- });
-
- let handle_change = change => port.postMessage(change);
-
- storage.add_change_listener(handle_change);
-
- port.onMessage.addListener(m => handle_remote_call(port, m));
- port.onDisconnect.addListener(() => remove_storage_listener(handle_change));
-}
-
-export default async function start()
-{
- storage = await get_storage();
-
- listen_for_connection(CONNECTION_TYPE.REMOTE_STORAGE, new_connection);
-}