1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-02 12:47:41 +02:00

Desktop: Resolves #9857: Back up to a subdirectory of the home directory by default (#9942)

This commit is contained in:
Henry Heino 2024-02-22 13:30:21 -08:00 committed by GitHub
parent 836e23c082
commit e5e191110c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 38 additions and 27 deletions

View File

@ -685,7 +685,7 @@ packages/lib/components/shared/side-menu-shared.js
packages/lib/database-driver-better-sqlite.js packages/lib/database-driver-better-sqlite.js
packages/lib/database.js packages/lib/database.js
packages/lib/debug/DebugService.js packages/lib/debug/DebugService.js
packages/lib/determineProfileDir.js packages/lib/determineBaseAppDirs.js
packages/lib/dom.js packages/lib/dom.js
packages/lib/errorUtils.js packages/lib/errorUtils.js
packages/lib/errors.js packages/lib/errors.js

2
.gitignore vendored
View File

@ -665,7 +665,7 @@ packages/lib/components/shared/side-menu-shared.js
packages/lib/database-driver-better-sqlite.js packages/lib/database-driver-better-sqlite.js
packages/lib/database.js packages/lib/database.js
packages/lib/debug/DebugService.js packages/lib/debug/DebugService.js
packages/lib/determineProfileDir.js packages/lib/determineBaseAppDirs.js
packages/lib/dom.js packages/lib/dom.js
packages/lib/errorUtils.js packages/lib/errorUtils.js
packages/lib/errors.js packages/lib/errors.js

View File

@ -10,7 +10,7 @@ const FsDriverNode = require('@joplin/lib/fs-driver-node').default;
const envFromArgs = require('@joplin/lib/envFromArgs'); const envFromArgs = require('@joplin/lib/envFromArgs');
const packageInfo = require('./packageInfo.js'); const packageInfo = require('./packageInfo.js');
const { isCallbackUrl } = require('@joplin/lib/callbackUrlUtils'); 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 // Electron takes the application name from package.json `name` and
// displays this in the tray icon toolip and message box titles, however in // 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`; const appId = `net.cozic.joplin${env === 'dev' ? 'dev' : ''}-desktop`;
let appName = env === 'dev' ? 'joplindev' : 'joplin'; let appName = env === 'dev' ? 'joplindev' : 'joplin';
if (appId.indexOf('-desktop') >= 0) appName += '-desktop'; if (appId.indexOf('-desktop') >= 0) appName += '-desktop';
const rootProfileDir = determineProfileDir(profileFromArgs, appName); const { rootProfileDir } = determineBaseAppDirs(profileFromArgs, appName);
const settingsPath = `${rootProfileDir}/settings.json`; const settingsPath = `${rootProfileDir}/settings.json`;
let autoUploadCrashDumps = false; let autoUploadCrashDumps = false;

View File

@ -5,7 +5,7 @@ import { safeModeFlagFilename } from '@joplin/lib/BaseApplication';
import initProfile from '@joplin/lib/services/profileConfig/initProfile'; import initProfile from '@joplin/lib/services/profileConfig/initProfile';
import { writeFile } from 'fs-extra'; import { writeFile } from 'fs-extra';
import { join } from 'path'; import { join } from 'path';
import determineProfileDir from '@joplin/lib/determineProfileDir'; import determineBaseAppDirs from '@joplin/lib/determineBaseAppDirs';
const restartInSafeModeFromMain = async () => { const restartInSafeModeFromMain = async () => {
@ -21,7 +21,7 @@ const restartInSafeModeFromMain = async () => {
shimInit({}); shimInit({});
const startFlags = await processStartFlags(bridge().processArgv()); 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); const { profileDir } = await initProfile(rootProfileDir);
// We can't access the database, so write to a file instead. // We can't access the database, so write to a file instead.

View File

@ -2,6 +2,6 @@
"io.github.jackgruber.backup": { "io.github.jackgruber.backup": {
"cloneUrl": "https://github.com/JackGruber/joplin-plugin-backup.git", "cloneUrl": "https://github.com/JackGruber/joplin-plugin-backup.git",
"branch": "master", "branch": "master",
"commit": "bd49c665bf60c1e0dd9b9862b2ba69cad3d4c9ae" "commit": "2d814a5466604daced108331d14aedf8e8414d62"
} }
} }

View File

@ -61,7 +61,7 @@ import RotatingLogs from './RotatingLogs';
import { NoteEntity } from './services/database/types'; import { NoteEntity } from './services/database/types';
import { join } from 'path'; import { join } from 'path';
import processStartFlags from './utils/processStartFlags'; import processStartFlags from './utils/processStartFlags';
import determineProfileDir from './determineProfileDir'; import determineProfileAndBaseDir from './determineBaseAppDirs';
const appLogger: LoggerWrapper = Logger.create('App'); const appLogger: LoggerWrapper = Logger.create('App');
@ -639,7 +639,7 @@ export default class BaseApplication {
// https://immerjs.github.io/immer/docs/freezing // https://immerjs.github.io/immer/docs/freezing
setAutoFreeze(initArgs.env === 'dev'); 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); const { profileDir, profileConfig, isSubProfile } = await initProfile(rootProfileDir);
this.profileConfig_ = profileConfig; this.profileConfig_ = profileConfig;
@ -655,6 +655,7 @@ export default class BaseApplication {
Setting.setConstant('pluginDataDir', `${profileDir}/plugin-data`); Setting.setConstant('pluginDataDir', `${profileDir}/plugin-data`);
Setting.setConstant('cacheDir', cacheDir); Setting.setConstant('cacheDir', cacheDir);
Setting.setConstant('pluginDir', `${rootProfileDir}/plugins`); Setting.setConstant('pluginDir', `${rootProfileDir}/plugins`);
Setting.setConstant('homeDir', homeDir);
SyncTargetRegistry.addClass(SyncTargetNone); SyncTargetRegistry.addClass(SyncTargetNone);
SyncTargetRegistry.addClass(SyncTargetFilesystem); SyncTargetRegistry.addClass(SyncTargetFilesystem);

View File

@ -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'),
};
};

View File

@ -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');
};

View File

@ -146,6 +146,7 @@ export interface Constants {
pluginDataDir: string; pluginDataDir: string;
cacheDir: string; cacheDir: string;
pluginDir: string; pluginDir: string;
homeDir: string;
flagOpenDevTools: boolean; flagOpenDevTools: boolean;
syncVersion: number; syncVersion: number;
startupDevPlugins: string[]; startupDevPlugins: string[];
@ -303,6 +304,7 @@ class Setting extends BaseModel {
pluginDataDir: '', pluginDataDir: '',
cacheDir: '', cacheDir: '',
pluginDir: '', pluginDir: '',
homeDir: '',
flagOpenDevTools: false, flagOpenDevTools: false,
syncVersion: 3, syncVersion: 3,
startupDevPlugins: [], startupDevPlugins: [],

View File

@ -29,7 +29,7 @@ export interface Plugins {
} }
export interface SettingAndValue { export interface SettingAndValue {
[settingName: string]: string; [settingName: string]: string|number|boolean;
} }
export interface DefaultPluginSettings { export interface DefaultPluginSettings {

View File

@ -6,7 +6,8 @@ const getDefaultPluginsInfo = (): DefaultPluginsInfo => {
const defaultPlugins = { const defaultPlugins = {
'io.github.jackgruber.backup': { 'io.github.jackgruber.backup': {
settings: { 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 // Joplin Portable is more likely to run on a device with low write speeds