@@ -60,18 +60,25 @@ chrome.webRequest.onAuthRequired.addListener(
60
60
{ urls : [ "<all_urls>" ] } ,
61
61
[ 'asyncBlocking' ] ) ;
62
62
63
- chrome . runtime . onMessage . addListener ( async function ( msg , sender , res ) {
63
+ chrome . runtime . onMessage . addListener ( ( msg , sender , res ) => {
64
64
if ( msg . action != "authUpdate" )
65
65
return ;
66
66
67
- console . log ( "%s onMessage listener" , new Date ( Date . now ( ) ) . toISOString ( ) ) ;
68
- if ( localStorage . proxySetting == undefined )
69
- await getLocalStorage ( ) ;
67
+ ( async ( ) => {
68
+ console . log ( "%s receive authUpdate" , new Date ( Date . now ( ) ) . toISOString ( ) ) ;
69
+ if ( localStorage . proxySetting == undefined )
70
+ await getLocalStorage ( ) ;
70
71
71
- var proxySetting = JSON . parse ( localStorage . proxySetting ) ;
72
- proxySetting [ 'auth' ] = msg . data ;
73
- localStorage . proxySetting = JSON . stringify ( proxySetting ) ;
74
- chrome . storage . local . set ( localStorage ) ;
72
+ var proxySetting = JSON . parse ( localStorage . proxySetting ) ;
73
+ proxySetting [ 'auth' ] = msg . data ;
74
+ localStorage . proxySetting = JSON . stringify ( proxySetting ) ;
75
+ await chrome . storage . local . set ( localStorage ) ;
76
+
77
+ console . log ( "%s sending authUpdate response" , new Date ( Date . now ( ) ) . toISOString ( ) ) ;
78
+ res ( 'done' ) ;
79
+ } ) ( ) ;
80
+
81
+ return true ;
75
82
} ) ;
76
83
77
84
var proxySetting = {
@@ -116,6 +123,23 @@ chrome.runtime.onInstalled.addListener(async details => {
116
123
if ( store . proxySetting == undefined ) {
117
124
localStorage . proxySetting = JSON . stringify ( proxySetting ) ;
118
125
await chrome . storage . local . set ( localStorage ) ;
126
+
127
+ if ( details . reason == "update" ) {
128
+ chrome . runtime . onMessage . addListener ( ( msg , sender , res ) => {
129
+ if ( msg . action != "migrationDone" )
130
+ return ;
131
+
132
+ console . log ( "%s data migration done" , new Date ( Date . now ( ) ) . toISOString ( ) ) ;
133
+ chrome . offscreen . closeDocument ( ) ;
134
+ } ) ;
135
+
136
+ console . log ( "%s starting data migration" , new Date ( Date . now ( ) ) . toISOString ( ) ) ;
137
+ chrome . offscreen . createDocument ( {
138
+ url : 'migration.html' ,
139
+ reasons : [ 'LOCAL_STORAGE' ] ,
140
+ justification : 'Migrate storage data for MV2 to MV3' ,
141
+ } ) ;
142
+ }
119
143
}
120
144
if ( details . reason == "install" ) {
121
145
gotoPage ( 'options.html' ) ;
0 commit comments