Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions l10n/bundle.l10n.ja.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"Show `background` commands": "「`background`」コマンドの表示",
"Background extension has been uninstalled. See you next time!": "Backgroundはアンインストールされています。また今度!",
"Restart vscode": "vscodeの再起動",
"Welcome to use background@{version}!": "ようこそbackground@{version}!",
"Reload vscode": "vscode を再読み込み",
"Background@{version} is ready! Apply to take effect.": "Background@{version} の準備ができました!「適用」をクリックして反映してください。",
"More": "詳細",
"Background has been disabled! Please restart.": "Backgroundは無効になっています!再起動してください。",
"Configuration has been changed, click to update.": "構成が変更されたので、更新をクリックします。",
"Update and restart": "更新と再起動",
"Background has been changed! Please restart.": "Backgroundは変わった!再起動してください。"
"Background has been disabled! Please reload.": "Backgroundは無効になっています!再起動してください。",
"Configuration has been changed, click to apply.": "構成が変更されたので、更新をクリックします。",
"Apply and Reload": "適用して再読み込み"
}
11 changes: 5 additions & 6 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"Show `background` commands": "Show `background` commands",
"Background extension has been uninstalled. See you next time!": "Background extension has been uninstalled. See you next time!",
"Restart vscode": "Restart vscode",
"Welcome to use background@{version}!": "Welcome to use background@{version}!",
"Reload vscode": "Reload vscode",
"Background@{version} is ready! Apply to take effect.": "Background@{version} is ready! Apply to take effect.",
"More": "More",
"Background has been disabled! Please restart.": "Background has been disabled! Please restart.",
"Configuration has been changed, click to update.": "Configuration has been changed, click to update.",
"Update and restart": "Update and restart",
"Background has been changed! Please restart.": "Background has been changed! Please restart."
"Background has been disabled! Please reload.": "Background has been disabled! Please reload.",
"Configuration has been changed, click to apply.": "Configuration has been changed, click to apply.",
"Apply and Reload": "Apply and Reload"
}
11 changes: 5 additions & 6 deletions l10n/bundle.l10n.zh-cn.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"Show `background` commands": "查看 `background` 命令",
"Background extension has been uninstalled. See you next time!": "Background 已经卸载,下次见!",
"Restart vscode": "重启 vscode",
"Welcome to use background@{version}!": "欢迎使用 background@{version}!",
"Reload vscode": "重载 vscode",
"Background@{version} is ready! Apply to take effect.": "Background@{version} 已就绪!点击应用生效。",
"More": "更多",
"Background has been disabled! Please restart.": "Background 已经禁用! 请重启。",
"Configuration has been changed, click to update.": "配置已改变,点击更新。",
"Update and restart": "更新并重启",
"Background has been changed! Please restart.": "Background 已经改变!请重启。"
"Background has been disabled! Please reload.": "Background 已经禁用! 请重载。",
"Configuration has been changed, click to apply.": "配置已改变,点击应用。",
"Apply and Reload": "应用并重载"
}
28 changes: 2 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "background",
"displayName": "background",
"description": "Bring background images to your vscode",
"version": "2.0.5",
"version": "2.0.6-alpha.0",
"scripts": {
"vscode:prepublish": "npm run compile",
"vscode:uninstall": "node ./out/uninstall",
Expand Down Expand Up @@ -316,7 +316,6 @@
},
"devDependencies": {
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
"@types/lockfile": "^1.0.4",
"@types/node": "^24",
"@types/stylis": "^4.2.7",
"@types/uglify-js": "^3.17.5",
Expand All @@ -334,7 +333,6 @@
"dependencies": {
"@vscode/sudo-prompt": "^9.3.1",
"fast-glob": "^3.3.3",
"lockfile": "^1.0.4",
"stylis": "^4.3.6",
"uglify-js": "^3.19.3"
}
Expand Down
4 changes: 2 additions & 2 deletions package.nls.ja.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extension.background.command.info.title": "backgroundへようこそ。",
"extension.background.command.install.title": "「background」をインストールして有効にします。",
"extension.background.command.disable.title": "background」を無効にする。",
"extension.background.command.install.title": "有効にして適用「Background」 を有効にして適用",
"extension.background.command.disable.title": "Background」を無効にする。",
"extension.background.command.uninstall.title": "拡張機能をアンインストール",

"extension.background.enabled.description": "拡張機能の有効化を制御します",
Expand Down
2 changes: 1 addition & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extension.background.command.info.title": "Welcome to background.",
"extension.background.command.install.title": "Install and enable the background.",
"extension.background.command.install.title": "Enable and apply the background.",
"extension.background.command.disable.title": "Disable the background.",
"extension.background.command.uninstall.title": "Uninstall the extension.",

Expand Down
2 changes: 1 addition & 1 deletion package.nls.zh.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extension.background.command.info.title": "欢迎使用 background 插件",
"extension.background.command.install.title": "安装/激活插件",
"extension.background.command.install.title": "激活/应用插件",
"extension.background.command.disable.title": "禁用插件",
"extension.background.command.uninstall.title": "卸载插件",

Expand Down
86 changes: 44 additions & 42 deletions src/background/Background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Background implements Disposable {
// #region private methods 私有方法

/**
* 检测是否初次加载,并在初次加载的时候提示用户
* 检测是否初次加载
*
* @private
* @returns {boolean} 是否初次加载
Expand All @@ -71,22 +71,6 @@ export class Background implements Disposable {
const firstLoad = !fs.existsSync(TOUCH_JSFILE_PATH);

if (firstLoad) {
// 提示
vscode.window
.showInformationMessage(l10n.t('Welcome to use background@{version}!', { version: VERSION }), {
title: l10n.t('More')
})
.then(confirm => {
if (!confirm) {
return;
}
this.showWelcome();
});

// 新版本强制提示下吧
// if (VERSION === '2.0.0' || true) {
// this.showWelcome();
// }
// 标识插件已启动过
await fs.promises.writeFile(TOUCH_JSFILE_PATH, vscodePath.jsPath, ENCODING);
return true;
Expand Down Expand Up @@ -155,25 +139,20 @@ export class Background implements Disposable {
if (!enabled) {
if (hasInstalled) {
await this.uninstall();
vsHelp.showInfoRestart(l10n.t('Background has been disabled! Please restart.'));
}
return;
}

// 更新,需要二次确认
const confirm = await vscode.window.showInformationMessage(
l10n.t('Configuration has been changed, click to update.'),
{
title: l10n.t('Update and restart')
vsHelp.reload({
message: l10n.t('Background has been disabled! Please reload.')
});
}
);

if (!confirm) {
return;
}

await this.applyPatch();
vscode.commands.executeCommand('workbench.action.reloadWindow');
// 更新,需要二次确认
vsHelp.reload({
message: l10n.t('Configuration has been changed, click to apply.'),
btnReload: l10n.t('Apply and Reload'),
beforeReload: () => this.applyPatch()
});
}

public async applyPatch() {
Expand All @@ -193,25 +172,48 @@ export class Background implements Disposable {
/**
* 初始化
*
* @return {*} {Promise<void>}
* @return {*} {Promise<any>}
* @memberof Background
*/
public async setup(): Promise<any> {
await this.removeLegacyCssPatch(); // 移除v1旧版本patch
await this.removeLegacyCssPatch(); // 移除「v1旧版本」patch

await this.checkFirstload(); // 是否初次加载插件

const patchType = await this.jsFile.getPatchType(); // css 文件目前状态
const patchType = await this.jsFile.getPatchType(); // 「js文件」目前状态

// 如果「开启」状态,文件不是「latest」,则进行更新
if (this.config.enabled) {
// 此时一般为 vscode更新、background更新
if ([EFilePatchType.Legacy, EFilePatchType.None].includes(patchType)) {
if (await this.applyPatch()) {
vsHelp.showInfoRestart(l10n.t('Background has been changed! Please restart.'));
}
}
// 如果「开启」状态,文件不是「latest」,则进行「提示更新」
// 此时一般为 「background更新」、「vscode更新」
const needApply = [EFilePatchType.Legacy, EFilePatchType.None].includes(patchType);
if (this.config.enabled && needApply) {
// 提示
vscode.window
.showInformationMessage(
l10n.t('Background@{version} is ready! Apply to take effect.', { version: VERSION }),
{
title: l10n.t('Apply and Reload'),
action: async () => {
await this.applyPatch();
await vsHelp.reload();
}
},
{
title: l10n.t('More'),
action: () => this.showWelcome()
}
)
.then(confirm => {
confirm?.action();
});
}
// if ([EFilePatchType.Legacy, EFilePatchType.None].includes(patchType)) {
// // 提示: 欢迎使用 background@version! 「应用并重载」、「更多」
// if (await this.applyPatch()) {
// vsHelp.reload({
// message: l10n.t('Background has been changed! Please reload.')
// });
// }
// }

// 监听文件改变
this.disposables.push(
Expand Down
3 changes: 0 additions & 3 deletions src/background/CssFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ export class CssFile {
*/
public async uninstall(): Promise<boolean> {
try {
await _.lock();
let content = await this.getContent();
content = this.clearContent(content);
// 异常case return
Expand All @@ -188,8 +187,6 @@ export class CssFile {
} catch (ex) {
console.log(ex);
return false;
} finally {
await _.unlock();
}
}
}
3 changes: 0 additions & 3 deletions src/background/PatchFile/PatchFile.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,11 @@ export abstract class AbsPatchFile {

public async restore() {
try {
await _.lock();
let content = await this.getContent();
content = this.cleanPatches(content);
return await this.write(content);
} catch {
return false;
} finally {
await _.unlock();
}
}
}
4 changes: 0 additions & 4 deletions src/background/PatchFile/PatchFile.javascript.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { _ } from '../../utils';
import { BACKGROUND_VER, VERSION } from '../../utils/constants';
import { AbsPatchFile } from './PatchFile.base';

Expand All @@ -15,7 +14,6 @@ import { AbsPatchFile } from './PatchFile.base';
export class JsPatchFile extends AbsPatchFile {
public async applyPatches(patchContent: string): Promise<boolean> {
try {
await _.lock();
const curContent = await this.getContent();
let content = this.cleanPatches(curContent);
content += [
Expand All @@ -33,8 +31,6 @@ export class JsPatchFile extends AbsPatchFile {
return await this.write(content);
} catch {
return false;
} finally {
await _.unlock();
}
}

Expand Down
15 changes: 7 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,25 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.commands.registerCommand('extension.background.install', async () => {
await background.config.update('enabled', true, true);
await background.applyPatch();
await vscode.commands.executeCommand('workbench.action.reloadWindow');
await vsHelp.reload();
})
);

context.subscriptions.push(
vscode.commands.registerCommand('extension.background.disable', async () => {
await background.config.update('enabled', false, true);
await background.uninstall();
await vscode.commands.executeCommand('workbench.action.reloadWindow');
await vsHelp.reload();
})
);

context.subscriptions.push(
vscode.commands.registerCommand('extension.background.uninstall', async () => {
if (await background.uninstall()) {
// 当且仅当成功删除样式时才会卸载扩展
// 否则可能导致没有成功删掉样式时扩展就被卸载掉
await vscode.commands.executeCommand('workbench.extensions.uninstallExtension', EXTENSION_ID);
await vsHelp.showInfoRestart(l10n.t('Background extension has been uninstalled. See you next time!'));
}
await background.uninstall();
await vscode.commands.executeCommand('workbench.extensions.uninstallExtension', EXTENSION_ID);
vsHelp.reload({
message: l10n.t('Background extension has been uninstalled. See you next time!')
});
})
);

Expand Down
3 changes: 0 additions & 3 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ export const EXTENSION_NAME: string = pkg.name;
/** 扩展ID */
export const EXTENSION_ID = `${PUBLISHER}.${EXTENSION_NAME}`;

/** 文件锁路径 */
export const LOCK_PATH = path.join(__dirname, '../../', `${EXTENSION_ID}.lock`);

/** 版本临时文件,存放js路径、标识初次安装 */
export const TOUCH_JSFILE_PATH = path.join(__dirname, `../../vscb.${VERSION}.js.touch`);
Loading
Loading