-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
drive4ik
committed
Jul 3, 2024
1 parent
abe9645
commit f1d3faf
Showing
14 changed files
with
604 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,52 @@ | ||
|
||
// import * as Constants from '/js/constants.js'; | ||
import Logger from '/js/logger.js'; | ||
import Messages from '/js/messages.js'; | ||
// import * as Storage from '/js/storage.js'; | ||
// import * as Groups from '/js/groups.js'; | ||
// import * as Utils from '/js/utils.js'; | ||
// import * as Cache from '/js/cache.js'; | ||
// import JSON from '/js/json.js'; | ||
// import * as SyncStorage from '/js/sync/sync-storage.js'; | ||
// import {GithubGist, syncData} from '/js/sync/cloud/cloud.js'; | ||
|
||
const logger = new Logger('cloud mixin'); | ||
const logger = new Logger('sync.cloud-mixin'); | ||
|
||
let instance; | ||
|
||
const {disconnect} = Messages.connectToBackground('sync-progress-mixin', [ | ||
'sync-start', | ||
'sync-progress', | ||
'sync-end', | ||
'sync-error', | ||
], ({action, progress, message}) => { | ||
logger.assert(instance, 'instance of vue not found'); | ||
logger.log(action, progress, message); | ||
|
||
if (!instance) { | ||
return; | ||
} | ||
|
||
if (action === 'sync-start') { | ||
instance.synchronisationError = ''; | ||
instance.synchronisationInProgress = true; | ||
} if (action === 'sync-progress') { | ||
instance.synchronisationProgress = progress; | ||
} else if (action === 'sync-end') { | ||
instance.synchronisationError = ''; | ||
instance.synchronisationInProgress = false; | ||
} else if (action === 'sync-error') { | ||
instance.synchronisationError = message; | ||
instance.synchronisationInProgress = false; | ||
} | ||
}); | ||
|
||
window.addEventListener('unload', disconnect); | ||
|
||
export default { | ||
// data() { | ||
// return { | ||
// openEditDefaultGroup: false, | ||
// }; | ||
// }, | ||
data() { | ||
return { | ||
synchronisationInProgress: false, | ||
synchronisationProgress: 0, | ||
synchronisationError: '', | ||
}; | ||
}, | ||
methods: { | ||
async syncCloud() { | ||
// const log = logger.start('sync button'); | ||
console.clear(); | ||
let res2 = await Messages.sendMessageModule('BG.cloudSync'); | ||
console.debug('res2', res2); | ||
// const result = []; | ||
// console.time('cloud'); | ||
// const syncOptions = await SyncStorage.get(); | ||
// const GithubGistCloud = new GithubGist(syncOptions.githubGistToken, syncOptions.githubGistFileName, syncOptions.githubGistId); | ||
// console.debug(await GithubGistCloud.findGistId()); | ||
// let localData = await Storage.get(); | ||
// let {groups} = await Groups.load(null, true); | ||
// // const allTabs = Utils.concatTabs(groups); | ||
// // await Promise.all(allTabs.map(tab => browser.sessions.setTabValue(tab.id, 'syncId', 16879931))) | ||
// // console.debug('finish') | ||
// // return; | ||
// console.debug('groups:', groups); | ||
// localData.groups = groups; | ||
// let cloud = await GithubGistCloud.getGist(); | ||
// let cloudData = JSON.parse(cloud.content); | ||
// console.debug('cloudData:', JSON.clone(cloudData)); | ||
// console.debug('before', JSON.clone(localData.groups), JSON.clone(cloudData.groups)); | ||
// await syncData(localData, cloudData); | ||
// console.debug('after', localData.groups, cloudData.groups); | ||
// const result = await GitHub.findFileId(localStorage.token, 'STG-backup.json') | ||
// let id = await github.foundStgGistId(); | ||
// let data = await github.getGist(); | ||
// let createdata = await github.createGist(utils.stringify({ | ||
// aaa: 123, | ||
// bbb: [1, '3', '@'], | ||
// }, 2)); | ||
// let result = await github.updateGist(utils.stringify({ | ||
// aaa: 123, | ||
// bbb: [2, '4', '99999'], | ||
// }, 2)); | ||
|
||
// console.debug('gist id', id) | ||
// console.debug('get gist data', data) | ||
// console.debug('create gist data', createdata) | ||
// console.timeEnd('cloud'); | ||
// console.debug('gist result', result) | ||
instance = this; | ||
await Messages.sendMessageModule('BG.cloudSync'); | ||
}, | ||
}, | ||
} |
Oops, something went wrong.