@@ -22,8 +22,20 @@ export function isEnabled(plugin: string) {
22
22
return pluginConfig !== undefined && pluginConfig . enabled ;
23
23
}
24
24
25
- export function setOptions < T > ( plugin : string , options : T ) {
25
+ /**
26
+ * Set options for a plugin
27
+ * @param plugin Plugin name
28
+ * @param options Options to set
29
+ * @param exclude Options to exclude from the options object
30
+ */
31
+ export function setOptions < T > ( plugin : string , options : T , exclude : string [ ] = [ 'enabled' ] ) {
26
32
const plugins = store . get ( 'plugins' ) as Record < string , T > ;
33
+ // HACK: This is a workaround for preventing changed options from being overwritten
34
+ exclude . forEach ( ( key ) => {
35
+ if ( Object . prototype . hasOwnProperty . call ( options , key ) ) {
36
+ delete options [ key as keyof T ] ;
37
+ }
38
+ } ) ;
27
39
store . set ( 'plugins' , {
28
40
...plugins ,
29
41
[ plugin ] : {
@@ -33,8 +45,8 @@ export function setOptions<T>(plugin: string, options: T) {
33
45
} ) ;
34
46
}
35
47
36
- export function setMenuOptions < T > ( plugin : string , options : T ) {
37
- setOptions ( plugin , options ) ;
48
+ export function setMenuOptions < T > ( plugin : string , options : T , exclude : string [ ] = [ 'enabled' ] ) {
49
+ setOptions ( plugin , options , exclude ) ;
38
50
if ( store . get ( 'options.restartOnConfigChanges' ) ) {
39
51
restart ( ) ;
40
52
}
@@ -45,11 +57,11 @@ export function getOptions<T>(plugin: string): T {
45
57
}
46
58
47
59
export function enable ( plugin : string ) {
48
- setMenuOptions ( plugin , { enabled : true } ) ;
60
+ setMenuOptions ( plugin , { enabled : true } , [ ] ) ;
49
61
}
50
62
51
63
export function disable ( plugin : string ) {
52
- setMenuOptions ( plugin , { enabled : false } ) ;
64
+ setMenuOptions ( plugin , { enabled : false } , [ ] ) ;
53
65
}
54
66
55
67
export default {
0 commit comments