Skip to content

Commit 11276d7

Browse files
committed
Migrations: Remove empty "commands" field from settings completely.
1 parent b2bfdc4 commit 11276d7

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/Migrations.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export async function RunMigrations(plugin: ShellCommandsPlugin) {
55
let save = MigrateCommandsToShellCommands(plugin);
66
save ||= MigrateShellCommandToPlatforms(plugin);
77
save ||= EnsureShellCommandsHaveAllFields(plugin);
8+
save ||= DeleteEmptyCommandsField(plugin);
89
if (save) {
910
// Only save if there were changes to configuration.
1011
console.log("Saving migrations...")
@@ -14,6 +15,9 @@ export async function RunMigrations(plugin: ShellCommandsPlugin) {
1415
}
1516

1617
function MigrateCommandsToShellCommands(plugin: ShellCommandsPlugin) {
18+
if (undefined === plugin.settings.commands) {
19+
return false;
20+
}
1721
let count_shell_commands = plugin.settings.commands.length;
1822
let save = false;
1923
if (0 < count_shell_commands) {
@@ -99,4 +103,21 @@ function MigrateShellCommandToPlatforms(plugin: ShellCommandsPlugin) {
99103
}
100104
}
101105
return save;
106+
}
107+
108+
/**
109+
* Can be removed in 1.0.0.
110+
*
111+
* @param plugin
112+
* @constructor
113+
*/
114+
function DeleteEmptyCommandsField(plugin: ShellCommandsPlugin) {
115+
let save = false;
116+
if (undefined !== plugin.settings.commands) {
117+
if (plugin.settings.commands.length === 0) {
118+
delete plugin.settings.commands;
119+
save = true;
120+
}
121+
}
122+
return save;
102123
}

src/settings/ShellCommandsPluginSettings.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface ShellCommandsPluginSettings {
1111

1212
// Legacy:
1313
/** @deprecated Use shell_commands object instead of this array. From now on, this array can be used only for migrating old configuration to shell_commands.*/
14-
commands: string[];
14+
commands?: string[];
1515
}
1616

1717
export const DEFAULT_SETTINGS: ShellCommandsPluginSettings = {
@@ -21,9 +21,6 @@ export const DEFAULT_SETTINGS: ShellCommandsPluginSettings = {
2121
shell_commands: {},
2222
error_message_duration: 20,
2323
notification_message_duration: 10,
24-
25-
// Legacy:
26-
commands: [] // Deprecated, but must be present in the default values as long as migrating from commands to shell_commands is supported.
2724
}
2825

2926
/**

0 commit comments

Comments
 (0)