Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,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
Expand Down
4 changes: 2 additions & 2 deletions packages/app-desktop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions packages/app-desktop/utils/restartInSafeModeFromMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/default-plugins/pluginRepositories.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"io.github.jackgruber.backup": {
"cloneUrl": "https://github.com/JackGruber/joplin-plugin-backup.git",
"branch": "master",
"commit": "bd49c665bf60c1e0dd9b9862b2ba69cad3d4c9ae"
"commit": "2d814a5466604daced108331d14aedf8e8414d62"
}
}
5 changes: 3 additions & 2 deletions packages/lib/BaseApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions packages/lib/determineBaseAppDirs.ts
Original file line number Diff line number Diff line change
@@ -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'),
};
};
16 changes: 0 additions & 16 deletions packages/lib/determineProfileDir.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/lib/models/Setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export interface Constants {
pluginDataDir: string;
cacheDir: string;
pluginDir: string;
homeDir: string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that homeDir is the best name for this setting...

Currently, homeDir points to os.homedir() only when not using the portable application (or the --profile flag).

flagOpenDevTools: boolean;
syncVersion: number;
startupDevPlugins: string[];
Expand Down Expand Up @@ -303,6 +304,7 @@ class Setting extends BaseModel {
pluginDataDir: '',
cacheDir: '',
pluginDir: '',
homeDir: '',
flagOpenDevTools: false,
syncVersion: 3,
startupDevPlugins: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/services/plugins/PluginService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface Plugins {
}

export interface SettingAndValue {
[settingName: string]: string;
[settingName: string]: string|number|boolean;
}

export interface DefaultPluginSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading