@@ -9,20 +9,43 @@ import Utils from './utils.js';
9
9
import { timeout , readFileAsync } from './utils.js' ;
10
10
import { loadInterfaceXML } from './utils.js' ;
11
11
12
+ function deprecated ( config : Config ) {
13
+ const warning = ( from : string , to : string ) => console . warn (
14
+ `${ from } config option has been removed: use ${ to } instead` ) ;
15
+
16
+ if ( config . notificationPopupTimeout !== undefined )
17
+ warning ( 'notificationPopupTimeout' , 'Notifications.popupTimeout' ) ;
18
+
19
+ if ( config . notificationForceTimeout !== undefined )
20
+ warning ( 'notificationForceTimeout' , 'Notifications.forceTimeout' ) ;
21
+
22
+ if ( config . cacheNotificationActions !== undefined )
23
+ warning ( 'cacheNotificationActions' , 'Notifications.cacheActions' ) ;
24
+
25
+ if ( config . cacheCoverArt !== undefined )
26
+ warning ( 'cacheCoverArt' , 'Mpris.cacheCoverArt' ) ;
27
+
28
+ if ( config . maxStreamVolume !== undefined )
29
+ warning ( 'cacheCoverArt' , 'Audio.maxStreamVolume' ) ;
30
+ }
31
+
12
32
const AgsIFace = ( bus : string ) =>
13
33
loadInterfaceXML ( 'com.github.Aylur.ags' ) ?. replace ( '@BUS@' , bus ) ;
14
34
15
35
export interface Config < W extends Gtk . Window = Gtk . Window > {
16
36
windows ?: W [ ]
17
37
style ?: string
38
+ icons ?: string
39
+ onWindowToggled ?: ( windowName : string , visible : boolean ) => void
40
+ onConfigParsed ?: ( app : App ) => void
41
+ closeWindowDelay : { [ key : string ] : number }
42
+
43
+ // FIXME: deprecated
18
44
notificationPopupTimeout : number
19
45
notificationForceTimeout : boolean
20
46
cacheNotificationActions : boolean
21
47
cacheCoverArt : boolean
22
- closeWindowDelay : { [ key : string ] : number }
23
48
maxStreamVolume : number
24
- onWindowToggled ?: ( windowName : string , visible : boolean ) => void ,
25
- onConfigParsed ?: ( app : App ) => void ,
26
49
}
27
50
28
51
export class App extends Gtk . Application {
@@ -34,19 +57,16 @@ export class App extends Gtk.Application {
34
57
}
35
58
36
59
private _dbus ! : Gio . DBusExportedObject ;
37
- private _closeDelay ! : { [ key : string ] : number } ;
60
+ private _closeDelay ! : Config [ 'closeWindowDelay' ] ;
38
61
private _cssProviders : Gtk . CssProvider [ ] = [ ] ;
39
62
private _objectPath ! : string ;
40
-
41
63
private _windows : Map < string , Gtk . Window > = new Map ( ) ;
42
64
private _configPath ! : string ;
43
65
private _configDir ! : string ;
44
- private _config ! : Config ;
45
66
46
- get windows ( ) { return this . _windows ; }
67
+ get windows ( ) { return [ ... this . _windows . values ( ) ] ; }
47
68
get configPath ( ) { return this . _configPath ; }
48
69
get configDir ( ) { return this . _configDir ; }
49
- get config ( ) { return this . _config ; }
50
70
51
71
resetCss ( ) {
52
72
const screen = Gdk . Screen . get_default ( ) ;
@@ -190,36 +210,26 @@ export class App extends Gtk.Application {
190
210
191
211
private async _load ( ) {
192
212
try {
193
- const mod = await import ( `file://${ this . configPath } ` ) ;
194
- const config = mod . default as Config ;
195
- config . closeWindowDelay ??= { } ;
196
- config . notificationPopupTimeout ??= 3000 ;
197
- config . notificationForceTimeout ??= false ;
198
- config . maxStreamVolume ??= 1.5 ;
199
- config . cacheNotificationActions ??= false ;
200
- config . cacheCoverArt ??= true ;
201
- this . _config = config ;
202
-
213
+ const entry = await import ( `file://${ this . configPath } ` ) ;
214
+ const config = entry . default as Config ;
203
215
if ( ! config ) {
204
216
console . error ( 'Missing default export' ) ;
205
- this . emit ( 'config-parsed' ) ;
206
- return ;
217
+ return this . emit ( 'config-parsed' ) ;
207
218
}
208
219
209
- this . _closeDelay = config . closeWindowDelay ;
220
+ // FIXME:
221
+ deprecated ( config ) ;
222
+
223
+ this . _closeDelay = config ?. closeWindowDelay || { } ;
210
224
211
225
if ( config . style ) {
212
226
this . applyCss ( config . style . startsWith ( '.' )
213
227
? `${ this . configDir } ${ config . style . slice ( 1 ) } `
214
228
: config . style ) ;
215
229
}
216
230
217
- if ( config . windows && ! Array . isArray ( config . windows ) ) {
218
- console . error ( 'windows attribute has to be an array, ' +
219
- `but it is a ${ typeof config . windows } ` ) ;
220
- this . emit ( 'config-parsed' ) ;
221
- return ;
222
- }
231
+ if ( config . icons )
232
+ Gtk . IconTheme . get_default ( ) . append_search_path ( config . icons ) ;
223
233
224
234
if ( typeof config . onWindowToggled === 'function' )
225
235
this . connect ( 'window-toggled' , ( _ , n , v ) => config . onWindowToggled ! ( n , v ) ) ;
0 commit comments