2017-11-29 16:28:06 +00:00
// Sketch
//
// Need an easy way of getting and setting settings
// If a setting is not set, the default should probably be returned.
// That probably means that binds etc. should be per-key?
//
// We should probably store all settings in memory, and only load from storage on startup and when we set it
//
// Really, we'd like a way of just letting things use the variables
//
2017-12-04 14:14:18 +00:00
2018-04-12 22:33:10 +01:00
/ * * # T r i d a c t y l C o n f i g u r a t i o n
*
* We very strongly recommend that you pretty much ignore this page and instead follow the link below DEFAULTS that will take you to our own source code which is formatted in a marginally more sane fashion .
*
* /
2017-11-29 16:28:06 +00:00
const CONFIGNAME = "userconfig"
2018-02-01 23:39:23 +00:00
const WAITERS = [ ]
let INITIALISED = false
2017-11-29 16:28:06 +00:00
// make a naked object
2018-04-13 19:28:03 +01:00
function o ( object ) {
return Object . assign ( Object . create ( null ) , object )
2017-11-29 16:28:06 +00:00
}
2018-02-01 23:39:23 +00:00
// "Import" is a reserved word so this will have to do
2018-04-13 19:28:03 +01:00
function schlepp ( settings ) {
Object . assign ( USERCONFIG , settings )
2018-02-01 23:39:23 +00:00
}
2017-11-29 20:13:40 +00:00
// TODO: have list of possibilities for settings, e.g. hintmode: reverse | normal
2017-11-29 16:28:06 +00:00
let USERCONFIG = o ( { } )
const DEFAULTS = o ( {
2018-04-13 19:28:03 +01:00
configversion : "0.0" ,
2018-07-01 18:24:37 +02:00
// When creating new <modifier-letter> maps, make sure to make the modifier uppercase (e.g. <C-a> instead of <c-a>) otherwise some commands might not be able to find them (e.g. `bind <c-a>`)
2018-04-13 19:28:03 +01:00
nmaps : o ( {
2018-04-26 19:53:54 +01:00
"<F1>" : "help" ,
2018-04-13 19:28:03 +01:00
o : "fillcmdline open" ,
O : "current_url open" ,
w : "fillcmdline winopen" ,
W : "current_url winopen" ,
t : "fillcmdline tabopen" ,
2017-11-29 16:28:06 +00:00
"]]" : "followpage next" ,
"[[" : "followpage prev" ,
"[c" : "urlincrement -1" ,
"]c" : "urlincrement 1" ,
2018-07-01 18:24:37 +02:00
"<C-x>" : "urlincrement -1" ,
"<C-a>" : "urlincrement 1" ,
2018-04-13 19:28:03 +01:00
T : "current_url tabopen" ,
yy : "clipboard yank" ,
ys : "clipboard yankshort" ,
yc : "clipboard yankcanon" ,
2018-07-03 19:12:04 +01:00
ym : "clipboard yankmd" ,
yt : "clipboard yanktitle" ,
2018-04-13 19:28:03 +01:00
gh : "home" ,
gH : "home true" ,
p : "clipboard open" ,
P : "clipboard tabopen" ,
j : "scrollline 10" ,
2018-07-01 18:24:37 +02:00
"<C-e>" : "scrollline 10" ,
2018-04-13 19:28:03 +01:00
k : "scrollline -10" ,
2018-07-01 18:24:37 +02:00
"<C-y>" : "scrollline 10" ,
2018-04-13 19:28:03 +01:00
h : "scrollpx -50" ,
l : "scrollpx 50" ,
G : "scrollto 100" ,
gg : "scrollto 0" ,
2018-07-01 18:24:37 +02:00
"<C-u>" : "scrollpage -0.5" ,
"<C-d>" : "scrollpage 0.5" ,
2018-04-16 00:05:31 +01:00
// Disabled while our find mode is bad
2018-07-01 18:24:37 +02:00
/* "<C-f>": "scrollpage -1", */
// "<C-b>": "scrollpage -1",
2018-04-13 19:28:03 +01:00
$ : "scrollto 100 x" ,
2017-12-08 21:11:40 -08:00
// "0": "scrollto 0 x", // will get interpreted as a count
2018-04-16 11:45:29 +01:00
"^" : "scrollto 0 x" ,
2018-07-01 18:24:37 +02:00
"<C-6>" : "buffer #" ,
2018-04-13 19:28:03 +01:00
H : "back" ,
L : "forward" ,
2018-07-01 18:24:37 +02:00
"<C-o>" : "jumpprev" ,
"<C-i>" : "jumpnext" ,
2018-04-13 19:28:03 +01:00
d : "tabclose" ,
2018-05-16 17:46:25 +01:00
D : "composite tabprev; sleep 100; tabclose #" ,
2018-05-04 11:38:15 +01:00
gx0 : "tabclosealltoleft" ,
gx $ : "tabclosealltoright" ,
2018-04-13 19:28:03 +01:00
u : "undo" ,
r : "reload" ,
R : "reloadhard" ,
gi : "focusinput -l" ,
2018-04-20 12:24:15 +01:00
"g;" : "changelistjump -1" ,
2018-04-13 19:28:03 +01:00
gt : "tabnext_gt" ,
gT : "tabprev" ,
2018-04-16 11:45:29 +01:00
// "<c-n>": "tabnext_gt", // c-n is reserved for new window
// "<c-p>": "tabprev",
2017-11-29 16:28:06 +00:00
"g^" : "tabfirst" ,
2018-04-16 11:45:29 +01:00
g0 : "tabfirst" ,
2018-04-13 19:28:03 +01:00
g $ : "tablast" ,
gr : "reader" ,
gu : "urlparent" ,
gU : "urlroot" ,
2018-04-29 08:36:45 +02:00
gf : "viewsource" ,
2018-07-01 17:30:10 +02:00
":" : "fillcmdline_notrail" ,
2018-04-13 19:28:03 +01:00
s : "fillcmdline open search" ,
S : "fillcmdline tabopen search" ,
2018-03-18 15:08:09 +00:00
// find mode not suitable for general consumption yet.
// "/": "find",
// "?": "find -1",
// "n": "findnext 1",
// "N": "findnext -1",
2018-04-13 19:28:03 +01:00
M : "gobble 1 quickmark" ,
2018-06-18 07:55:46 +02:00
B : "fillcmdline bufferall" ,
2018-04-13 19:28:03 +01:00
b : "fillcmdline buffer" ,
ZZ : "qall" ,
f : "hint" ,
F : "hint -b" ,
2017-11-29 16:28:06 +00:00
";i" : "hint -i" ,
";I" : "hint -I" ,
2017-11-28 22:51:53 +00:00
";k" : "hint -k" ,
2017-11-29 16:28:06 +00:00
";y" : "hint -y" ,
";p" : "hint -p" ,
2018-05-18 18:15:13 +03:00
";P" : "hint -P" ,
2017-11-30 04:11:49 +00:00
";r" : "hint -r" ,
2017-11-27 14:43:01 +00:00
";s" : "hint -s" ,
";S" : "hint -S" ,
";a" : "hint -a" ,
";A" : "hint -A" ,
2017-11-29 16:28:06 +00:00
";;" : "hint -;" ,
";#" : "hint -#" ,
2018-04-26 20:54:32 +01:00
";v" : "hint -W exclaim_quiet mpv" ,
2018-06-17 18:18:23 +01:00
";w" : "hint -w" ,
2018-04-28 13:38:53 +01:00
"<S-Insert>" : "mode ignore" ,
2018-05-13 13:30:08 +01:00
"<CA-Esc>" : "mode ignore" ,
2018-05-16 14:59:11 +01:00
"<CA-`>" : "mode ignore" ,
2018-07-02 07:06:26 +02:00
"<Esc>" : "composite mode normal ; hidecmdline" ,
2018-05-25 09:24:02 +01:00
I :
"fillcmdline Ignore mode is now toggled by pressing <S-Insert> or <C-A-`>" ,
2018-04-13 19:28:03 +01:00
a : "current_url bmark" ,
A : "bmark" ,
zi : "zoom 0.1 true" ,
zo : "zoom -0.1 true" ,
zz : "zoom 1" ,
2017-12-02 12:08:30 +01:00
"." : "repeat" ,
2018-04-16 00:05:31 +01:00
"<SA-ArrowUp><SA-ArrowUp><SA-ArrowDown><SA-ArrowDown><SA-ArrowLeft><SA-ArrowRight><SA-ArrowLeft><SA-ArrowRight>ba" :
"open https://www.youtube.com/watch?v=M3iOROuTuMA" ,
2018-07-16 15:25:30 +02:00
"<A-p>" : "pin" ,
2018-07-16 09:50:18 +00:00
"<A-m>" : "mute toggle" ,
2017-11-29 16:40:16 +00:00
} ) ,
2018-04-13 19:28:03 +01:00
autocmds : o ( {
DocStart : o ( {
2018-05-17 21:40:38 +01:00
// "addons.mozilla.org": "mode ignore",
2018-02-01 23:39:23 +00:00
} ) ,
2018-06-02 05:35:48 +02:00
DocEnd : o ( {
// "emacs.org": "sanitise history",
} ) ,
2018-05-11 07:57:12 +02:00
TriStart : o ( {
".*" : "source_quiet" ,
} ) ,
2018-06-01 08:39:43 +02:00
TabEnter : o ( {
// "gmail.com": "mode ignore",
} ) ,
TabLeft : o ( {
// Actually, this doesn't work because tabclose closes the current tab
// Too bad :/
// "emacs.org": "tabclose",
} ) ,
2018-01-31 19:51:08 +00:00
} ) ,
2018-04-13 19:28:03 +01:00
exaliases : o ( {
alias : "command" ,
au : "autocmd" ,
2018-07-12 16:51:25 +01:00
audel : "autocmddelete" ,
audelete : "autocmddelete" ,
2018-04-13 19:28:03 +01:00
b : "buffer" ,
o : "open" ,
w : "winopen" ,
t : "tabopen" ,
tn : "tabnext_gt" ,
bn : "tabnext_gt" ,
tnext : "tabnext_gt" ,
bnext : "tabnext_gt" ,
tp : "tabprev" ,
tN : "tabprev" ,
bp : "tabprev" ,
bN : "tabprev" ,
tprev : "tabprev" ,
bprev : "tabprev" ,
bfirst : "tabfirst" ,
blast : "tablast" ,
tfirst : "tabfirst" ,
tlast : "tablast" ,
bd : "tabclose" ,
bdelete : "tabclose" ,
2018-05-07 23:05:51 +02:00
quit : "tabclose" ,
q : "tabclose" ,
2018-05-22 17:09:19 +01:00
qa : "qall" ,
2018-04-13 19:28:03 +01:00
sanitize : "sanitise" ,
2018-04-14 14:03:54 +01:00
tutorial : "tutor" ,
2018-04-23 11:56:05 +02:00
h : "help" ,
2018-07-16 09:28:50 +00:00
unmute : "mute unmute" ,
2018-05-23 15:39:40 +01:00
authors : "credits" ,
2018-04-20 19:32:09 +01:00
openwith : "hint -W" ,
2018-04-25 12:32:21 +01:00
"!" : "exclaim" ,
2018-05-06 08:15:26 +01:00
"!s" : "exclaim_quiet" ,
2018-05-19 14:10:58 +01:00
colourscheme : "set theme" ,
colours : "colourscheme" ,
colorscheme : "colourscheme" ,
colors : "colourscheme" ,
man : "help" ,
2018-05-05 14:14:02 +01:00
"!js" : "js" ,
2018-05-17 16:45:55 +01:00
"!jsb" : "jsb" ,
2018-05-16 17:12:29 +01:00
current_url : "composite get_current_url | fillcmdline_notrail " ,
2017-12-27 18:03:13 +08:00
} ) ,
2018-02-18 18:23:21 +00:00
followpagepatterns : o ( {
2018-04-13 12:37:43 +01:00
next : "^(next|newer)\\b|»|>>|more" ,
2018-02-18 18:23:21 +00:00
prev : "^(prev(ious)?|older)\\b|«|<<" ,
} ) ,
2018-04-13 19:28:03 +01:00
searchengine : "google" ,
searchurls : o ( {
google : "https://www.google.com/search?q=" ,
scholar : "https://scholar.google.com/scholar?q=" ,
googleuk : "https://www.google.co.uk/search?q=" ,
bing : "https://www.bing.com/search?q=" ,
duckduckgo : "https://duckduckgo.com/?q=" ,
yahoo : "https://search.yahoo.com/search?p=" ,
twitter : "https://twitter.com/search?q=" ,
wikipedia : "https://en.wikipedia.org/wiki/Special:Search/" ,
youtube : "https://www.youtube.com/results?search_query=" ,
amazon :
"https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=" ,
amazonuk :
"https://www.amazon.co.uk/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=" ,
startpage :
"https://startpage.com/do/search?language=english&cat=web&query=" ,
github : "https://github.com/search?utf8=✓&q=" ,
searx : "https://searx.me/?category_general=on&q=" ,
cnrtl : "http://www.cnrtl.fr/lexicographie/" ,
osm : "https://www.openstreetmap.org/search?query=" ,
mdn : "https://developer.mozilla.org/en-US/search?q=" ,
gentoo_wiki :
"https://wiki.gentoo.org/index.php?title=Special%3ASearch&profile=default&fulltext=Search&search=" ,
qwant : "https://www.qwant.com/?q=" ,
2017-12-03 11:30:44 +00:00
} ) ,
2018-03-03 23:42:46 +01:00
2018-04-13 19:28:03 +01:00
newtab : "" ,
viewsource : "tridactyl" , // "tridactyl" or "default"
storageloc : "sync" ,
homepages : [ ] ,
hintchars : "hjklasdfgyuiopqwertnmzxcvb" ,
hintfiltermode : "simple" , // "simple", "vimperator", "vimperator-reflow"
2018-03-17 00:37:39 -04:00
hintnames : "short" ,
2018-04-13 19:28:03 +01:00
2018-04-06 06:04:47 +02:00
// Controls whether the page can focus elements for you via js
// Remember to also change browser.autofocus (autofocusing elements via
// HTML) in about:config
// Maybe have a nice user-vicible message when the setting is changed?
2018-03-05 19:20:52 +01:00
allowautofocus : "true" ,
2018-03-03 23:42:46 +01:00
2018-05-26 17:31:27 +02:00
// These two options will fall back to user's preferences and then to a
// default value set in scrolling.ts if left undefined.
2018-05-29 20:38:12 +01:00
smoothscroll : "false" , // "false" | "true"
2018-05-30 05:24:55 +02:00
scrollduration : 100 , // number
2018-05-26 17:31:27 +02:00
2018-04-13 19:28:03 +01:00
tabopenpos : "next" ,
relatedopenpos : "related" ,
ttsvoice : "default" , // chosen from the listvoices list, or "default"
ttsvolume : 1 , // 0 to 1
ttsrate : 1 , // 0.1 to 10
ttspitch : 1 , // 0 to 2
2018-03-10 15:42:09 +01:00
2018-03-13 12:46:31 +00:00
// either "nextinput" or "firefox"
2018-03-10 15:42:09 +01:00
// If nextinput, <Tab> after gi brings selects the next input
2018-03-13 12:46:31 +00:00
// If firefox, <Tab> selects the next selectable element, e.g. a link
2018-04-13 19:28:03 +01:00
gimode : "nextinput" , // either "nextinput" or "firefox"
2017-12-04 14:14:18 +00:00
2018-04-02 14:48:06 +02:00
// either "beginning" or "end"
// Decides where to place the cursor when selecting non-empty input fields
2018-04-13 19:28:03 +01:00
cursorpos : "end" ,
2018-04-02 14:48:06 +02:00
2018-04-13 19:28:03 +01:00
theme : "default" , // currently available: "default", "dark"
2018-04-23 21:28:46 +01:00
modeindicator : "true" ,
2017-12-04 14:14:18 +00:00
2018-05-28 16:15:37 +01:00
jumpdelay : 3000 , // Milliseconds before registering a scroll in the jumplist
2018-03-11 15:25:28 +01:00
2017-12-29 23:58:23 +00:00
// Default logging levels - 2 === WARNING
2018-04-13 19:28:03 +01:00
logging : o ( {
messaging : 2 ,
cmdline : 2 ,
controller : 2 ,
2018-05-14 10:59:43 +00:00
containers : 2 ,
2018-04-13 19:28:03 +01:00
hinting : 2 ,
state : 2 ,
excmd : 1 ,
2018-05-20 13:17:28 +01:00
styling : 2 ,
2017-12-04 14:14:18 +00:00
} ) ,
2018-04-24 19:49:44 +01:00
noiframeon : [ ] ,
2018-04-18 21:49:33 +01:00
2018-04-20 22:06:06 +01:00
// Native messenger settings
2018-04-18 21:49:33 +01:00
// This has to be a command that stays in the foreground for the whole editing session
2018-04-25 15:30:17 +01:00
// "auto" will attempt to find a sane editor in your path.
// Please send your requests to have your favourite terminal moved further up the list to /dev/null.
// (but we are probably happy to add your terminal to the list if it isn't already there).
editorcmd : "auto" ,
2018-04-20 22:06:06 +01:00
browser : "firefox" ,
2018-07-03 19:52:22 +02:00
yankto : "clipboard" , // "clipboard", "selection", "both"
putfrom : "clipboard" , // "clipboard", "selection"
2018-06-12 06:15:28 +02:00
externalclipboardcmd : "auto" ,
2018-04-25 12:44:16 +01:00
nativeinstallcmd :
"curl -fsSl https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/install.sh | bash" ,
2018-07-11 12:19:04 +10:00
win_nativeinstallcmd :
"powershell -NoProfile -InputFormat None -Command \"Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/install.ps1'))\"" ,
2018-04-22 19:59:41 +01:00
profiledir : "auto" ,
2018-05-03 17:48:03 +01:00
2018-05-08 12:27:30 +00:00
// Container settings
// If enabled, tabopen opens a new tab in the currently active tab's container.
tabopencontaineraware : "false" ,
2018-06-16 09:22:52 +00:00
// If moodeindicator is enabled, containerindicator will color the border of the mode indicator with the container color.
containerindicator : "true" ,
2018-05-03 17:48:03 +01:00
// Performance related settings
// number of most recent results to ask Firefox for. We display the top 20 or so most frequently visited ones.
historyresults : "50" ,
2018-05-08 17:49:59 +01:00
// Security settings
2018-05-11 12:06:43 +01:00
csp : "untouched" , // change this to "clobber" to ruin the CSP of all sites and make Tridactyl run a bit better on some of them, e.g. raw.github*
2017-11-29 16:28:06 +00:00
} )
2018-02-01 23:39:23 +00:00
/ * * G i v e n a n o b j e c t a n d a t a r g e t , e x t r a c t t h e t a r g e t i f i t e x i s t s , e l s e r e t u r n u n d e f i n e d
@param target path of properties as an array
* /
function getDeepProperty ( obj , target ) {
if ( obj !== undefined && target . length ) {
return getDeepProperty ( obj [ target [ 0 ] ] , target . slice ( 1 ) )
} else {
return obj
}
}
/ * * C r e a t e t h e k e y p a t h t a r g e t i f i t d o e s n ' t e x i s t a n d s e t t h e f i n a l p r o p e r t y t o v a l u e .
If the path is an empty array , replace the obj .
@param target path of properties as an array
* /
2018-02-02 13:11:23 +00:00
function setDeepProperty ( obj , value , target ) {
2018-02-01 23:39:23 +00:00
if ( target . length > 1 ) {
// If necessary antecedent objects don't exist, create them.
if ( obj [ target [ 0 ] ] === undefined ) {
obj [ target [ 0 ] ] = o ( { } )
2017-11-29 16:28:06 +00:00
}
2018-02-01 23:39:23 +00:00
return setDeepProperty ( obj [ target [ 0 ] ] , value , target . slice ( 1 ) )
} else {
obj [ target [ 0 ] ] = value
}
}
/ * * G e t t h e v a l u e o f t h e k e y t a r g e t .
If the user has not specified a key , use the corresponding key from
defaults , if one exists , else undefined .
* /
export function get ( . . . target ) {
const user = getDeepProperty ( USERCONFIG , target )
const defult = getDeepProperty ( DEFAULTS , target )
// Merge results if there's a default value and it's not an Array or primitive.
2018-04-13 19:28:03 +01:00
if ( defult && ( ! Array . isArray ( defult ) && typeof defult === "object" ) ) {
2018-02-01 23:39:23 +00:00
return Object . assign ( o ( { } ) , defult , user )
} else {
2018-02-19 16:17:57 +00:00
if ( user !== undefined ) {
return user
} else {
return defult
}
2017-11-29 16:28:06 +00:00
}
}
2018-02-01 23:39:23 +00:00
/ * * G e t t h e v a l u e o f t h e k e y t a r g e t , b u t w a i t f o r c o n f i g t o b e l o a d e d f r o m t h e
database first if it has not been at least once before .
This is useful if you are a content script and you ' ve just been loaded .
* /
export async function getAsync ( . . . target ) {
if ( INITIALISED ) {
2018-02-02 14:12:47 +00:00
return get ( . . . target )
2018-02-01 23:39:23 +00:00
} else {
2018-04-13 19:28:03 +01:00
return new Promise ( resolve = >
WAITERS . push ( ( ) = > resolve ( get ( . . . target ) ) ) ,
2018-02-01 23:39:23 +00:00
)
}
2017-11-29 16:28:06 +00:00
}
2018-02-01 23:39:23 +00:00
/ * * F u l l t a r g e t s p e c i f i c a t i o n , t h e n v a l u e
e . g .
set ( "nmaps" , "o" , "open" )
set ( "search" , "default" , "google" )
set ( "aucmd" , "BufRead" , "memrise.com" , "open memrise.com" )
* /
export function set ( . . . args ) {
if ( args . length < 2 ) {
throw "You must provide at least two arguments!"
}
2018-02-19 16:17:57 +00:00
const target = args . slice ( 0 , args . length - 1 )
const value = args [ args . length - 1 ]
2018-02-01 23:39:23 +00:00
setDeepProperty ( USERCONFIG , value , target )
save ( )
}
/** Delete the key at target if it exists */
export function unset ( . . . target ) {
const parent = getDeepProperty ( USERCONFIG , target . slice ( 0 , - 1 ) )
2018-02-19 16:17:57 +00:00
if ( parent !== undefined ) delete parent [ target [ target . length - 1 ] ]
2018-02-01 23:39:23 +00:00
save ( )
2017-11-29 18:57:04 +00:00
}
2018-02-01 23:39:23 +00:00
/ * * S a v e t h e c o n f i g b a c k t o s t o r a g e A P I .
Config is not synchronised between different instances of this module until
sometime after this happens .
* /
2018-04-13 19:28:03 +01:00
export async function save ( storage : "local" | "sync" = get ( "storageloc" ) ) {
2017-11-29 16:56:56 +00:00
// let storageobj = storage == "local" ? browser.storage.local : browser.storage.sync
// storageobj.set({CONFIGNAME: USERCONFIG})
let settingsobj = o ( { } )
settingsobj [ CONFIGNAME ] = USERCONFIG
if ( storage == "local" ) browser . storage . local . set ( settingsobj )
else browser . storage . sync . set ( settingsobj )
2017-11-29 16:28:06 +00:00
}
2018-03-10 15:42:09 +01:00
/ * * U p d a t e s t h e c o n f i g t o t h e l a t e s t v e r s i o n .
Proposed semantic for config versionning :
- x . y - > x + 1.0 : major architectural changes
- x . y - > x . y + 1 : renaming settings / changing their types
There 's no need for an updater if you' re only adding a new setting / changing
a default setting
2018-03-13 12:46:31 +00:00
When adding updaters , don ' t forget to set ( "configversion" , newversionnumber ) !
2018-03-10 15:42:09 +01:00
* /
2018-03-10 14:40:23 +01:00
export async function update() {
2018-03-10 14:18:09 +01:00
let updaters = {
2018-03-10 14:40:23 +01:00
"0.0" : async ( ) = > {
try {
// Before we had a config system, we had nmaps, and we put them in the
// root namespace because we were young and bold.
let legacy_nmaps = await browser . storage . sync . get ( "nmaps" )
2018-04-24 20:00:14 +01:00
if ( Object . keys ( legacy_nmaps ) . length > 0 ) {
2018-04-13 19:28:03 +01:00
USERCONFIG [ "nmaps" ] = Object . assign (
legacy_nmaps [ "nmaps" ] ,
USERCONFIG [ "nmaps" ] ,
)
2018-03-10 14:40:23 +01:00
}
} finally {
2018-03-13 12:46:31 +00:00
set ( "configversion" , "1.0" )
2018-03-10 14:40:23 +01:00
}
2018-03-10 14:18:09 +01:00
} ,
2018-03-10 15:42:09 +01:00
"1.0" : ( ) = > {
let vimiumgi = getDeepProperty ( USERCONFIG , "vimium-gi" )
2018-03-13 12:46:31 +00:00
if ( vimiumgi === true || vimiumgi === "true" )
set ( "gimode" , "nextinput" )
else if ( vimiumgi === false || vimiumgi === "false" )
set ( "gimode" , "firefox" )
2018-03-10 15:42:09 +01:00
unset ( "vimium-gi" )
2018-03-13 12:46:31 +00:00
set ( "configversion" , "1.1" )
2018-04-13 19:28:03 +01:00
} ,
2018-03-10 14:18:09 +01:00
}
2018-04-13 19:28:03 +01:00
if ( ! get ( "configversion" ) ) set ( "configversion" , "0.0" )
2018-03-13 12:46:31 +00:00
while ( updaters [ get ( "configversion" ) ] instanceof Function ) {
await updaters [ get ( "configversion" ) ] ( )
2018-03-10 14:18:09 +01:00
}
}
2018-02-01 23:39:23 +00:00
/ * * R e a d a l l u s e r c o n f i g u r a t i o n f r o m s t o r a g e A P I t h e n n o t i f y a n y w a i t i n g a s y n c h r o n o u s c a l l s
asynchronous calls generated by getAsync .
* /
async function init() {
2018-03-10 14:40:23 +01:00
let syncConfig = await browser . storage . sync . get ( CONFIGNAME )
schlepp ( syncConfig [ CONFIGNAME ] )
// Local storage overrides sync
let localConfig = await browser . storage . local . get ( CONFIGNAME )
schlepp ( localConfig [ CONFIGNAME ] )
await update ( )
INITIALISED = true
for ( let waiter of WAITERS ) {
waiter ( )
2018-02-01 23:39:23 +00:00
}
2017-11-29 16:28:06 +00:00
}
2017-11-29 21:48:46 +00:00
2018-02-01 23:39:23 +00:00
// Listen for changes to the storage and update the USERCONFIG if appropriate.
// TODO: BUG! Sync and local storage are merged at startup, but not by this thing.
2018-06-16 14:39:42 +02:00
browser . storage . onChanged . addListener ( async ( changes , areaname ) = > {
2018-04-13 19:28:03 +01:00
if ( CONFIGNAME in changes ) {
2018-06-16 14:39:42 +02:00
// newValue is undefined when calling browser.storage.AREANAME.clear()
if ( changes [ CONFIGNAME ] . newValue !== undefined ) {
USERCONFIG = changes [ CONFIGNAME ] . newValue
} else if ( areaname === ( await get ( "storageloc" ) ) ) {
// If newValue is undefined and AREANAME is the same value as STORAGELOC, the user wants to clean their config
USERCONFIG = o ( { } )
}
2017-11-29 21:48:46 +00:00
}
2018-04-13 19:28:03 +01:00
} )
2018-02-01 23:39:23 +00:00
init ( )