diff --git a/.eslintignore b/.eslintignore index 95e5bf976..035069d5c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -685,7 +685,7 @@ packages/lib/components/shared/side-menu-shared.js packages/lib/database-driver-better-sqlite.js packages/lib/database.js packages/lib/debug/DebugService.js -packages/lib/determineProfileDir.js +packages/lib/determineBaseAppDirs.js packages/lib/dom.js packages/lib/errorUtils.js packages/lib/errors.js diff --git a/.gitignore b/.gitignore index ac6bc1607..a3bcf4cc5 100644 --- a/.gitignore +++ b/.gitignore @@ -665,7 +665,7 @@ packages/lib/components/shared/side-menu-shared.js packages/lib/database-driver-better-sqlite.js packages/lib/database.js packages/lib/debug/DebugService.js -packages/lib/determineProfileDir.js +packages/lib/determineBaseAppDirs.js packages/lib/dom.js packages/lib/errorUtils.js packages/lib/errors.js diff --git a/packages/app-desktop/main.js b/packages/app-desktop/main.js index 1b0ab7d85..415ea49b0 100644 --- a/packages/app-desktop/main.js +++ b/packages/app-desktop/main.js @@ -10,7 +10,7 @@ const FsDriverNode = require('@joplin/lib/fs-driver-node').default; const envFromArgs = require('@joplin/lib/envFromArgs'); const packageInfo = require('./packageInfo.js'); const { isCallbackUrl } = require('@joplin/lib/callbackUrlUtils'); -const determineProfileDir = require('@joplin/lib/determineProfileDir').default; +const determineBaseAppDirs = require('@joplin/lib/determineBaseAppDirs').default; // Electron takes the application name from package.json `name` and // displays this in the tray icon toolip and message box titles, however in @@ -45,7 +45,7 @@ const isDebugMode = !!process.argv && process.argv.indexOf('--debug') >= 0; const appId = `net.cozic.joplin${env === 'dev' ? 'dev' : ''}-desktop`; let appName = env === 'dev' ? 'joplindev' : 'joplin'; if (appId.indexOf('-desktop') >= 0) appName += '-desktop'; -const rootProfileDir = determineProfileDir(profileFromArgs, appName); +const { rootProfileDir } = determineBaseAppDirs(profileFromArgs, appName); const settingsPath = `${rootProfileDir}/settings.json`; let autoUploadCrashDumps = false; diff --git a/packages/app-desktop/utils/restartInSafeModeFromMain.ts b/packages/app-desktop/utils/restartInSafeModeFromMain.ts index 32f994e78..7b65225b0 100644 --- a/packages/app-desktop/utils/restartInSafeModeFromMain.ts +++ b/packages/app-desktop/utils/restartInSafeModeFromMain.ts @@ -5,7 +5,7 @@ import { safeModeFlagFilename } from '@joplin/lib/BaseApplication'; import initProfile from '@joplin/lib/services/profileConfig/initProfile'; import { writeFile } from 'fs-extra'; import { join } from 'path'; -import determineProfileDir from '@joplin/lib/determineProfileDir'; +import determineBaseAppDirs from '@joplin/lib/determineBaseAppDirs'; const restartInSafeModeFromMain = async () => { @@ -21,7 +21,7 @@ const restartInSafeModeFromMain = async () => { shimInit({}); const startFlags = await processStartFlags(bridge().processArgv()); - const rootProfileDir = determineProfileDir(startFlags.matched.profileDir, appName); + const { rootProfileDir } = determineBaseAppDirs(startFlags.matched.profileDir, appName); const { profileDir } = await initProfile(rootProfileDir); // We can't access the database, so write to a file instead. diff --git a/packages/default-plugins/pluginRepositories.json b/packages/default-plugins/pluginRepositories.json index 9fc027155..2aca406e3 100644 --- a/packages/default-plugins/pluginRepositories.json +++ b/packages/default-plugins/pluginRepositories.json @@ -2,6 +2,6 @@ "io.github.jackgruber.backup": { "cloneUrl": "https://github.com/JackGruber/joplin-plugin-backup.git", "branch": "master", - "commit": "bd49c665bf60c1e0dd9b9862b2ba69cad3d4c9ae" + "commit": "2d814a5466604daced108331d14aedf8e8414d62" } } diff --git a/packages/lib/BaseApplication.ts b/packages/lib/BaseApplication.ts index 8df9cdd60..fc6b472da 100644 --- a/packages/lib/BaseApplication.ts +++ b/packages/lib/BaseApplication.ts @@ -61,7 +61,7 @@ import RotatingLogs from './RotatingLogs'; import { NoteEntity } from './services/database/types'; import { join } from 'path'; import processStartFlags from './utils/processStartFlags'; -import determineProfileDir from './determineProfileDir'; +import determineProfileAndBaseDir from './determineBaseAppDirs'; const appLogger: LoggerWrapper = Logger.create('App'); @@ -639,7 +639,7 @@ export default class BaseApplication { // https://immerjs.github.io/immer/docs/freezing setAutoFreeze(initArgs.env === 'dev'); - const rootProfileDir = options.rootProfileDir ? options.rootProfileDir : determineProfileDir(initArgs.profileDir, appName); + const { rootProfileDir, homeDir } = determineProfileAndBaseDir(options.rootProfileDir ?? initArgs.profileDir, appName); const { profileDir, profileConfig, isSubProfile } = await initProfile(rootProfileDir); this.profileConfig_ = profileConfig; @@ -655,6 +655,7 @@ export default class BaseApplication { Setting.setConstant('pluginDataDir', `${profileDir}/plugin-data`); Setting.setConstant('cacheDir', cacheDir); Setting.setConstant('pluginDir', `${rootProfileDir}/plugins`); + Setting.setConstant('homeDir', homeDir); SyncTargetRegistry.addClass(SyncTargetNone); SyncTargetRegistry.addClass(SyncTargetFilesystem); diff --git a/packages/lib/determineBaseAppDirs.ts b/packages/lib/determineBaseAppDirs.ts new file mode 100644 index 000000000..92198e09e --- /dev/null +++ b/packages/lib/determineBaseAppDirs.ts @@ -0,0 +1,23 @@ +import { homedir } from 'os'; +import { toSystemSlashes } from './path-utils'; + +export default (profileFromArgs: string, appName: string) => { + let profileDir = ''; + let homeDir = ''; + + if (profileFromArgs) { + profileDir = profileFromArgs; + homeDir = profileDir; + } else if (process && process.env && process.env.PORTABLE_EXECUTABLE_DIR) { + profileDir = `${process.env.PORTABLE_EXECUTABLE_DIR}/JoplinProfile`; + homeDir = process.env.PORTABLE_EXECUTABLE_DIR; + } else { + profileDir = `${homedir()}/.config/${appName}`; + homeDir = homedir(); + } + + return { + rootProfileDir: toSystemSlashes(profileDir, 'linux'), + homeDir: toSystemSlashes(homeDir, 'linux'), + }; +}; diff --git a/packages/lib/determineProfileDir.ts b/packages/lib/determineProfileDir.ts deleted file mode 100644 index b37e576fb..000000000 --- a/packages/lib/determineProfileDir.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { homedir } from 'os'; -import { toSystemSlashes } from './path-utils'; - -export default (profileFromArgs: string, appName: string) => { - let output = ''; - - if (profileFromArgs) { - output = profileFromArgs; - } else if (process && process.env && process.env.PORTABLE_EXECUTABLE_DIR) { - output = `${process.env.PORTABLE_EXECUTABLE_DIR}/JoplinProfile`; - } else { - output = `${homedir()}/.config/${appName}`; - } - - return toSystemSlashes(output, 'linux'); -}; diff --git a/packages/lib/models/Setting.ts b/packages/lib/models/Setting.ts index 7cb3fbcd8..27ecf1e6b 100644 --- a/packages/lib/models/Setting.ts +++ b/packages/lib/models/Setting.ts @@ -146,6 +146,7 @@ export interface Constants { pluginDataDir: string; cacheDir: string; pluginDir: string; + homeDir: string; flagOpenDevTools: boolean; syncVersion: number; startupDevPlugins: string[]; @@ -303,6 +304,7 @@ class Setting extends BaseModel { pluginDataDir: '', cacheDir: '', pluginDir: '', + homeDir: '', flagOpenDevTools: false, syncVersion: 3, startupDevPlugins: [], diff --git a/packages/lib/services/plugins/PluginService.ts b/packages/lib/services/plugins/PluginService.ts index 6784c0338..cfbee5d90 100644 --- a/packages/lib/services/plugins/PluginService.ts +++ b/packages/lib/services/plugins/PluginService.ts @@ -29,7 +29,7 @@ export interface Plugins { } export interface SettingAndValue { - [settingName: string]: string; + [settingName: string]: string|number|boolean; } export interface DefaultPluginSettings { diff --git a/packages/lib/services/plugins/defaultPlugins/desktopDefaultPluginsInfo.ts b/packages/lib/services/plugins/defaultPlugins/desktopDefaultPluginsInfo.ts index ff7daae62..2696280c7 100644 --- a/packages/lib/services/plugins/defaultPlugins/desktopDefaultPluginsInfo.ts +++ b/packages/lib/services/plugins/defaultPlugins/desktopDefaultPluginsInfo.ts @@ -6,7 +6,8 @@ const getDefaultPluginsInfo = (): DefaultPluginsInfo => { const defaultPlugins = { 'io.github.jackgruber.backup': { settings: { - 'path': `${Setting.value('profileDir')}`, + 'path': `${Setting.value('homeDir')}`, + 'createSubfolderPerProfile': true, }, // Joplin Portable is more likely to run on a device with low write speeds