From 15766d18f567c2ed01d449eb4175e93ee335776c Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 11 Aug 2021 16:23:37 +0100 Subject: [PATCH] Cli: Fixed version command so that it does not require the keychain --- packages/app-cli/app/app.js | 10 +++++++++- packages/app-cli/app/command-version.js | 5 ++--- packages/lib/BaseApplication.ts | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/app-cli/app/app.js b/packages/app-cli/app/app.js index 461bd00c2..28472819d 100644 --- a/packages/app-cli/app/app.js +++ b/packages/app-cli/app/app.js @@ -402,8 +402,16 @@ class Application extends BaseApplication { } } + // We need this special case here because by the time the `version` command + // runs, the keychain has already been setup. + checkIfKeychainEnabled(argv) { + return argv.indexOf('version') < 0; + } + async start(argv) { - argv = await super.start(argv); + const keychainEnabled = this.checkIfKeychainEnabled(argv); + + argv = await super.start(argv, { keychainEnabled }); cliUtils.setStdout(object => { return this.stdout(object); diff --git a/packages/app-cli/app/command-version.js b/packages/app-cli/app/command-version.js index 7f5d3df1d..5a2c7ec68 100644 --- a/packages/app-cli/app/command-version.js +++ b/packages/app-cli/app/command-version.js @@ -1,6 +1,6 @@ const { BaseCommand } = require('./base-command.js'); -const Setting = require('@joplin/lib/models/Setting').default; const { _ } = require('@joplin/lib/locale'); +const versionInfo = require('@joplin/lib/versionInfo').default; class Command extends BaseCommand { usage() { @@ -12,8 +12,7 @@ class Command extends BaseCommand { } async action() { - const p = require('./package.json'); - this.stdout(_('%s %s (%s)', p.name, p.version, Setting.value('env'))); + this.stdout(versionInfo(require('./package.json')).message); } } diff --git a/packages/lib/BaseApplication.ts b/packages/lib/BaseApplication.ts index 8d3551994..cd8005fbd 100644 --- a/packages/lib/BaseApplication.ts +++ b/packages/lib/BaseApplication.ts @@ -4,6 +4,7 @@ import shim from './shim'; import BaseService from './services/BaseService'; import reducer, { setStore } from './reducer'; import KeychainServiceDriver from './services/keychain/KeychainServiceDriver.node'; +import KeychainServiceDriverDummy from './services/keychain/KeychainServiceDriver.dummy'; import { _, setLocale } from './locale'; import KvStore from './services/KvStore'; import SyncTargetJoplinServer from './SyncTargetJoplinServer'; @@ -55,6 +56,10 @@ const appLogger: LoggerWrapper = Logger.create('App'); // const ntpClient = require('./vendor/ntp-client'); // ntpClient.dgram = require('dgram'); +interface StartOptions { + keychainEnabled?: boolean; +} + export default class BaseApplication { private eventEmitter_: any; @@ -655,7 +660,12 @@ export default class BaseApplication { return toSystemSlashes(output, 'linux'); } - async start(argv: string[]): Promise { + async start(argv: string[], options: StartOptions = null): Promise { + options = { + keychainEnabled: true, + ...options, + }; + const startFlags = await this.handleStartFlags_(argv); argv = startFlags.argv; @@ -744,7 +754,7 @@ export default class BaseApplication { reg.setDb(this.database_); BaseModel.setDb(this.database_); - await loadKeychainServiceAndSettings(KeychainServiceDriver); + await loadKeychainServiceAndSettings(options.keychainEnabled ? KeychainServiceDriver : KeychainServiceDriverDummy); await handleSyncStartupOperation(); appLogger.info(`Client ID: ${Setting.value('clientId')}`);