From b845e84be430278a8d4dcb84e25781ecaef9d349 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Thu, 6 Aug 2015 00:34:19 -0700 Subject: [PATCH] Support better migration of old settings on script updates. --- src/General/Config.coffee | 2 +- src/General/Main.coffee | 47 +++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 0bcbaf908..b6cb44091 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -382,7 +382,7 @@ Config = 'Bookmark threads.' ] '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.' 1 ] diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 737dda2ad..ed836848a 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -34,8 +34,7 @@ Main = if g.VIEW is 'thread' g.THREADID = +pathname[3] - # flatten Config into Conf - # and get saved or default values + # Flatten default values from Config into Conf flatten = (parent, obj) -> if obj instanceof Array Conf[parent] = obj[0] @@ -52,16 +51,50 @@ Main = Conf[db] = boards: {} Conf['selectedArchives'] = {} - $.get Conf, (items) -> - $.extend Conf, items - # XXX temporarily set here so old versions update to correct setting - Conf['Fixed Thread Watcher'] ?= Conf['Toggleable Thread Watcher'] - $.asap (-> doc = d.documentElement), Main.initFeatures + # Get saved values as items + items = {} + items[key] = undefined for key of Conf + items['previousversion'] = undefined + $.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 is completely loaded $.asap (-> doc = d.documentElement), -> $.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 version ${g.VERSION}.') %> + new Notice 'info', el, 15 + initFeatures: -> if location.hostname in ['boards.4chan.org', 'sys.4chan.org', 'www.4chan.org'] $.globalEval 'document.documentElement.classList.add("js-enabled");'