Show options page on first run.

This commit is contained in:
FelisCatus 2014-11-28 20:45:20 +08:00
parent 25f27dd1ee
commit e2133b3962
2 changed files with 19 additions and 3 deletions

View File

@ -221,13 +221,13 @@ class ChromeOptions extends OmegaTarget.Options
else else
Promise.reject() Promise.reject()
getOldOptions = getOldOptions.catch -> getOldOptions = getOldOptions.catch =>
if options?['config'] if options?['config']
Promise.resolve options Promise.resolve options
else if localStorage['config'] else if localStorage['config']
Promise.resolve localStorage Promise.resolve localStorage
else else
Promise.reject new Error('No options set.') Promise.reject new @NoOptionsError()
getOldOptions.then (oldOptions) => getOldOptions.then (oldOptions) =>
i18n = { i18n = {
@ -244,5 +244,8 @@ class ChromeOptions extends OmegaTarget.Options
@_state.set({'firstRun': 'upgrade'}) @_state.set({'firstRun': 'upgrade'})
return this && super(upgraded, upgraded) return this && super(upgraded, upgraded)
onFirstRun: (reason) ->
chrome.tabs.create url: chrome.extension.getURL('options.html')
module.exports = ChromeOptions module.exports = ChromeOptions

View File

@ -34,6 +34,8 @@ class Options
constructor: (@profileName) -> constructor: (@profileName) ->
super.constructor("Profile #{@profileName} does not exist!") super.constructor("Profile #{@profileName} does not exist!")
NoOptionsError: class NoOptionsError extends Error
constructor: (@_options, @_storage, @_state, @log) -> constructor: (@_options, @_storage, @_state, @log) ->
@_storage ?= Storage() @_storage ?= Storage()
@_state ?= Storage() @_state ?= Storage()
@ -55,7 +57,8 @@ class Options
@_storage.remove(removed) @_storage.remove(removed)
).return(options) ).return(options)
).catch (ex) => ).catch (ex) =>
@log.error(ex.stack) if not ex instanceof NoOptionsError
@log.error(ex.stack)
@reset().tap => @reset().tap =>
@_state.set({'firstRun': 'new', 'web.switchGuide': 'showOnFirstUse'}) @_state.set({'firstRun': 'new', 'web.switchGuide': 'showOnFirstUse'})
).then((options) => ).then((options) =>
@ -82,6 +85,10 @@ class Options
).then => @getAll() ).then => @getAll()
@ready.then => @ready.then =>
@_state.get({'firstRun': ''}).then ({firstRun}) =>
if firstRun
@onFirstRun(firstRun)
if @_options['-downloadInterval'] > 0 if @_options['-downloadInterval'] > 0
@updateProfile() @updateProfile()
@ -156,6 +163,12 @@ class Options
@_storage.set(opt) @_storage.set(opt)
).then -> opt ).then -> opt
###*
# Called on the first initialization of options.
# @param {reason} reason The value of 'firstRun' in state.
###
onFirstRun: (reason) -> null
###* ###*
# Return the default options used initially and on resets. # Return the default options used initially and on resets.
# @returns {?OmegaOptions} The default options. # @returns {?OmegaOptions} The default options.