2022-04-11 17:49:32 +02:00
|
|
|
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';
|
2022-04-20 18:34:58 +02:00
|
|
|
import restart from '../services/restart';
|
2022-04-11 17:49:32 +02:00
|
|
|
|
|
|
|
export const declaration: CommandDeclaration = {
|
|
|
|
name: 'switchProfile',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const runtime = (): CommandRuntime => {
|
|
|
|
return {
|
2022-04-16 16:04:06 +02:00
|
|
|
execute: async (context: CommandContext, profileId: string) => {
|
2022-04-11 17:49:32 +02:00
|
|
|
const currentConfig = context.state.profileConfig;
|
2022-04-16 16:04:06 +02:00
|
|
|
if (currentConfig.currentProfileId === profileId) return;
|
2022-04-11 17:49:32 +02:00
|
|
|
|
|
|
|
const newConfig: ProfileConfig = {
|
|
|
|
...currentConfig,
|
2022-04-16 16:04:06 +02:00
|
|
|
currentProfileId: profileId,
|
2022-04-11 17:49:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
await saveProfileConfig(`${Setting.value('rootProfileDir')}/profiles.json`, newConfig);
|
2022-04-20 18:34:58 +02:00
|
|
|
await restart(false);
|
2022-04-11 17:49:32 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|