Skip to content

Commit

Permalink
Merge pull request #154 from AShujiao/2.6.2
Browse files Browse the repository at this point in the history
2.6.2
  • Loading branch information
AShujiao authored Nov 20, 2024
2 parents b32f200 + 109516c commit bc9c4c0
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 55 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

1.修复vsc1.94.0版本导致的异常

#### ver 2.6.1 (2024/11/12)
#### ver 2.6.2 (2024/11/12)

1.底层实现方式由css改为js(修复重载不生效的问题)
2.增加背景模糊效果
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Add a picture you like to cover the entire vscode..

## Warns 警告:

> **升级到2.6.1后如果出现背景重叠的情况,请关闭vsc重新打开即可。因为旧版本的重载不生效导致的**
> **升级到2.6.2后如果出现背景重叠的情况,请关闭vsc重新打开即可。因为旧版本的重载不生效导致的**
> **If the background overlaps after the upgrade to 2.6.1, close the vsc and turn it on again. This is because the older version of the overloading did not take effect**
> **If the background overlaps after the upgrade to 2.6.2, close the vsc and turn it on again. This is because the older version of the overloading did not take effect**
> **本插件是通过修改 vscode 的 css 文件的方式运行**
> 所以会在初次安装,或者 vscode 升级的时候,出现以下提示,请选择 【不再提示】:
Expand Down Expand Up @@ -129,7 +129,7 @@ Add a picture you like to cover the entire vscode..
## 最近更新日志
[完整日志](https://github.com/vscode-extension/vscode-background-cover/blob/master/CHANGELOG.md)

#### ver 2.6.1 (2024/11/12)
#### ver 2.6.2 (2024/11/12)

1.底层实现方式由css改为js(修复重载不生效的问题)
2.增加背景模糊效果
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "background-cover",
"displayName": "background-cover",
"description": "Add a picture you like to cover the entire vscode..",
"version": "2.6.1",
"version": "2.6.2",
"publisher": "manasxx",
"engines": {
"vscode": "^1.38.0"
Expand Down
84 changes: 38 additions & 46 deletions src/FileDom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class FileDom {

// 获取全局变量是否已经清除
let vsContext = getContext();
let clearCssNum = Number(vsContext.globalState.get('ext_backgroundCover_clear')) || 0;
let clearCssNum = Number(vsContext.globalState.get('ext_backgroundCover_clear_v2')) || 0;
// 尝试5次清除旧版css文件
if(clearCssNum <= 5){
// 验证旧版css文件是否需要清除
Expand All @@ -87,7 +87,7 @@ export class FileDom {
this.upCssContent = this.clearCssContent(cssContent);
}else{
// 不存在旧版css文件,设置全局变量
vsContext.globalState.update('ext_backgroundCover_clear',clearCssNum + 1);
vsContext.globalState.update('ext_backgroundCover_clear_v2',clearCssNum + 1);
}
}

Expand Down Expand Up @@ -118,17 +118,8 @@ export class FileDom {
}

const newContent = bakContent + content;
return await this.saveContent(newContent);

switch (this.systemType) {
case SystemType.WINDOWS:
return await this.installWindows(newContent);
case SystemType.MACOS:
return await this.installMacOS(newContent);
case SystemType.LINUX:
return await this.installLinux(newContent);
default:
throw new Error('Unsupported operating system');
}
} catch (error: any) {
await window.showErrorMessage(`Installation failed: ${error.message}`);
return false;
Expand All @@ -140,40 +131,22 @@ export class FileDom {
}
}

private async installWindows(content: string): Promise<boolean> {
try {
await this.saveContent(content);
return true;
} catch (error) {
// 权限不足时,修改文件权限,使用cmd命令
await SudoPromptHelper.exec(`takeown /f "${this.filePath}" /a`);
await SudoPromptHelper.exec(`icacls "${this.filePath}" /grant Users:F`);
await this.saveContent(content);
return true;
// 获取文件权限通用方法
public async getFilePermission(filePath:string): Promise<void> {
switch(this.systemType){
case SystemType.WINDOWS:
await SudoPromptHelper.exec(`takeown /f "${filePath}" /a`);
await SudoPromptHelper.exec(`icacls "${filePath}" /grant Users:F`);
break;
case SystemType.MACOS:
await SudoPromptHelper.exec(`chmod a+rwx "${filePath}"`);
break;
case SystemType.LINUX:
await SudoPromptHelper.exec(`chmod 666 "${filePath}"`);
break;
}
}

private async installMacOS(content: string): Promise<boolean> {
try {
await this.saveContent(content);
return true;
} catch {
await SudoPromptHelper.exec(`chmod a+rwx "${this.filePath}"`);
await this.saveContent(content);
return true;
}
}

private async installLinux(content: string): Promise<boolean> {
try {
await this.saveContent(content);
return true;
} catch {
await SudoPromptHelper.exec(`chmod 666 "${this.filePath}"`);
await this.saveContent(content);
return true;
}
}

public async uninstall(): Promise<boolean> {
try {
Expand All @@ -191,17 +164,36 @@ export class FileDom {
return fs.readFileSync(filePath, 'utf-8');
}

private async saveContent(content: string): Promise<void> {
private async saveContent(content: string): Promise<boolean> {

// 追加新内容到原文件
await fse.writeFile(this.filePath,content, {encoding: 'utf-8'});
try{
await fse.writeFile(this.filePath,content, {encoding: 'utf-8'});
}catch(err){
// 权限不足,根据不同系统获取创建文件权限
await this.getFilePermission(this.filePath);
await fse.writeFile(this.filePath,content, {encoding: 'utf-8'});
}


// 清除旧版css文件
if(this.upCssContent){
await fse.writeFile(cssFilePath,this.upCssContent, {encoding: 'utf-8'});
try{
await fse.writeFile(cssFilePath,this.upCssContent, {encoding: 'utf-8'});
}catch(err){
// 权限不足,根据不同系统获取创建文件权限
await this.getFilePermission(cssFilePath);
await fse.writeFile(cssFilePath,this.upCssContent, {encoding: 'utf-8'});
}
this.upCssContent = '';
}

// 备份文件
if(this.bakStatus){
await this.bakFile();
}

return true;
}

private async bakFile(): Promise<void> {
Expand Down
7 changes: 6 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ export function activate(context: ExtensionContext) {
let title:string = ex ? ex.packageJSON['one_title'] : '';
if(openVersion != version && title != ""){
context.globalState.update('ext_version',version);
vsHelp.showInfoSupport('🐷已更新到2.6.1:增加了超超超炫酷的模糊背景!\r🐶是否愿意帮助在线图库社区运营🐶❓');
vsHelp.showInfoSupport(`
🐷已更新到2.6.2🐷----------------------------------------------
🐷增加了背景模糊效果!----------------------------------------
🐷自动获取文件权限!------------------------------------------
🐶是否愿意帮助在线图库社区运营🐶❓`
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* @Date: 2023-08-25 10:00:03
* @FilePath: \vscode-background-cover\src\version.ts
*/
export default '2.6.1';
export default '2.6.2';

0 comments on commit bc9c4c0

Please sign in to comment.