@@ -7,7 +7,6 @@ import { getVirtualKey, isValidArray } from '@/share/core/utils';
77import { getDatabase } from './core/db' ;
88import { getAll , save , updateCache , waitLoad } from './core/rules' ;
99
10- // Upgrade
1110async function doUpgrade ( ) {
1211 if ( typeof localStorage !== 'undefined' ) {
1312 const downloadHistory = localStorage . getItem ( 'dl_history' ) ;
@@ -24,7 +23,7 @@ async function doUpgrade() {
2423 version = 0 ;
2524 }
2625 if ( version < 1 ) {
27- // Upgrade group
26+ // Upgrade groups
2827 const rebindRuleWithGroup = ( group ) => {
2928 return new Promise ( ( resolve ) => {
3029 const cacheQueue : Array < Promise < void > > = [ ] ;
@@ -70,20 +69,17 @@ async function doUpgrade() {
7069 if ( groups ) {
7170 const g = JSON . parse ( groups ) ;
7271 localStorage . removeItem ( 'groups' ) ;
73- rebindRuleWithGroup ( g ) ;
72+ await rebindRuleWithGroup ( g ) ;
7473 } else {
75- storage
76- . getLocal ( )
77- . get ( 'groups' )
78- . then ( ( r ) => {
79- if ( r . groups !== undefined ) {
80- rebindRuleWithGroup ( r . groups ) . then ( ( ) => storage . getLocal ( ) . remove ( 'groups' ) ) ;
81- } else {
82- const g = { } ;
83- g [ browser . i18n . getMessage ( 'ungrouped' ) ] = [ ] ;
84- rebindRuleWithGroup ( g ) ;
85- }
86- } ) ;
74+ const r = await storage . getLocal ( ) . get ( 'groups' ) ;
75+ if ( r . groups !== undefined ) {
76+ await rebindRuleWithGroup ( r . groups ) ;
77+ await storage . getLocal ( ) . remove ( 'groups' ) ;
78+ } else {
79+ const g = { } ;
80+ g [ browser . i18n . getMessage ( 'ungrouped' ) ] = [ ] ;
81+ await rebindRuleWithGroup ( g ) ;
82+ }
8783 }
8884 }
8985 }
@@ -120,27 +116,12 @@ async function doUpgrade() {
120116 } ) ;
121117 } ) ;
122118 await Promise . all ( queue ) ;
123- tableToUpdate . forEach ( ( table ) => {
124- updateCache ( table ) ;
125- } ) ;
126- // rule_switch_
119+ await Promise . all ( tableToUpdate . map ( ( table ) => updateCache ( table ) ) ) ;
127120 }
128121
129- storage . getLocal ( ) . set ( {
122+ await storage . getLocal ( ) . set ( {
130123 version_mark : 2 ,
131124 } ) ;
132125}
133126
134- if ( MANIFEST_VER === 'v3' ) {
135- browser . runtime . onInstalled . addListener ( ( details ) => {
136- if ( IS_DEV ) {
137- console . log ( 'chrome onInstalled' , details ) ;
138- }
139- if ( details . reason !== 'install' && details . reason !== 'update' ) {
140- return ;
141- }
142- doUpgrade ( ) ;
143- } ) ;
144- } else {
145- doUpgrade ( ) ;
146- }
127+ doUpgrade ( ) ;
0 commit comments