From ab959623aa423afa4d866821bcbd6656703fffb1 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 28 Dec 2017 19:14:03 +0000 Subject: [PATCH] CLI: Fixes #117: 'edit' command raising error in shell mode --- CliClient/app/app-gui.js | 8 ++++++++ CliClient/app/app.js | 5 ++++- CliClient/app/command-edit.js | 4 ++-- ReactNativeClient/lib/joplin-database.js | 7 +++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CliClient/app/app-gui.js b/CliClient/app/app-gui.js index 39ec44a8b..7f501267f 100644 --- a/CliClient/app/app-gui.js +++ b/CliClient/app/app-gui.js @@ -80,6 +80,14 @@ class AppGui { await this.renderer_.renderRoot(); } + termSaveState() { + return this.term().saveState(); + } + + termRestoreState(state) { + return this.term().restoreState(state); + } + prompt(initialText = '', promptString = ':') { return this.widget('statusBar').prompt(initialText, promptString); } diff --git a/CliClient/app/app.js b/CliClient/app/app.js index 04db4c663..29107cbe0 100644 --- a/CliClient/app/app.js +++ b/CliClient/app/app.js @@ -283,7 +283,10 @@ class Application extends BaseApplication { exit: () => {}, showModalOverlay: (text) => {}, hideModalOverlay: () => {}, - stdoutMaxWidth: () => { return 78; } + stdoutMaxWidth: () => { return 78; }, + forceRender: () => {}, + termSaveState: () => {}, + termRestoreState: (state) => {}, }; } diff --git a/CliClient/app/command-edit.js b/CliClient/app/command-edit.js index 9fc7fec7e..6589b5f40 100644 --- a/CliClient/app/command-edit.js +++ b/CliClient/app/command-edit.js @@ -76,12 +76,12 @@ class Command extends BaseCommand { app().gui().showModalOverlay(_('Starting to edit note. Close the editor to get back to the prompt.')); await app().gui().forceRender(); - const termState = app().gui().term().saveState(); + const termState = app().gui().termSaveState(); const spawnSync = require('child_process').spawnSync; spawnSync(editorPath, editorArgs, { stdio: 'inherit' }); - app().gui().term().restoreState(termState); + app().gui().termRestoreState(termState); app().gui().hideModalOverlay(); app().gui().forceRender(); diff --git a/ReactNativeClient/lib/joplin-database.js b/ReactNativeClient/lib/joplin-database.js index dfe0e2e6a..5f78f2a89 100644 --- a/ReactNativeClient/lib/joplin-database.js +++ b/ReactNativeClient/lib/joplin-database.js @@ -205,10 +205,13 @@ class JoplinDatabase extends Database { const existingDatabaseVersions = [0, 1, 2, 3, 4, 5, 6, 7, 8]; let currentVersionIndex = existingDatabaseVersions.indexOf(fromVersion); + + if (currentVersionIndex < 0) throw new Error('Unknown profile version. Most likely this is an old version of Joplin, while the profile was created by a newer version. Please upgrade Joplin at http://joplin.cozic.net and try again.'); + // currentVersionIndex < 0 if for the case where an old version of Joplin used with a newer // version of the database, so that migration is not run in this case. - if (currentVersionIndex == existingDatabaseVersions.length - 1 || currentVersionIndex < 0) return false; - + if (currentVersionIndex == existingDatabaseVersions.length - 1) return false; + while (currentVersionIndex < existingDatabaseVersions.length - 1) { const targetVersion = existingDatabaseVersions[currentVersionIndex + 1]; this.logger().info("Converting database to version " + targetVersion);