mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-01-22 15:08:12 -05:00
add source code reference;fix gist sync not work on first init;refactor code;
This commit is contained in:
parent
fa41a54784
commit
b2bbc5fd60
@ -5,6 +5,14 @@ Promise.longStackTraces()
|
||||
OmegaTargetCurrent.Log = Object.create(OmegaTargetCurrent.Log)
|
||||
Log = OmegaTargetCurrent.Log
|
||||
|
||||
# TODO 将来可能代码需要重构下,这里写得有点乱. (suziwen1@gmail.com)
|
||||
globalThis.isBrowserRestart = globalThis.startupCheck is undefined
|
||||
startupCheck = globalThis.startupCheck ?= -> true
|
||||
|
||||
chrome.runtime.onStartup.addListener ->
|
||||
globalThis.isBrowserRestart = true
|
||||
|
||||
|
||||
unhandledPromises = []
|
||||
unhandledPromisesId = []
|
||||
unhandledPromisesNextId = 1
|
||||
@ -163,9 +171,11 @@ if chrome?.storage?.sync or browser?.storage?.sync
|
||||
|
||||
proxyImpl = OmegaTargetCurrent.proxy.getProxyImpl(Log)
|
||||
state.set({proxyImplFeatures: proxyImpl.features})
|
||||
options = new OmegaTargetCurrent.Options(null, storage, state, Log, sync,
|
||||
options = new OmegaTargetCurrent.Options(storage, state, Log, sync,
|
||||
proxyImpl)
|
||||
|
||||
options.initWithOptions(null, startupCheck)
|
||||
|
||||
options.externalApi = new OmegaTargetCurrent.ExternalApi(options)
|
||||
options.externalApi.listen()
|
||||
|
||||
@ -322,7 +332,6 @@ resetAllOptions = ->
|
||||
chrome.storage.sync.clear(),
|
||||
chrome.storage.local.clear()
|
||||
])
|
||||
|
||||
chrome.runtime.onMessage.addListener (request, sender, respond) ->
|
||||
return unless request and request.method
|
||||
options.ready.then ->
|
||||
|
@ -9,14 +9,8 @@ Url = require('url')
|
||||
|
||||
TEMPPROFILEKEY = 'tempProfileState'
|
||||
|
||||
globalThis.isBrowserRestart = false
|
||||
|
||||
chrome.runtime.onStartup.addListener ->
|
||||
globalThis.isBrowserRestart = true
|
||||
console.log('delete temp profile')
|
||||
idbKeyval.del(TEMPPROFILEKEY).then(->
|
||||
console.log('delete temp profile success')
|
||||
)
|
||||
idbKeyval.del(TEMPPROFILEKEY)
|
||||
|
||||
class ChromeOptions extends OmegaTarget.Options
|
||||
_inspect: null
|
||||
@ -28,7 +22,6 @@ class ChromeOptions extends OmegaTarget.Options
|
||||
chrome.alarms.onAlarm.addListener (alarm) =>
|
||||
switch alarm.name
|
||||
when 'omega.updateProfile'
|
||||
console.log('update profile interval')
|
||||
@ready.then( =>
|
||||
@updateProfile()
|
||||
)
|
||||
@ -73,12 +66,10 @@ class ChromeOptions extends OmegaTarget.Options
|
||||
chrome.tabs.reload(tab.id)
|
||||
)
|
||||
|
||||
init: ->
|
||||
super()
|
||||
init: (startupCheck) ->
|
||||
super(startupCheck)
|
||||
@ready.then =>
|
||||
console.log('get temp profile')
|
||||
idbKeyval.get(TEMPPROFILEKEY).then (tempProfileState) =>
|
||||
console.log('init temp profile:', tempProfileState)
|
||||
# tempProfileState =
|
||||
# { _tempProfile,
|
||||
# _tempProfileActive}
|
||||
|
@ -8,7 +8,8 @@ isPushing = false
|
||||
|
||||
state = null
|
||||
|
||||
optionFilename = 'ZeroOmega.json'
|
||||
mainLetters = ['Z','e', 'r', 'o', 'O', 'm','e', 'g', 'a']
|
||||
optionFilename = mainLetters.concat(['.json']).join('')
|
||||
gistId = ''
|
||||
gistToken = ''
|
||||
gistHost = 'https://api.github.com'
|
||||
@ -135,7 +136,7 @@ getGist = (gistId) ->
|
||||
|
||||
updateGist = (gistId, options) ->
|
||||
postBody = {
|
||||
description: 'ZeroOmega Sync'
|
||||
description: mainLetters.concat([' Sync']).join('')
|
||||
files: {}
|
||||
}
|
||||
postBody.files[optionFilename] = {
|
||||
@ -275,6 +276,8 @@ class ChromeSyncStorage extends OmegaTarget.Storage
|
||||
return Promise.resolve({})
|
||||
Promise.resolve(@storage.remove(keys))
|
||||
.catch(ChromeSyncStorage.parseStorageErrors)
|
||||
destroy: ->
|
||||
idbKeyval.clear(@syncStore)
|
||||
flush: ({data}) ->
|
||||
entries = []
|
||||
result = null
|
||||
|
@ -56,20 +56,26 @@ class Options
|
||||
value = profile
|
||||
return value
|
||||
|
||||
constructor: (options, @_storage, @_state, @log, @sync, @proxyImpl) ->
|
||||
constructor: (@_storage, @_state, @log, @sync, @proxyImpl) ->
|
||||
@_options = {}
|
||||
@_tempProfileRules = {}
|
||||
@_tempProfileRulesByProfile = {}
|
||||
@_storage ?= Storage()
|
||||
@_state ?= Storage()
|
||||
@log ?= Log
|
||||
|
||||
|
||||
###
|
||||
# 拆开比较合理些
|
||||
###
|
||||
initWithOptions: (options, startupCheck) ->
|
||||
if not options?
|
||||
@init()
|
||||
@init(startupCheck)
|
||||
else
|
||||
@ready = @_storage.remove().then(=>
|
||||
@_storage.set(options)
|
||||
).then =>
|
||||
@init()
|
||||
@init(startupCheck)
|
||||
|
||||
###*
|
||||
# Attempt to load options from local and remote storage.
|
||||
@ -174,9 +180,15 @@ class Options
|
||||
# Attempt to initialize (or reinitialize) options.
|
||||
# @returns {Promise<OmegaOptions>} A promise that is fulfilled on ready.
|
||||
###
|
||||
init: ->
|
||||
init: (startupCheck = -> true) ->
|
||||
# startupCheck 一定要放在 isBrowserRestart 后面
|
||||
# TODO (suziwen1@gmail.com)
|
||||
# 1. 好像有 bug , 一直没法重现,但就是很不经意就能出现,概率很小的样子
|
||||
# 2. 有全局变量,容易污染代码,需要重构初始化流程
|
||||
@ready = @loadOptions().then(=>
|
||||
if globalThis.isBrowserRestart and @_options['-startupProfileName']
|
||||
if globalThis.isBrowserRestart and
|
||||
startupCheck() and
|
||||
@_options['-startupProfileName']
|
||||
@applyProfile(@_options['-startupProfileName'])
|
||||
else
|
||||
@_state.get({
|
||||
@ -1033,6 +1045,7 @@ class Options
|
||||
@sync.enabled = false
|
||||
@_syncWatchStop?()
|
||||
@_syncWatchStop = null
|
||||
@sync.destroy()
|
||||
return
|
||||
|
||||
if syncOptions == 'conflict'
|
||||
@ -1059,7 +1072,7 @@ class Options
|
||||
@sync.enabled = true
|
||||
@init()
|
||||
else
|
||||
if remoteOptions.schemaVersion
|
||||
if remoteOptions?.schemaVersion
|
||||
@sync.flush({data: remoteOptions}).then( =>
|
||||
@sync.enabled = false
|
||||
@_state.set({'syncOptions': 'conflict'})
|
||||
|
@ -220,6 +220,8 @@ class OptionsSync
|
||||
})
|
||||
init: (args) ->
|
||||
@storage.init(args)
|
||||
destroy: ->
|
||||
@storage.destroy()
|
||||
flush: ({data}) ->
|
||||
@storage.flush({data})
|
||||
|
||||
|
5
omega-web/lib/csso.js
vendored
5
omega-web/lib/csso.js
vendored
File diff suppressed because one or more lines are too long
6
omega-web/lib/idb-keyval.js
vendored
6
omega-web/lib/idb-keyval.js
vendored
File diff suppressed because one or more lines are too long
4
omega-web/lib/moment-with-locales.js
vendored
4
omega-web/lib/moment-with-locales.js
vendored
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* https://github.com/moment/moment/
|
||||
* 源地址
|
||||
**/
|
||||
;(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
|
Loading…
Reference in New Issue
Block a user