1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-13 00:10:37 +02:00

Desktop: Resolves #591: Add support for multiple profiles (#6385)

This commit is contained in:
Laurent
2022-04-11 16:49:32 +01:00
committed by GitHub
parent 58bf93a112
commit 6458ad0540
32 changed files with 919 additions and 154 deletions

View File

@ -0,0 +1,19 @@
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
import Setting from '../../lib/models/Setting';
import { openFileWithExternalEditor } from '../../lib/services/ExternalEditWatcher/utils';
import bridge from '../services/bridge';
import { _ } from '@joplin/lib/locale';
export const declaration: CommandDeclaration = {
name: 'editProfileConfig',
label: () => _('Edit profile configuration...'),
};
export const runtime = (): CommandRuntime => {
return {
execute: async (_context: CommandContext) => {
await openFileWithExternalEditor(`${Setting.value('rootProfileDir')}/profiles.json`, bridge());
},
enabledCondition: 'hasMultiProfiles',
};
};

View File

@ -1,5 +1,6 @@
// AUTO-GENERATED using `gulp buildCommandIndex`
import * as copyDevCommand from './copyDevCommand';
import * as editProfileConfig from './editProfileConfig';
import * as exportFolders from './exportFolders';
import * as exportNotes from './exportNotes';
import * as focusElement from './focusElement';
@ -8,11 +9,16 @@ import * as replaceMisspelling from './replaceMisspelling';
import * as restoreNoteRevision from './restoreNoteRevision';
import * as startExternalEditing from './startExternalEditing';
import * as stopExternalEditing from './stopExternalEditing';
import * as switchProfile from './switchProfile';
import * as switchProfile1 from './switchProfile1';
import * as switchProfile2 from './switchProfile2';
import * as switchProfile3 from './switchProfile3';
import * as toggleExternalEditing from './toggleExternalEditing';
import * as toggleSafeMode from './toggleSafeMode';
const index:any[] = [
copyDevCommand,
editProfileConfig,
exportFolders,
exportNotes,
focusElement,
@ -21,6 +27,10 @@ const index:any[] = [
restoreNoteRevision,
startExternalEditing,
stopExternalEditing,
switchProfile,
switchProfile1,
switchProfile2,
switchProfile3,
toggleExternalEditing,
toggleSafeMode,
];

View File

@ -0,0 +1,26 @@
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
import Setting from '@joplin/lib/models/Setting';
import { saveProfileConfig } from '@joplin/lib/services/profileConfig';
import { ProfileConfig } from '@joplin/lib/services/profileConfig/types';
import bridge from '../services/bridge';
export const declaration: CommandDeclaration = {
name: 'switchProfile',
};
export const runtime = (): CommandRuntime => {
return {
execute: async (context: CommandContext, profileIndex: number) => {
const currentConfig = context.state.profileConfig;
if (currentConfig.currentProfile === profileIndex) return;
const newConfig: ProfileConfig = {
...currentConfig,
currentProfile: profileIndex,
};
await saveProfileConfig(`${Setting.value('rootProfileDir')}/profiles.json`, newConfig);
bridge().restart();
},
};
};

View File

@ -0,0 +1,15 @@
import CommandService, { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
export const declaration: CommandDeclaration = {
name: 'switchProfile1',
label: () => _('Switch to profile %d', 1),
};
export const runtime = (): CommandRuntime => {
return {
execute: async (_context: CommandContext) => {
await CommandService.instance().execute('switchProfile', 0);
},
};
};

View File

@ -0,0 +1,15 @@
import CommandService, { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
export const declaration: CommandDeclaration = {
name: 'switchProfile2',
label: () => _('Switch to profile %d', 2),
};
export const runtime = (): CommandRuntime => {
return {
execute: async (_context: CommandContext) => {
await CommandService.instance().execute('switchProfile', 1);
},
};
};

View File

@ -0,0 +1,15 @@
import CommandService, { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
export const declaration: CommandDeclaration = {
name: 'switchProfile3',
label: () => _('Switch to profile %d', 3),
};
export const runtime = (): CommandRuntime => {
return {
execute: async (_context: CommandContext) => {
await CommandService.instance().execute('switchProfile', 2);
},
};
};