Support better migration of old settings on script updates.
This commit is contained in:
parent
600e38fa76
commit
b845e84be4
@ -382,7 +382,7 @@ Config =
|
|||||||
'Bookmark threads.'
|
'Bookmark threads.'
|
||||||
]
|
]
|
||||||
'Fixed Thread Watcher': [
|
'Fixed Thread Watcher': [
|
||||||
null # XXX temporarily set in Main.coffee so old versions update to correct setting
|
true
|
||||||
'Makes the thread watcher scroll with the page.'
|
'Makes the thread watcher scroll with the page.'
|
||||||
1
|
1
|
||||||
]
|
]
|
||||||
|
|||||||
@ -34,8 +34,7 @@ Main =
|
|||||||
if g.VIEW is 'thread'
|
if g.VIEW is 'thread'
|
||||||
g.THREADID = +pathname[3]
|
g.THREADID = +pathname[3]
|
||||||
|
|
||||||
# flatten Config into Conf
|
# Flatten default values from Config into Conf
|
||||||
# and get saved or default values
|
|
||||||
flatten = (parent, obj) ->
|
flatten = (parent, obj) ->
|
||||||
if obj instanceof Array
|
if obj instanceof Array
|
||||||
Conf[parent] = obj[0]
|
Conf[parent] = obj[0]
|
||||||
@ -52,16 +51,50 @@ Main =
|
|||||||
Conf[db] = boards: {}
|
Conf[db] = boards: {}
|
||||||
Conf['selectedArchives'] = {}
|
Conf['selectedArchives'] = {}
|
||||||
|
|
||||||
$.get Conf, (items) ->
|
# Get saved values as items
|
||||||
$.extend Conf, items
|
items = {}
|
||||||
# XXX temporarily set here so old versions update to correct setting
|
items[key] = undefined for key of Conf
|
||||||
Conf['Fixed Thread Watcher'] ?= Conf['Toggleable Thread Watcher']
|
items['previousversion'] = undefined
|
||||||
$.asap (-> doc = d.documentElement), Main.initFeatures
|
$.get items, (items) ->
|
||||||
|
$.asap (-> doc = d.documentElement), ->
|
||||||
|
|
||||||
|
# Fresh install
|
||||||
|
if !items.previousversion?
|
||||||
|
Main.ready ->
|
||||||
|
$.set 'previousversion', g.VERSION
|
||||||
|
Settings.open()
|
||||||
|
|
||||||
|
# Migrate old settings
|
||||||
|
else if items.previousversion isnt g.VERSION
|
||||||
|
Main.upgrade items
|
||||||
|
|
||||||
|
# Combine default values with saved values
|
||||||
|
for key, val of Conf
|
||||||
|
Conf[key] = items[key] ? val
|
||||||
|
|
||||||
|
Main.initFeatures()
|
||||||
|
|
||||||
# set up CSS when <head> is completely loaded
|
# set up CSS when <head> is completely loaded
|
||||||
$.asap (-> doc = d.documentElement), ->
|
$.asap (-> doc = d.documentElement), ->
|
||||||
$.onExists doc, 'body', false, Main.initStyle
|
$.onExists doc, 'body', false, Main.initStyle
|
||||||
|
|
||||||
|
upgrade: (items) ->
|
||||||
|
{previousversion} = items
|
||||||
|
items2 = {previousversion: g.VERSION}
|
||||||
|
compareString = previousversion.replace(/\d+/g, (x) -> ('0000'+x)[-5..])
|
||||||
|
|
||||||
|
if compareString < '00001.00011.00008.00000'
|
||||||
|
unless items['Fixed Thread Watcher']?
|
||||||
|
items2['Fixed Thread Watcher'] = items['Toggleable Thread Watcher'] ? true
|
||||||
|
unless items['Custom Board Navigation']?
|
||||||
|
items2['Custom Board Navigation'] = true
|
||||||
|
|
||||||
|
$.extend items, items2
|
||||||
|
$.set items2, ->
|
||||||
|
el = $.el 'span',
|
||||||
|
<%= html(meta.name + ' has been updated to <a href="' + meta.repo + 'blob/' + meta.mainBranch + '/CHANGELOG.md" target="_blank">version ${g.VERSION}</a>.') %>
|
||||||
|
new Notice 'info', el, 15
|
||||||
|
|
||||||
initFeatures: ->
|
initFeatures: ->
|
||||||
if location.hostname in ['boards.4chan.org', 'sys.4chan.org', 'www.4chan.org']
|
if location.hostname in ['boards.4chan.org', 'sys.4chan.org', 'www.4chan.org']
|
||||||
$.globalEval 'document.documentElement.classList.add("js-enabled");'
|
$.globalEval 'document.documentElement.classList.add("js-enabled");'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user