You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-06 09:19:22 +02:00
All: Started moving sync glue logic to SyncTarget classes
This commit is contained in:
@@ -16,7 +16,7 @@ class Command extends BaseCommand {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.syncTarget_ = null;
|
||||
this.syncTargetId_ = null;
|
||||
this.releaseLockFn_ = null;
|
||||
this.oneDriveApiUtils_ = null;
|
||||
}
|
||||
@@ -62,6 +62,27 @@ class Command extends BaseCommand {
|
||||
});
|
||||
}
|
||||
|
||||
async doAuth(syncTargetId) {
|
||||
const syncTarget = reg.syncTarget(this.syncTargetId_);
|
||||
this.oneDriveApiUtils_ = new OneDriveApiNodeUtils(syncTarget.oneDriveApi());
|
||||
const auth = await this.oneDriveApiUtils_.oauthDance({
|
||||
log: (...s) => { return this.stdout(...s); }
|
||||
});
|
||||
this.oneDriveApiUtils_ = null;
|
||||
return auth;
|
||||
}
|
||||
|
||||
cancelAuth() {
|
||||
if (this.oneDriveApiUtils_) {
|
||||
this.oneDriveApiUtils_.cancelOAuthDance();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
doingAuth() {
|
||||
return !!this.oneDriveApiUtils_;
|
||||
}
|
||||
|
||||
async action(args) {
|
||||
this.releaseLockFn_ = null;
|
||||
|
||||
@@ -91,25 +112,24 @@ class Command extends BaseCommand {
|
||||
};
|
||||
|
||||
try {
|
||||
this.syncTarget_ = Setting.value('sync.target');
|
||||
if (args.options.target) this.syncTarget_ = args.options.target;
|
||||
this.syncTargetId_ = Setting.value('sync.target');
|
||||
if (args.options.target) this.syncTargetId_ = args.options.target;
|
||||
|
||||
if (this.syncTarget_ == Setting.SYNC_TARGET_ONEDRIVE && !reg.syncHasAuth(this.syncTarget_)) {
|
||||
const syncTarget = reg.syncTarget(this.syncTargetId_);
|
||||
|
||||
if (syncTarget.isAuthenticated()) {
|
||||
app().gui().showConsole();
|
||||
app().gui().maximizeConsole();
|
||||
this.oneDriveApiUtils_ = new OneDriveApiNodeUtils(reg.oneDriveApi());
|
||||
const auth = await this.oneDriveApiUtils_.oauthDance({
|
||||
log: (...s) => { return this.stdout(...s); }
|
||||
});
|
||||
this.oneDriveApiUtils_ = null;
|
||||
Setting.setValue('sync.3.auth', auth ? JSON.stringify(auth) : null);
|
||||
|
||||
const auth = await this.doAuth(this.syncTargetId_);
|
||||
Setting.setValue('sync.' + this.syncTargetId_ + '.auth', auth ? JSON.stringify(auth) : null);
|
||||
if (!auth) {
|
||||
this.stdout(_('Authentication was not completed (did not receive an authentication token).'));
|
||||
return cleanUp();
|
||||
}
|
||||
}
|
||||
|
||||
let sync = await reg.synchronizer(this.syncTarget_);
|
||||
const sync = await syncTarget.synchronizer();
|
||||
|
||||
let options = {
|
||||
onProgress: (report) => {
|
||||
@@ -123,13 +143,13 @@ class Command extends BaseCommand {
|
||||
randomFailures: args.options['random-failures'] === true,
|
||||
};
|
||||
|
||||
this.stdout(_('Synchronisation target: %s (%s)', Setting.enumOptionLabel('sync.target', this.syncTarget_), this.syncTarget_));
|
||||
this.stdout(_('Synchronisation target: %s (%s)', Setting.enumOptionLabel('sync.target', this.syncTargetId_), this.syncTargetId_));
|
||||
|
||||
if (!sync) throw new Error(_('Cannot initialize synchroniser.'));
|
||||
|
||||
this.stdout(_('Starting synchronisation...'));
|
||||
|
||||
const contextKey = 'sync.' + this.syncTarget_ + '.context';
|
||||
const contextKey = 'sync.' + this.syncTargetId_ + '.context';
|
||||
let context = Setting.value(contextKey);
|
||||
|
||||
context = context ? JSON.parse(context) : {};
|
||||
@@ -156,26 +176,28 @@ class Command extends BaseCommand {
|
||||
}
|
||||
|
||||
async cancel() {
|
||||
if (this.oneDriveApiUtils_) {
|
||||
this.oneDriveApiUtils_.cancelOAuthDance();
|
||||
if (this.doingAuth()) {
|
||||
this.cancelAuth();
|
||||
return;
|
||||
}
|
||||
|
||||
const target = this.syncTarget_ ? this.syncTarget_ : Setting.value('sync.target');
|
||||
const syncTargetId = this.syncTargetId_ ? this.syncTargetId_ : Setting.value('sync.target');
|
||||
|
||||
cliUtils.redrawDone();
|
||||
|
||||
this.stdout(_('Cancelling... Please wait.'));
|
||||
|
||||
if (reg.syncHasAuth(target)) {
|
||||
let sync = await reg.synchronizer(target);
|
||||
const syncTarget = reg.syncTarget(syncTargetId);
|
||||
|
||||
if (syncTarget.isAuthenticated()) {
|
||||
const sync = await syncTarget.synchronizer();
|
||||
if (sync) await sync.cancel();
|
||||
} else {
|
||||
if (this.releaseLockFn_) this.releaseLockFn_();
|
||||
this.releaseLockFn_ = null;
|
||||
}
|
||||
|
||||
this.syncTarget_ = null;
|
||||
this.syncTargetId_ = null;
|
||||
}
|
||||
|
||||
cancellable() {
|
||||
|
||||
@@ -568,12 +568,15 @@ msgstr ""
|
||||
msgid "Add or remove tags"
|
||||
msgstr ""
|
||||
|
||||
msgid "Switch between note and to-do"
|
||||
msgid "Switch between note and to-do type"
|
||||
msgstr ""
|
||||
|
||||
msgid "Delete"
|
||||
msgstr ""
|
||||
|
||||
msgid "Delete notes?"
|
||||
msgstr ""
|
||||
|
||||
msgid "No notes in here. Create one by clicking on \"New note\"."
|
||||
msgstr ""
|
||||
|
||||
@@ -628,6 +631,9 @@ msgstr ""
|
||||
msgid "Unknown flag: %s"
|
||||
msgstr ""
|
||||
|
||||
msgid "OneDrive"
|
||||
msgstr ""
|
||||
|
||||
#, javascript-format
|
||||
msgid "Unknown log level: %s"
|
||||
msgstr ""
|
||||
@@ -641,11 +647,6 @@ msgid ""
|
||||
"synchronisation again may fix the problem."
|
||||
msgstr ""
|
||||
|
||||
msgid ""
|
||||
"Please set the \"sync.2.path\" config value to the desired synchronisation "
|
||||
"destination."
|
||||
msgstr ""
|
||||
|
||||
#, javascript-format
|
||||
msgid "Cannot access %s"
|
||||
msgstr ""
|
||||
@@ -737,9 +738,6 @@ msgstr ""
|
||||
msgid "File system"
|
||||
msgstr ""
|
||||
|
||||
msgid "OneDrive"
|
||||
msgstr ""
|
||||
|
||||
msgid "Text editor"
|
||||
msgstr ""
|
||||
|
||||
@@ -784,10 +782,10 @@ msgstr ""
|
||||
msgid "%d hours"
|
||||
msgstr ""
|
||||
|
||||
msgid "Show advanced options"
|
||||
msgid "Automatically update the application"
|
||||
msgstr ""
|
||||
|
||||
msgid "Automatically update the application"
|
||||
msgid "Show advanced options"
|
||||
msgstr ""
|
||||
|
||||
msgid "Sync status (synced items / total items)"
|
||||
@@ -819,6 +817,9 @@ msgstr ""
|
||||
msgid "There are currently no notes. Create one by clicking on the (+) button."
|
||||
msgstr ""
|
||||
|
||||
msgid "Delete these notes?"
|
||||
msgstr ""
|
||||
|
||||
msgid "Log"
|
||||
msgstr ""
|
||||
|
||||
@@ -828,6 +829,13 @@ msgstr ""
|
||||
msgid "Export Debug Report"
|
||||
msgstr ""
|
||||
|
||||
msgid "Move to notebook..."
|
||||
msgstr ""
|
||||
|
||||
#, javascript-format
|
||||
msgid "Move %d notes to notebook \"%s\"?"
|
||||
msgstr ""
|
||||
|
||||
msgid "Cancel synchronisation"
|
||||
msgstr ""
|
||||
|
||||
|
||||
@@ -620,12 +620,17 @@ msgstr "Disposition"
|
||||
msgid "Add or remove tags"
|
||||
msgstr "Gérer les étiquettes"
|
||||
|
||||
msgid "Switch between note and to-do"
|
||||
#, fuzzy
|
||||
msgid "Switch between note and to-do type"
|
||||
msgstr "Alterner entre note et tâche"
|
||||
|
||||
msgid "Delete"
|
||||
msgstr "Supprimer"
|
||||
|
||||
#, fuzzy
|
||||
msgid "Delete notes?"
|
||||
msgstr "Supprimer la note ?"
|
||||
|
||||
msgid "No notes in here. Create one by clicking on \"New note\"."
|
||||
msgstr ""
|
||||
"Pas de notes ici. Créez-en une en pressant le bouton \"Nouvelle note\"."
|
||||
@@ -681,6 +686,9 @@ msgstr "Utilisation : %s"
|
||||
msgid "Unknown flag: %s"
|
||||
msgstr "Paramètre inconnu : %s"
|
||||
|
||||
msgid "OneDrive"
|
||||
msgstr "OneDrive"
|
||||
|
||||
#, javascript-format
|
||||
msgid "Unknown log level: %s"
|
||||
msgstr "Paramètre inconnu : %s"
|
||||
@@ -696,13 +704,6 @@ msgstr ""
|
||||
"Impossible de rafraîchir la connexion à OneDrive. Démarrez la "
|
||||
"synchronisation à nouveau pour corriger le problème."
|
||||
|
||||
msgid ""
|
||||
"Please set the \"sync.2.path\" config value to the desired synchronisation "
|
||||
"destination."
|
||||
msgstr ""
|
||||
"Veuillez attribuer une valeur au paramètre de configuration \"sync.2.path\" "
|
||||
"pour indiquer le dossier où devra se faire la synchronisation."
|
||||
|
||||
#, javascript-format
|
||||
msgid "Cannot access %s"
|
||||
msgstr "Impossible d'accéder à %s"
|
||||
@@ -798,9 +799,6 @@ msgstr ""
|
||||
msgid "File system"
|
||||
msgstr "Système de fichier"
|
||||
|
||||
msgid "OneDrive"
|
||||
msgstr "OneDrive"
|
||||
|
||||
msgid "Text editor"
|
||||
msgstr "Éditeur de texte"
|
||||
|
||||
@@ -847,13 +845,13 @@ msgstr "%d heure"
|
||||
msgid "%d hours"
|
||||
msgstr "%d heures"
|
||||
|
||||
msgid "Show advanced options"
|
||||
msgstr "Montrer les options avancées"
|
||||
|
||||
#, fuzzy
|
||||
msgid "Automatically update the application"
|
||||
msgstr "Quitter le logiciel."
|
||||
|
||||
msgid "Show advanced options"
|
||||
msgstr "Montrer les options avancées"
|
||||
|
||||
msgid "Sync status (synced items / total items)"
|
||||
msgstr "Status de la synchronisation (objets synchro. / total)"
|
||||
|
||||
@@ -885,6 +883,10 @@ msgstr ""
|
||||
"Ce carnet ne contient aucune note. Créez-en une en appuyant sur le bouton "
|
||||
"(+)."
|
||||
|
||||
#, fuzzy
|
||||
msgid "Delete these notes?"
|
||||
msgstr "Supprimer la note ?"
|
||||
|
||||
msgid "Log"
|
||||
msgstr "Journal"
|
||||
|
||||
@@ -894,6 +896,14 @@ msgstr "État"
|
||||
msgid "Export Debug Report"
|
||||
msgstr "Exporter rapport de débogage"
|
||||
|
||||
#, fuzzy
|
||||
msgid "Move to notebook..."
|
||||
msgstr "Déplacer la note vers un carnet."
|
||||
|
||||
#, fuzzy, javascript-format
|
||||
msgid "Move %d notes to notebook \"%s\"?"
|
||||
msgstr "Déplacer la note vers un carnet."
|
||||
|
||||
msgid "Cancel synchronisation"
|
||||
msgstr "Annuler synchronisation"
|
||||
|
||||
@@ -962,6 +972,13 @@ msgstr ""
|
||||
msgid "Welcome"
|
||||
msgstr "Bienvenue"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "Please set the \"sync.2.path\" config value to the desired "
|
||||
#~ "synchronisation destination."
|
||||
#~ msgstr ""
|
||||
#~ "Veuillez attribuer une valeur au paramètre de configuration \"sync.2.path"
|
||||
#~ "\" pour indiquer le dossier où devra se faire la synchronisation."
|
||||
|
||||
#~ msgid "Seach:"
|
||||
#~ msgstr "Chercher :"
|
||||
|
||||
|
||||
@@ -568,12 +568,15 @@ msgstr ""
|
||||
msgid "Add or remove tags"
|
||||
msgstr ""
|
||||
|
||||
msgid "Switch between note and to-do"
|
||||
msgid "Switch between note and to-do type"
|
||||
msgstr ""
|
||||
|
||||
msgid "Delete"
|
||||
msgstr ""
|
||||
|
||||
msgid "Delete notes?"
|
||||
msgstr ""
|
||||
|
||||
msgid "No notes in here. Create one by clicking on \"New note\"."
|
||||
msgstr ""
|
||||
|
||||
@@ -628,6 +631,9 @@ msgstr ""
|
||||
msgid "Unknown flag: %s"
|
||||
msgstr ""
|
||||
|
||||
msgid "OneDrive"
|
||||
msgstr ""
|
||||
|
||||
#, javascript-format
|
||||
msgid "Unknown log level: %s"
|
||||
msgstr ""
|
||||
@@ -641,11 +647,6 @@ msgid ""
|
||||
"synchronisation again may fix the problem."
|
||||
msgstr ""
|
||||
|
||||
msgid ""
|
||||
"Please set the \"sync.2.path\" config value to the desired synchronisation "
|
||||
"destination."
|
||||
msgstr ""
|
||||
|
||||
#, javascript-format
|
||||
msgid "Cannot access %s"
|
||||
msgstr ""
|
||||
@@ -737,9 +738,6 @@ msgstr ""
|
||||
msgid "File system"
|
||||
msgstr ""
|
||||
|
||||
msgid "OneDrive"
|
||||
msgstr ""
|
||||
|
||||
msgid "Text editor"
|
||||
msgstr ""
|
||||
|
||||
@@ -784,10 +782,10 @@ msgstr ""
|
||||
msgid "%d hours"
|
||||
msgstr ""
|
||||
|
||||
msgid "Show advanced options"
|
||||
msgid "Automatically update the application"
|
||||
msgstr ""
|
||||
|
||||
msgid "Automatically update the application"
|
||||
msgid "Show advanced options"
|
||||
msgstr ""
|
||||
|
||||
msgid "Sync status (synced items / total items)"
|
||||
@@ -819,6 +817,9 @@ msgstr ""
|
||||
msgid "There are currently no notes. Create one by clicking on the (+) button."
|
||||
msgstr ""
|
||||
|
||||
msgid "Delete these notes?"
|
||||
msgstr ""
|
||||
|
||||
msgid "Log"
|
||||
msgstr ""
|
||||
|
||||
@@ -828,6 +829,13 @@ msgstr ""
|
||||
msgid "Export Debug Report"
|
||||
msgstr ""
|
||||
|
||||
msgid "Move to notebook..."
|
||||
msgstr ""
|
||||
|
||||
#, javascript-format
|
||||
msgid "Move %d notes to notebook \"%s\"?"
|
||||
msgstr ""
|
||||
|
||||
msgid "Cancel synchronisation"
|
||||
msgstr ""
|
||||
|
||||
|
||||
@@ -30,8 +30,6 @@ const logDir = __dirname + '/../tests/logs';
|
||||
fs.mkdirpSync(logDir, 0o755);
|
||||
|
||||
const syncTargetId_ = Setting.SYNC_TARGET_MEMORY;
|
||||
//const syncTargetId_ = Setting.SYNC_TARGET_FILESYSTEM;
|
||||
//const syncTargetId_ = Setting.SYNC_TARGET_ONEDRIVE;
|
||||
const syncDir = __dirname + '/../tests/sync';
|
||||
|
||||
const sleepTime = syncTargetId_ == Setting.SYNC_TARGET_FILESYSTEM ? 1001 : 400;
|
||||
|
||||
Reference in New Issue
Block a user