add source code reference;fix gist sync not work on first init;refactor code;

This commit is contained in:
suziwen 2024-08-12 12:32:50 +08:00
parent fa41a54784
commit b2bbc5fd60
8 changed files with 54 additions and 23 deletions

View File

@ -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 ->

View File

@ -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}

View File

@ -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

View File

@ -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'})

View File

@ -220,6 +220,8 @@ class OptionsSync
})
init: (args) ->
@storage.init(args)
destroy: ->
@storage.destroy()
flush: ({data}) ->
@storage.flush({data})

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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) :