@@ -61,7 +61,7 @@ export class Background implements Disposable {
6161 // #region private methods 私有方法
6262
6363 /**
64- * 检测是否初次加载,并在初次加载的时候提示用户
64+ * 检测是否初次加载
6565 *
6666 * @private
6767 * @returns {boolean } 是否初次加载
@@ -71,22 +71,6 @@ export class Background implements Disposable {
7171 const firstLoad = ! fs . existsSync ( TOUCH_JSFILE_PATH ) ;
7272
7373 if ( firstLoad ) {
74- // 提示
75- vscode . window
76- . showInformationMessage ( l10n . t ( 'Welcome to use background@{version}!' , { version : VERSION } ) , {
77- title : l10n . t ( 'More' )
78- } )
79- . then ( confirm => {
80- if ( ! confirm ) {
81- return ;
82- }
83- this . showWelcome ( ) ;
84- } ) ;
85-
86- // 新版本强制提示下吧
87- // if (VERSION === '2.0.0' || true) {
88- // this.showWelcome();
89- // }
9074 // 标识插件已启动过
9175 await fs . promises . writeFile ( TOUCH_JSFILE_PATH , vscodePath . jsPath , ENCODING ) ;
9276 return true ;
@@ -155,25 +139,20 @@ export class Background implements Disposable {
155139 if ( ! enabled ) {
156140 if ( hasInstalled ) {
157141 await this . uninstall ( ) ;
158- vsHelp . showInfoRestart ( l10n . t ( 'Background has been disabled! Please restart.' ) ) ;
159- }
160- return ;
161- }
162142
163- // 更新,需要二次确认
164- const confirm = await vscode . window . showInformationMessage (
165- l10n . t ( 'Configuration has been changed, click to update.' ) ,
166- {
167- title : l10n . t ( 'Update and restart' )
143+ vsHelp . reload ( {
144+ message : l10n . t ( 'Background has been disabled! Please reload.' )
145+ } ) ;
168146 }
169- ) ;
170-
171- if ( ! confirm ) {
172147 return ;
173148 }
174149
175- await this . applyPatch ( ) ;
176- vscode . commands . executeCommand ( 'workbench.action.reloadWindow' ) ;
150+ // 更新,需要二次确认
151+ vsHelp . reload ( {
152+ message : l10n . t ( 'Configuration has been changed, click to apply.' ) ,
153+ btnReload : l10n . t ( 'Apply and Reload' ) ,
154+ beforeReload : ( ) => this . applyPatch ( )
155+ } ) ;
177156 }
178157
179158 public async applyPatch ( ) {
@@ -193,25 +172,48 @@ export class Background implements Disposable {
193172 /**
194173 * 初始化
195174 *
196- * @return {* } {Promise<void >}
175+ * @return {* } {Promise<any >}
197176 * @memberof Background
198177 */
199178 public async setup ( ) : Promise < any > {
200- await this . removeLegacyCssPatch ( ) ; // 移除v1旧版本patch
179+ await this . removeLegacyCssPatch ( ) ; // 移除「v1旧版本」patch
201180
202181 await this . checkFirstload ( ) ; // 是否初次加载插件
203182
204- const patchType = await this . jsFile . getPatchType ( ) ; // css 文件目前状态
183+ const patchType = await this . jsFile . getPatchType ( ) ; // 「js文件」目前状态
205184
206- // 如果「开启」状态,文件不是「latest」,则进行更新
207- if ( this . config . enabled ) {
208- // 此时一般为 vscode更新、background更新
209- if ( [ EFilePatchType . Legacy , EFilePatchType . None ] . includes ( patchType ) ) {
210- if ( await this . applyPatch ( ) ) {
211- vsHelp . showInfoRestart ( l10n . t ( 'Background has been changed! Please restart.' ) ) ;
212- }
213- }
185+ // 如果「开启」状态,文件不是「latest」,则进行「提示更新」
186+ // 此时一般为 「background更新」、「vscode更新」
187+ const needApply = [ EFilePatchType . Legacy , EFilePatchType . None ] . includes ( patchType ) ;
188+ if ( this . config . enabled && needApply ) {
189+ // 提示
190+ vscode . window
191+ . showInformationMessage (
192+ l10n . t ( 'Background@{version} is ready! Apply to take effect.' , { version : VERSION } ) ,
193+ {
194+ title : l10n . t ( 'Apply and Reload' ) ,
195+ action : async ( ) => {
196+ await this . applyPatch ( ) ;
197+ await vsHelp . reload ( ) ;
198+ }
199+ } ,
200+ {
201+ title : l10n . t ( 'More' ) ,
202+ action : ( ) => this . showWelcome ( )
203+ }
204+ )
205+ . then ( confirm => {
206+ confirm ?. action ( ) ;
207+ } ) ;
214208 }
209+ // if ([EFilePatchType.Legacy, EFilePatchType.None].includes(patchType)) {
210+ // // 提示: 欢迎使用 background@version! 「应用并重载」、「更多」
211+ // if (await this.applyPatch()) {
212+ // vsHelp.reload({
213+ // message: l10n.t('Background has been changed! Please reload.')
214+ // });
215+ // }
216+ // }
215217
216218 // 监听文件改变
217219 this . disposables . push (
0 commit comments