File tree Expand file tree Collapse file tree 3 files changed +34
-24
lines changed Expand file tree Collapse file tree 3 files changed +34
-24
lines changed Original file line number Diff line number Diff line change 1616 }
1717
1818 function storeConfigToLocalStorage ( data ) {
19- localStorage . setItem ( SETUP_STRING , JSON . stringify ( data || { } ) ) ;
19+ chrome . storage . local . set ( { [ SETUP_STRING ] : data || { } } ) ;
2020 }
21-
22- function getConfigFromLocalStorage ( data ) {
23- const val = localStorage . getItem ( SETUP_STRING ) ;
24- return JSON . parse ( val ) || { } ;
21+
22+ function getConfigFromLocalStorage ( ) {
23+ return new Promise ( ( resolve ) => {
24+ chrome . storage . local . get ( [ SETUP_STRING ] , ( result ) => {
25+ resolve ( result [ SETUP_STRING ] || { } ) ;
26+ } ) ;
27+ } ) ;
2528 }
2629
2730 chrome . runtime . onMessage . addListener ( ( msg , sender , sendResponse ) => {
3235 sendMsgToAllContainPage ( 'live-server-config-updated' , msg . data ) ;
3336 }
3437 else if ( msg . req === 'get-live-server-config' ) {
35- const data = getConfigFromLocalStorage ( ) ;
36- sendResponse ( data ) ;
38+ getConfigFromLocalStorage ( ) . then (
39+ function ( value ) { sendResponse ( value ) } ,
40+ function ( error ) { console . error ( `Error: ${ error } ` ) }
41+ ) ;
3742 }
38-
43+ return true ; //Keep the callback(sendResponse) active
3944 } ) ;
4045
4146} ) ( ) ;
Original file line number Diff line number Diff line change 11{
2- "manifest_version" : 2 ,
2+ "manifest_version" : 3 ,
33 "name" : " Live Server Web Extension" ,
44 "version" : " 1.4.0" ,
55 "description" : " Makes your existing server live. This is a browser extension that helps you to live reload feature for dynamic pages" ,
2222 }
2323 ],
2424 "background" : {
25- "scripts" : [
26- " background.js"
27- ]
25+ "service_worker" : " background.js" ,
26+ "type" : " module"
2827 },
29- "browser_action " : {
28+ "action " : {
3029 "default_popup" : " ./popup/popup.html" ,
3130 "default_icon" : " ./img/icon.png" ,
3231 "default_title" : " Live Server"
3332 },
3433 "permissions" : [
34+ " storage"
35+ ],
36+ "host_permissions" : [
3537 " http://*/*" ,
3638 " https://*/*"
3739 ]
Original file line number Diff line number Diff line change 11; ( function ( ) {
2-
2+
33 'use strict' ;
44
55 const liveReloadCheck = document . getElementById ( 'liveReloadCheck' ) ;
1818 liveServerUrl : liveServerAddress . value || ''
1919 }
2020
21- chrome . runtime . sendMessage ( {
22- req : 'set-live-server-config' ,
23- data : formData
24- } ) ;
21+ if ( chrome && chrome . runtime ) {
22+ chrome . runtime . sendMessage ( {
23+ req : 'set-live-server-config' ,
24+ data : formData
25+ } ) ;
26+ }
2527 }
2628
2729 liveReloadCheck . onclick = ( ) => {
3941 chrome . runtime . sendMessage ( {
4042 req : 'get-live-server-config'
4143 } , ( data ) => {
42- console . log ( 'popupwidnow' )
43- liveReloadCheck . checked = data . isEnable || false ;
44- noProxyCheckBox . checked = ! data . proxySetup ;
45- actualServerAddress . value = data . actualUrl || '' ;
46- liveServerAddress . value = data . liveServerUrl || '' ;
47- serverSetupDiv . className = noProxyCheckBox . checked ? 'show' : 'hide' ;
44+ if ( data ) {
45+ liveReloadCheck . checked = data . isEnable || false ;
46+ noProxyCheckBox . checked = ! data . proxySetup ;
47+ actualServerAddress . value = data . actualUrl || '' ;
48+ liveServerAddress . value = data . liveServerUrl || '' ;
49+ serverSetupDiv . className = noProxyCheckBox . checked ? 'show' : 'hide' ;
50+ }
4851 } ) ;
4952 } ) ;
5053
You can’t perform that action at this time.
0 commit comments