Skip to content

Commit

Permalink
change windows desktop icon
Browse files Browse the repository at this point in the history
  • Loading branch information
HowcanoeWang committed Sep 24, 2023
1 parent 0c53c8d commit efce9d1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* <b style='color:red'>此插件所使用的图片、图标、音乐和视频片段版权均归米哈游所有。该插件并非思源笔记的官方功能,是插件作者个人为学习前端开发而创建的,供插件开发者学习交流使用,所有代码和素材均无偿公开,请勿用于其他商业用途。</b>
* **此插件通过替换安装目录文件实现,会影响所有的工作空间。**
* 目前仅支持Windows端和MacOS端
* Windows端需要管理员权限才可以实现替换。
* Windows端需要管理员权限才可以实现替换(<b style='color:red'>默认为全局安装在<code>C:\Program Files</code>中</b>)
* Linux端由于AppImage每次运行都在临时文件夹内,故替换后重启不起效。
* 安卓端的傻\*文件权限管理直接锁死了这条技术路线。
* 重装思源可以解决因这个插件引起的所有问题。
Expand Down
2 changes: 1 addition & 1 deletion README_en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ English | [简体中文](https://github.com/HowcanoeWang/siyuan-genshin-launcher
* <b style='color:red'>The copyright of the images, icons, music, and video clips used in this plugin belongs to miHoYo. This plugin is not an official feature of SiYuan Note, but was created by the plugin author for personal learning of front-end development. It is provided as teaching and learning purposes for plugin developers. All code and materials are publicly available for free, please do not use for other commercial purposes.</b>
* **This plugin achieves its functionality by replacing files in the installation directory, which will affect all workspaces!**</b>**
* Currently only supports Windows and MacOS
* Windows requires administrator privileges for replacement.
* Windows requires administrator privileges for replacement (<b style='color:red'>Installed into <code>C:\Program Files</code> globally</b>).
* The Linux version does not work after restarting due to AppImage running in a temporary folder each time.
* The f\*\*king stupid file permission in the Android 11+ completely blocks this technical approach.
* Reinstalling SiYuan can solve all issues caused by this plugin.
Expand Down
11 changes: 11 additions & 0 deletions source/changeDesktopIcon.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
param(
[string]$icoPath=''
)

$publiclink='C:\Users\Public\Desktop\SiYuan.lnk'

# Write-Output $publiclink $icoPath
$shell = New-Object -ComObject ("WScript.Shell")
$shortcut = $Shell.CreateShortcut($publiclink)
$Shortcut.IconLocation = $icoPath
$Shortcut.Save()
3 changes: 2 additions & 1 deletion src/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"inDevModeLabel": "Developer mode",
"inDevModeDes": "Show more logs when open (debug log for waifu need refresh the siyuan note)",
"batchTitle": "Execute",
"batchDes": "Will execute the following commands, please confirm\n\n"
"batchDes": "Will execute the following commands, please confirm\n\n",
"batchDone": "Finish executing, your can close this window"
}
3 changes: 2 additions & 1 deletion src/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"inDevModeLabel": "开发者模式",
"inDevModeDes": "开启后将显示更多日志输出(看板娘debug日志需要刷新页面生效)",
"batchTitle": "批处理",
"batchDes": "将会执行下述脚本,请确认\n\n"
"batchDes": "将会执行下述脚本,请确认\n\n",
"batchDone": "运行结束,你可以关闭此窗口"
}
25 changes: 23 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export default class PluginSample extends Plugin {
// var userProfilePath = process.env.USERPROFILE;
// userProfilePath = userProfilePath .replaceAll('\\', '/');
// this.execudeCMD(`Remove-Item -Path '${userProfilePath}/AppData/Local/Microsoft/Windows/Explorer/iconcache_*.db' -Force;`)

// this.execudeCMD(`powershell ${this.dataDir}/plugins/${pname}/source/changeDesktopIcon.ps1 -icoPath ${this.dataDir}/plugins/${pname}/source/iconWin.ico`);
}

onunload() {
Expand Down Expand Up @@ -282,7 +284,7 @@ export default class PluginSample extends Plugin {
return `${ceiExeFile} '${icoFile}' '${siyuanExeFile}' '${siyuanExeChangedFile}'`
}

public async execudeCMD(cmdStr:string){
public async execudeCMD(cmdStr:string, isFile:boolean=false){
// const demoCMD = "cp 'C:\\Users\\hwang\\Desktop\\aaa.bmp' 'C:\\Program Files\\SiYuan\\resources\\aaa.bmp'"
const spawn = (window as any).require('child_process').spawn;

Expand All @@ -298,13 +300,19 @@ export default class PluginSample extends Plugin {
var spawn_param:{};

if (this.os === 'windows') {
spawn_cmd = `Start-Process powershell.exe -Verb runAs -ArgumentList \"-NoExit -Command ${cmdStr}\"`;
if (isFile) {
spawn_cmd = `Start-Process powershell.exe -Verb runAs -ArgumentList "-NoExit", "-File", "${cmdStr}"`;
} else {
spawn_cmd = `Start-Process powershell.exe -Verb runAs -ArgumentList "-NoExit", "-Command", "${cmdStr}"`;
}
spawn_param = {shell:"powershell.exe"};
} else {
spawn_cmd = cmdStr;
spawn_param = {shell: true};
}

debug(`[index.ts][execudeCMD]: `, spawn_cmd)

const child = spawn(spawn_cmd, spawn_param,
(error: any, stdout: any, stderr: any) => {
if (error) {
Expand Down Expand Up @@ -500,6 +508,12 @@ export default class PluginSample extends Plugin {
const clearCacheStr = this.clearWinCache();

finCmdStr += winChangeExeStr + ` ${spara} ` + clearCacheStr;

// replace desktop icon by powershell file
finCmdStr += `powershell -File ${this.dataDir}/plugins/${pname}/source/changeDesktopIcon.ps1 -icoPath '${this.dataDir}/plugins/${pname}/source/iconWin.ico'`

// notice finish
finCmdStr += ` ${spara} ` + `Write-Output '${this.i18n.batchDone}';`;
}

debug(`[index.ts][openSetting] final execude cmd ${finCmdStr}`);
Expand Down Expand Up @@ -546,6 +560,13 @@ export default class PluginSample extends Plugin {
const clearCacheStr = this.clearWinCache();

finCmdStr += clearCacheStr;

// replace desktop icon by powershell file
const originalExe = this.appDir.replace('/resources', '/') + 'SiYuan.exe'
finCmdStr += `powershell -File ${this.dataDir}/plugins/${pname}/source/changeDesktopIcon.ps1 -icoPath '${originalExe}'`

// notice finish
finCmdStr += ` ${spara} ` + `Write-Output '${this.i18n.batchDone}';`;
}

info(`[index.ts][openSetting] click recover btn, execute the following command: ${finCmdStr}`);
Expand Down

0 comments on commit efce9d1

Please sign in to comment.