aboutsummary
aboutsummaryrefslogtreecommitdiff
/**
 * This file is part of Haketilo.
 *
 * Function: Basic wrappers for storage API functions.
 *
 * Copyright (C) 2021 Wojtek Kosior
 * Redistribution terms are gathered in the `copyright' file.
 */

/*
 * IMPORTS_START
 * IMPORT TYPE_PREFIX
 * IMPORT browser
 * IMPORT is_chrome
 * IMPORTS_END
 */

async function get(key)
{
    /* Fix for fact that Chrome does not use promises here */
    const promise = is_chrome ?
	  new Promise(resolve => chrome.storage.local.get(key, resolve)) :
	  browser.storage.local.get(key);

    return (await promise)[key];
}

async function set(key_or_object, value)
{
    const arg = typeof key_or_object === "object" ?
	  key_or_object : {[key_or_object]: value};
    return browser.storage.local.set(arg);
}

async function set_var(name, value)
{
    return set(TYPE_PREFIX.VAR + name, value);
}

async function get_var(name)
{
    return get(TYPE_PREFIX.VAR + name);
}

const on_changed = browser.storage.onChanged || browser.storage.local.onChanged;
const listen = cb => on_changed.addListener(cb);
const no_listen = cb => on_changed.removeListener(cb);

const raw_storage = {get, set, get_var, set_var, listen, no_listen};

/*
 * EXPORTS_START
 * EXPORT raw_storage
 * EXPORTS_END
 */
AGH-engineering-thesis/tree/Makefile.test?id=a0e9d28f2a21cc42dff7ed2fce3e52cb04bc5170'>Makefile.test1964logplainabout -rw-r--r--Makefile.util209logplainabout -rw-r--r--README.txt4934logplainabout d---------design654logplain d---------include78logplain d---------models238logplain -rwxr-xr-xtclasm.tcl6688logplainabout d---------tests1656logplain d---------tools457logplain