2023-10-31 17:05:28 +02:00
|
|
|
import Setting from '@joplin/lib/models/Setting';
|
|
|
|
import bridge from '../bridge';
|
|
|
|
import processStartFlags from '@joplin/lib/utils/processStartFlags';
|
2024-02-07 20:04:29 +02:00
|
|
|
import { safeModeFlagFilename } from '@joplin/lib/BaseApplication';
|
2023-10-31 17:05:28 +02:00
|
|
|
import initProfile from '@joplin/lib/services/profileConfig/initProfile';
|
|
|
|
import { writeFile } from 'fs-extra';
|
|
|
|
import { join } from 'path';
|
2024-02-22 23:30:21 +02:00
|
|
|
import determineBaseAppDirs from '@joplin/lib/determineBaseAppDirs';
|
2023-10-31 17:05:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
const restartInSafeModeFromMain = async () => {
|
|
|
|
// Only set constants here -- the main process doesn't have easy access (without loading
|
|
|
|
// a large amount of other code) to the database.
|
2024-02-07 20:04:29 +02:00
|
|
|
const appName = bridge().appName();
|
2023-10-31 17:05:28 +02:00
|
|
|
Setting.setConstant('appId', `net.cozic.${appName}`);
|
|
|
|
Setting.setConstant('appType', 'desktop');
|
|
|
|
Setting.setConstant('appName', appName);
|
|
|
|
|
|
|
|
// Load just enough for us to write a file in the profile directory
|
|
|
|
const { shimInit } = require('@joplin/lib/shim-init-node.js');
|
|
|
|
shimInit({});
|
|
|
|
|
|
|
|
const startFlags = await processStartFlags(bridge().processArgv());
|
2024-02-22 23:30:21 +02:00
|
|
|
const { rootProfileDir } = determineBaseAppDirs(startFlags.matched.profileDir, appName);
|
2023-10-31 17:05:28 +02:00
|
|
|
const { profileDir } = await initProfile(rootProfileDir);
|
|
|
|
|
|
|
|
// We can't access the database, so write to a file instead.
|
|
|
|
const safeModeFlagFile = join(profileDir, safeModeFlagFilename);
|
|
|
|
await writeFile(safeModeFlagFile, 'true', 'utf8');
|
|
|
|
|
|
|
|
bridge().restart();
|
|
|
|
};
|
|
|
|
|
|
|
|
export default restartInSafeModeFromMain;
|