@@ -37,7 +37,7 @@ function stateStore() {
3737 // store oldState to see how state transitioned
3838 // ex. if (newState === foo && oldState === bar) baz();
3939 let oldState = [ ] ;
40- const add = ( stateModifier ) =>
40+ const add = ( stateModifier ) => {
4141 update ( ( state ) => {
4242 // list of acceptable states, mostly for state definition tracking
4343 const states = [
@@ -68,7 +68,14 @@ function stateStore() {
6868 ) ;
6969 return state ;
7070 } ) ;
71- const remove = ( stateModifier ) =>
71+ // URL hash handle
72+ const params = new URLSearchParams ( location . hash . slice ( 1 ) ) ;
73+ if ( [ "settings" ] . includes ( stateModifier ) ) {
74+ params . set ( "state" , stateModifier ) ;
75+ location . hash = params . toString ( ) ;
76+ }
77+ } ;
78+ const remove = ( stateModifier ) => {
7279 update ( ( state ) => {
7380 // save pre-changed state to oldState var
7481 oldState = [ ...state ] ;
@@ -84,20 +91,38 @@ function stateStore() {
8491 ) ;
8592 return state ;
8693 } ) ;
94+ // URL hash handle
95+ const params = new URLSearchParams ( location . hash . slice ( 1 ) ) ;
96+ const state = params . get ( "state" ) ;
97+ if ( state === stateModifier ) {
98+ params . delete ( "state" ) ;
99+ location . hash = params . toString ( ) ;
100+ }
101+ } ;
87102 const getOldState = ( ) => oldState ;
88- return { subscribe, add, getOldState, remove } ;
103+ // URL hash handle
104+ const loadUrlState = ( ) => {
105+ const params = new URLSearchParams ( location . hash . slice ( 1 ) ) ;
106+ const state = params . get ( "state" ) ;
107+ state && add ( state ) ;
108+ } ;
109+ return { subscribe, add, getOldState, remove, loadUrlState } ;
89110}
90111export const state = stateStore ( ) ;
91112
92113function settingsStore ( ) {
93114 const { subscribe, update, set } = writable ( { } ) ;
94115 const init = async ( initData ) => {
95- // import legacy settings data just one-time
96- await settingsStorage . legacyImport ( ) ;
116+ if ( import . meta. env . SAFARI_PLATFORM === "mac" ) {
117+ // import legacy settings data just one-time
118+ await settingsStorage . legacyImport ( ) ;
119+ }
97120 // for compatibility with legacy getting names only
98121 // once all new name is used, use settingsStorage.get()
99122 const settings = await settingsStorage . legacyGet ( ) ;
100- console . info ( "store.js settingsStore init" , initData , settings ) ;
123+ if ( import . meta. env . MODE === "development" ) {
124+ console . info ( "store.js settingsStore init" , initData , settings ) ;
125+ }
101126 set ( { ...initData , ...settings } ) ;
102127 // sync popup, backgound, etc... settings changes
103128 settingsStorage . onChangedSettings ( ( sets , area ) => {
@@ -135,6 +160,7 @@ function settingsStore() {
135160 // for compatibility with legacy setting names only
136161 // once all new name is used, use settingsStorage.set()
137162 settingsStorage . legacySet ( { [ key ] : value } ) ; // Durable Storage
163+ settingsStorage . set ( { [ key ] : value } ) ; // Durable Storage
138164 // temporarily keep the old storage method until it is confirmed that all dependencies are removed
139165 updateSingleSettingOld ( key , value ) ;
140166 } ;
0 commit comments