Project

General

Profile

Download (970 Bytes) Statistics
| Branch: | Tag: | Revision:

haketilo / common / storage_raw.js @ 53891495

1
/**
2
 * part of Hachette
3
 * Basic wrappers for storage API functions.
4
 *
5
 * Copyright (C) 2021 Wojtek Kosior
6
 * Redistribution terms are gathered in the `copyright' file.
7
 */
8

    
9
/*
10
 * IMPORTS_START
11
 * IMPORT TYPE_PREFIX
12
 * IMPORT browser
13
 * IMPORT is_chrome
14
 * IMPORTS_END
15
 */
16

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

    
24
    return (await promise)[key];
25
}
26

    
27
async function set(key_or_object, value)
28
{
29
    return browser.storage.local.set(typeof key_or_object === "object" ?
30
				     key_or_object : {[key]: value});
31
}
32

    
33
async function set_var(name, value)
34
{
35
    return set(TYPE_PREFIX.VAR + name, value);
36
}
37

    
38
async function get_var(name)
39
{
40
    return get(TYPE_PREFIX.VAR + name);
41
}
42

    
43
const raw_storage = {get, set, get_var, set_var};
44

    
45
/*
46
 * EXPORTS_START
47
 * EXPORT raw_storage
48
 * EXPORTS_END
49
 */
(14-14/15)