* @param {Object} options - either undefined, force set or key and password provided * @param {Boolean} [options.force] - if newer version on server available force sync * @param {openpgp.key.Key} [options.key] - key to decrypt and sign sync message * @param {String} [options.password] - pa
(options)
| 42 | * @param {String} [options.password] - password for options.key |
| 43 | */ |
| 44 | async triggerSync(options) { |
| 45 | options = options || {}; |
| 46 | if (this.syncRunning) { |
| 47 | this.repeatSync = options; |
| 48 | return; |
| 49 | } |
| 50 | this.modified = this.keyring.sync.data.modified; |
| 51 | const defaultKey = await this.keyring.getDefaultKey(); |
| 52 | if (!defaultKey) { |
| 53 | return; |
| 54 | } |
| 55 | if (!options.key) { |
| 56 | // if no key provided we take the default key |
| 57 | options.key = defaultKey; |
| 58 | } else { |
| 59 | // check if provided key is default key, otherwise no sync |
| 60 | if (!equalKey(options.key, defaultKey)) { |
| 61 | return; |
| 62 | } |
| 63 | } |
| 64 | if (!(options.force || await this.canUnlockKey('decrypt', options))) { |
| 65 | return; |
| 66 | } |
| 67 | this.syncRunning = true; |
| 68 | // reset modified to detect further modification |
| 69 | this.keyring.sync.data.modified = false; |
| 70 | try { |
| 71 | await this.downloadSyncMessage(options); |
| 72 | if (this.modified) { |
| 73 | if (await this.canUnlockKey('sign', options)) { |
| 74 | await this.uploadSyncMessage(options); |
| 75 | } else { |
| 76 | // upload didn't happen, reset modified flag |
| 77 | this.keyring.sync.data.modified = true; |
| 78 | } |
| 79 | } |
| 80 | await this.keyring.sync.save(); |
| 81 | this.checkRepeat(); |
| 82 | } catch (err) { |
| 83 | console.log('Sync error', err); |
| 84 | if (this.modified || this.keyring.sync.data.modified) { |
| 85 | this.keyring.sync.data.modified = true; |
| 86 | } |
| 87 | this.checkRepeat(); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | checkRepeat() { |
| 92 | this.syncRunning = false; |
no test coverage detected