@@ -13,7 +13,7 @@ import { SubscribeService } from "./subscribe";
1313import { ScriptDAO } from "@App/app/repo/scripts" ;
1414import { SystemService } from "./system" ;
1515import { type Logger , LoggerDAO } from "@App/app/repo/logger" ;
16- import { initLocales , localePath , t } from "@App/locales/locales" ;
16+ import { initLocales , initLocalesPromise , localePath , t , watchLanguageChange } from "@App/locales/locales" ;
1717import { getCurrentTab , InfoNotification } from "@App/pkg/utils/utils" ;
1818import { onTabRemoved , onUrlNavigated , setOnUserActionDomainChanged } from "./url_monitor" ;
1919import { LocalStorageDAO } from "@App/app/repo/localStorage" ;
@@ -178,14 +178,10 @@ export default class ServiceWorkerManager {
178178 }
179179 } ) ;
180180
181- // 监听配置变化
182- systemConfig . addListener ( "cloud_sync" , ( value ) => {
181+ // 云同步
182+ systemConfig . watch ( "cloud_sync" , ( value ) => {
183183 synchronize . cloudSyncConfigChange ( value ) ;
184184 } ) ;
185- // 启动一次云同步
186- systemConfig . getCloudSync ( ) . then ( ( config ) => {
187- synchronize . cloudSyncConfigChange ( config ) ;
188- } ) ;
189185
190186 if ( process . env . NODE_ENV === "production" ) {
191187 chrome . runtime . onInstalled . addListener ( ( details ) => {
@@ -194,41 +190,45 @@ export default class ServiceWorkerManager {
194190 console . error ( "chrome.runtime.lastError in chrome.runtime.onInstalled:" , lastError ) ;
195191 // chrome.runtime.onInstalled API出错不进行后续处理
196192 }
197- if ( details . reason === "install" ) {
198- chrome . tabs . create ( { url : `${ DocumentationSite } ${ localePath } /docs/use/install_comple` } ) ;
199- } else if ( details . reason === "update" ) {
200- const url = `${ DocumentationSite } /docs/change/${ ExtVersion . includes ( "-" ) ? "beta-changelog/" : "" } #${ ExtVersion } ` ;
201- getCurrentTab ( )
202- . then ( ( tab ) => {
203- // 检查是否正在播放视频,或者窗口未激活
204- const openInBackground = ! tab || tab . audible === true || ! tab . active ;
205- // chrome.tabs.create 传回 Promise<chrome.tabs.Tab>
206- return chrome . tabs . create ( {
207- url,
208- active : ! openInBackground ,
209- index : ! tab ? undefined : tab . index + 1 ,
210- windowId : ! tab ? undefined : tab . windowId ,
193+ initLocalesPromise . then ( ( ) => {
194+ if ( details . reason === "install" ) {
195+ chrome . tabs . create ( { url : `${ DocumentationSite } ${ localePath } /docs/use/install_comple` } ) ;
196+ } else if ( details . reason === "update" ) {
197+ const url = `${ DocumentationSite } ${ localePath } /docs/change/${ ExtVersion . includes ( "-" ) ? "beta-changelog/" : "" } #${ ExtVersion } ` ;
198+ getCurrentTab ( )
199+ . then ( ( tab ) => {
200+ // 检查是否正在播放视频,或者窗口未激活
201+ const openInBackground = ! tab || tab . audible === true || ! tab . active ;
202+ // chrome.tabs.create 传回 Promise<chrome.tabs.Tab>
203+ return chrome . tabs . create ( {
204+ url,
205+ active : ! openInBackground ,
206+ index : ! tab ? undefined : tab . index + 1 ,
207+ windowId : ! tab ? undefined : tab . windowId ,
208+ } ) ;
209+ } )
210+ . then ( ( _createdTab ) => {
211+ // 当新 Tab 成功建立时才执行
212+ InfoNotification (
213+ t ( "ext_update_notification" ) ,
214+ t ( "ext_update_notification_desc" , { version : ExtVersion } )
215+ ) ;
216+ } )
217+ . catch ( ( e ) => {
218+ console . error ( e ) ;
211219 } ) ;
212- } )
213- . then ( ( _createdTab ) => {
214- // 当新 Tab 成功建立时才执行
215- InfoNotification (
216- t ( "ext_update_notification" ) ,
217- t ( "ext_update_notification_desc" , { version : ExtVersion } )
218- ) ;
219- } )
220- . catch ( ( e ) => {
221- console . error ( e ) ;
222- } ) ;
223- }
220+ }
221+ } ) ;
224222 } ) ;
225223
226224 // 监听扩展卸载事件
227- chrome . runtime . setUninstallURL ( `${ DocumentationSite } ${ localePath } /uninstall` , ( ) => {
228- const lastError = chrome . runtime . lastError ;
229- if ( lastError ) {
230- console . error ( "chrome.runtime.lastError in chrome.runtime.setUninstallURL:" , lastError ) ;
231- }
225+ watchLanguageChange ( ( ) => {
226+ chrome . runtime . setUninstallURL ( `${ DocumentationSite } ${ localePath } /uninstall` , ( ) => {
227+ const lastError = chrome . runtime . lastError ;
228+ if ( lastError ) {
229+ console . error ( "chrome.runtime.lastError in chrome.runtime.setUninstallURL:" , lastError ) ;
230+ }
231+ } ) ;
232232 } ) ;
233233 }
234234
0 commit comments