@@ -5,6 +5,8 @@ import { computed, reactive, ref, toRaw } from 'vue';
5
5
6
6
import type { ListEntity } from '~/models/list.model' ;
7
7
8
+ import type { PosterItem } from '~/models/poster.model' ;
9
+
8
10
import { NavbarPosition , type NavbarPositions } from '~/models/navbar-position.model' ;
9
11
10
12
import { PageSize } from '~/models/page-size.model' ;
@@ -34,12 +36,33 @@ type RouteDictionary = Partial<Record<Route, boolean>>;
34
36
const DefaultRoutes : RouteDictionary = {
35
37
[ Route . Progress ] : false ,
36
38
[ Route . Calendar ] : true ,
37
- [ Route . Releases ] : false ,
38
39
[ Route . History ] : true ,
39
40
[ Route . Watchlist ] : true ,
41
+ [ Route . Releases ] : false ,
40
42
[ Route . Search ] : true ,
41
43
} ;
42
44
45
+ type ImageTypeDictionary = Partial < Record < Route , PosterItem [ 'type' ] | 'default' > > ;
46
+
47
+ const DefaultImageTypes : ImageTypeDictionary = {
48
+ [ Route . Progress ] : 'default' ,
49
+ [ Route . Calendar ] : 'default' ,
50
+ [ Route . History ] : 'default' ,
51
+ [ Route . Watchlist ] : 'default' ,
52
+ [ Route . Releases ] : 'default' ,
53
+ [ Route . Search ] : 'default' ,
54
+ } ;
55
+
56
+ type ImageFormatDictionary = Partial < Record < Route , 'backdrop' | 'poster' > > ;
57
+ const DefaultImageFormats : ImageFormatDictionary = {
58
+ [ Route . Progress ] : 'backdrop' ,
59
+ [ Route . Calendar ] : 'backdrop' ,
60
+ [ Route . History ] : 'backdrop' ,
61
+ [ Route . Watchlist ] : 'poster' ,
62
+ [ Route . Releases ] : 'poster' ,
63
+ [ Route . Search ] : 'poster' ,
64
+ } ;
65
+
43
66
type ExtensionSettings = {
44
67
cacheRetention : CacheRetentionState ;
45
68
enabledRoutes : RouteDictionary ;
@@ -53,6 +76,8 @@ type ExtensionSettings = {
53
76
loadingHysteresis : number ;
54
77
navbarPosition : NavbarPositions ;
55
78
iconOnly : boolean ;
79
+ imageType : ImageTypeDictionary ;
80
+ imageFormat : ImageFormatDictionary ;
56
81
} ;
57
82
58
83
const ExtensionSettingsConstants = {
@@ -75,10 +100,14 @@ export const useExtensionSettingsStore = defineStore(ExtensionSettingsConstants.
75
100
const loadingHysteresis = ref ( - 1 ) ;
76
101
const navbarPosition = ref < NavbarPositions > ( NavbarPosition . Auto ) ;
77
102
const iconOnly = ref ( true ) ;
103
+ const imageType = reactive < ExtensionSettings [ 'imageType' ] > ( DefaultImageTypes ) ;
104
+ const imageFormat = reactive < ExtensionSettings [ 'imageFormat' ] > ( DefaultImageFormats ) ;
78
105
79
106
const clearState = ( ) => {
80
107
Object . assign ( cacheRetention , DefaultCacheRetention ) ;
81
108
Object . assign ( routeDictionary , DefaultRoutes ) ;
109
+ Object . assign ( imageType , DefaultImageTypes ) ;
110
+ Object . assign ( imageFormat , DefaultImageFormats ) ;
82
111
restoreRoute . value = true ;
83
112
restorePanel . value = false ;
84
113
progressType . value = ProgressType . Show ;
@@ -92,14 +121,16 @@ export const useExtensionSettingsStore = defineStore(ExtensionSettingsConstants.
92
121
enabledRoutes : toRaw ( routeDictionary ) ,
93
122
restoreRoute : restoreRoute . value ,
94
123
restorePanel : restorePanel . value ,
95
- loadLists,
124
+ loadLists : toRaw ( loadLists ) ,
96
125
loadListsPageSize : loadListsPageSize . value ,
97
126
progressType : progressType . value ,
98
127
enableRatings : enableRatings . value ,
99
128
backgroundColor : backgroundColor . value ,
100
129
loadingHysteresis : loadingHysteresis . value ,
101
130
navbarPosition : navbarPosition . value ,
102
131
iconOnly : iconOnly . value ,
132
+ imageType : toRaw ( imageType ) ,
133
+ imageFormat : toRaw ( imageFormat ) ,
103
134
} ) ,
104
135
500 ,
105
136
) ;
@@ -136,6 +167,8 @@ export const useExtensionSettingsStore = defineStore(ExtensionSettingsConstants.
136
167
if ( restored ?. loadingHysteresis !== undefined ) loadingHysteresis . value = restored . loadingHysteresis ;
137
168
if ( restored ?. navbarPosition !== undefined ) navbarPosition . value = restored . navbarPosition ;
138
169
if ( restored ?. iconOnly !== undefined ) iconOnly . value = restored . iconOnly ;
170
+ if ( restored ?. imageType !== undefined ) Object . assign ( imageType , restored . imageType ) ;
171
+ if ( restored ?. imageFormat !== undefined ) Object . assign ( imageFormat , restored . imageFormat ) ;
139
172
140
173
if ( ! chromeRuntimeId ) routeDictionary [ Route . Progress ] = false ;
141
174
} ;
@@ -166,6 +199,12 @@ export const useExtensionSettingsStore = defineStore(ExtensionSettingsConstants.
166
199
saveState ( ) . catch ( err => Logger . error ( 'Failed to save enabled tab extension settings' , { tab, err } ) ) ;
167
200
} ;
168
201
202
+ const getImageSettings = ( route : Route ) =>
203
+ computed ( ( ) => ( {
204
+ type : imageType [ route ] === 'default' ? undefined : imageType [ route ] ,
205
+ backdrop : imageFormat [ route ] === 'backdrop' ,
206
+ } ) ) ;
207
+
169
208
return {
170
209
initExtensionSettingsStore,
171
210
restoreDefaultTab,
@@ -266,6 +305,21 @@ export const useExtensionSettingsStore = defineStore(ExtensionSettingsConstants.
266
305
saveState ( ) . catch ( err => Logger . error ( 'Failed to save icon only extension settings' , { value, err } ) ) ;
267
306
} ,
268
307
} ) ,
308
+ getImageSettings,
309
+ imageType : computed ( {
310
+ get : ( ) => imageType ,
311
+ set : ( value : ImageTypeDictionary ) => {
312
+ Object . assign ( imageType , value ) ;
313
+ saveState ( ) . catch ( err => Logger . error ( 'Failed to save image type extension settings' , { value, err } ) ) ;
314
+ } ,
315
+ } ) ,
316
+ imageFormat : computed ( {
317
+ get : ( ) => imageFormat ,
318
+ set : ( value : ImageFormatDictionary ) => {
319
+ Object . assign ( imageFormat , value ) ;
320
+ saveState ( ) . catch ( err => Logger . error ( 'Failed to save image format extension settings' , { value, err } ) ) ;
321
+ } ,
322
+ } ) ,
269
323
} ;
270
324
} ) ;
271
325
0 commit comments