2022-04-11 17:49:32 +02:00
|
|
|
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
|
|
|
import { _ } from '@joplin/lib/locale';
|
|
|
|
import { createNewProfile, saveProfileConfig } from '@joplin/lib/services/profileConfig';
|
|
|
|
import Setting from '@joplin/lib/models/Setting';
|
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: 'addProfile',
|
|
|
|
label: () => _('Create new profile...'),
|
|
|
|
};
|
|
|
|
|
|
|
|
export const runtime = (comp: any): CommandRuntime => {
|
|
|
|
return {
|
|
|
|
execute: async (context: CommandContext) => {
|
|
|
|
comp.setState({
|
|
|
|
promptOptions: {
|
|
|
|
label: _('Profile name:'),
|
|
|
|
buttons: ['create', 'cancel'],
|
|
|
|
value: '',
|
|
|
|
onClose: async (answer: string) => {
|
|
|
|
if (answer) {
|
2022-04-16 16:04:06 +02:00
|
|
|
const { newConfig, newProfile } = createNewProfile(context.state.profileConfig, answer);
|
|
|
|
newConfig.currentProfileId = newProfile.id;
|
2022-04-11 17:49:32 +02:00
|
|
|
await saveProfileConfig(`${Setting.value('rootProfileDir')}/profiles.json`, newConfig);
|
2023-06-08 15:43:47 +02:00
|
|
|
await restart();
|
2022-04-11 17:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
comp.setState({ promptOptions: null });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|