1
1
import Store from 'electron-store' ;
2
- import Conf from 'conf' ;
3
2
4
3
import defaults from './defaults' ;
5
4
6
5
import { DefaultPresetList , type Preset } from '@/plugins/downloader/types' ;
7
6
7
+ // prettier-ignore
8
+ export type IStore = InstanceType < typeof import ( 'conf/dist/source/index' ) . default < Record < string , unknown > > > ;
9
+
8
10
const migrations = {
9
- '>=3.3.0' ( store : Conf < Record < string , unknown > > ) {
11
+ '>=3.3.0' ( store : IStore ) {
10
12
const lastfmConfig = store . get ( 'plugins.lastfm' ) as {
11
13
enabled ?: boolean ;
12
14
token ?: string ;
@@ -16,21 +18,21 @@ const migrations = {
16
18
secret ?: string ;
17
19
} ;
18
20
if ( lastfmConfig ) {
19
- let scrobblerConfig = store . get (
20
- 'plugins.scrobbler' ,
21
- ) as {
22
- enabled ?: boolean ;
23
- scrobblers ?: {
24
- lastfm ?: {
21
+ let scrobblerConfig = store . get ( 'plugins.scrobbler' ) as
22
+ | {
25
23
enabled ?: boolean ;
26
- token ?: string ;
27
- sessionKey ?: string ;
28
- apiRoot ?: string ;
29
- apiKey ?: string ;
30
- secret ?: string ;
31
- } ;
32
- } ;
33
- } | undefined ;
24
+ scrobblers ?: {
25
+ lastfm ?: {
26
+ enabled ?: boolean ;
27
+ token ?: string ;
28
+ sessionKey ?: string ;
29
+ apiRoot ?: string ;
30
+ apiKey ?: string ;
31
+ secret ?: string ;
32
+ } ;
33
+ } ;
34
+ }
35
+ | undefined ;
34
36
35
37
if ( ! scrobblerConfig ) {
36
38
scrobblerConfig = {
@@ -56,7 +58,7 @@ const migrations = {
56
58
store . delete ( 'plugins.lastfm' ) ;
57
59
}
58
60
} ,
59
- '>=3.0.0' ( store : Conf < Record < string , unknown > > ) {
61
+ '>=3.0.0' ( store : IStore ) {
60
62
const discordConfig = store . get ( 'plugins.discord' ) as Record <
61
63
string ,
62
64
unknown
@@ -78,14 +80,14 @@ const migrations = {
78
80
}
79
81
}
80
82
} ,
81
- '>=2.1.3' ( store : Conf < Record < string , unknown > > ) {
83
+ '>=2.1.3' ( store : IStore ) {
82
84
const listenAlong = store . get ( 'plugins.discord.listenAlong' ) ;
83
85
if ( listenAlong !== undefined ) {
84
86
store . set ( 'plugins.discord.playOnYouTubeMusic' , listenAlong ) ;
85
87
store . delete ( 'plugins.discord.listenAlong' ) ;
86
88
}
87
89
} ,
88
- '>=2.1.0' ( store : Conf < Record < string , unknown > > ) {
90
+ '>=2.1.0' ( store : IStore ) {
89
91
const originalPreset = store . get ( 'plugins.downloader.preset' ) as
90
92
| string
91
93
| undefined ;
@@ -110,7 +112,7 @@ const migrations = {
110
112
store . delete ( 'plugins.downloader.ffmpegArgs' ) ;
111
113
}
112
114
} ,
113
- '>=1.20.0' ( store : Conf < Record < string , unknown > > ) {
115
+ '>=1.20.0' ( store : IStore ) {
114
116
store . delete ( 'plugins.visualizer' ) ; // default value is now in the plugin
115
117
116
118
if ( store . get ( 'plugins.notifications.toastStyle' ) === undefined ) {
@@ -125,14 +127,14 @@ const migrations = {
125
127
store . set ( 'options.likeButtons' , 'force' ) ;
126
128
}
127
129
} ,
128
- '>=1.17.0' ( store : Conf < Record < string , unknown > > ) {
130
+ '>=1.17.0' ( store : IStore ) {
129
131
store . delete ( 'plugins.picture-in-picture' ) ; // default value is now in the plugin
130
132
131
133
if ( store . get ( 'plugins.video-toggle.mode' ) === undefined ) {
132
134
store . set ( 'plugins.video-toggle.mode' , 'custom' ) ;
133
135
}
134
136
} ,
135
- '>=1.14.0' ( store : Conf < Record < string , unknown > > ) {
137
+ '>=1.14.0' ( store : IStore ) {
136
138
if (
137
139
typeof store . get ( 'plugins.precise-volume.globalShortcuts' ) !== 'object'
138
140
) {
@@ -144,12 +146,12 @@ const migrations = {
144
146
store . set ( 'plugins.video-toggle.enabled' , true ) ;
145
147
}
146
148
} ,
147
- '>=1.13.0' ( store : Conf < Record < string , unknown > > ) {
149
+ '>=1.13.0' ( store : IStore ) {
148
150
if ( store . get ( 'plugins.discord.listenAlong' ) === undefined ) {
149
151
store . set ( 'plugins.discord.listenAlong' , true ) ;
150
152
}
151
153
} ,
152
- '>=1.12.0' ( store : Conf < Record < string , unknown > > ) {
154
+ '>=1.12.0' ( store : IStore ) {
153
155
const options = store . get ( 'plugins.shortcuts' ) as
154
156
| Record <
155
157
string ,
@@ -187,12 +189,12 @@ const migrations = {
187
189
}
188
190
}
189
191
} ,
190
- '>=1.11.0' ( store : Conf < Record < string , unknown > > ) {
192
+ '>=1.11.0' ( store : IStore ) {
191
193
if ( store . get ( 'options.resumeOnStart' ) === undefined ) {
192
194
store . set ( 'options.resumeOnStart' , true ) ;
193
195
}
194
196
} ,
195
- '>=1.7.0' ( store : Conf < Record < string , unknown > > ) {
197
+ '>=1.7.0' ( store : IStore ) {
196
198
const enabledPlugins = store . get ( 'plugins' ) as string [ ] ;
197
199
if ( ! Array . isArray ( enabledPlugins ) ) {
198
200
console . warn ( 'Plugins are not in array format, cannot migrate' ) ;
@@ -233,4 +235,4 @@ export default new Store({
233
235
} ,
234
236
clearInvalidConfig : false ,
235
237
migrations,
236
- } ) ;
238
+ } ) as Store & IStore ;
0 commit comments