node获取桌面快捷图标
引入模块
const electron =
process.env.IS_ELECTRON === true ? window.require('electron') : null;
const remote = process.env.IS_ELECTRON === true ? electron.remote : null;
const app = process.env.IS_ELECTRON === true ? remote.app : null;
const shell = process.env.IS_ELECTRON === true ? electron.shell : null;
const dialog = process.env.IS_ELECTRON === true ? remote.dialog : null;
const path = require('path');
const fs = require('fs');
//获取桌面的路径
const desktopPath = app.getPath('desktop')
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
关键脚本
let desktopFiles = fs.readdirSync(desktopPath);
for (let file of desktopFiles) {
let url = undefined;
const fileName = file.split('.')[0];
const suffix = file.split('.')[1];
const fileUrl = desktopPath + '\\' + file;
if (suffix === 'lnk') {
try {
let lnk = shell.readShortcutLink(fileUrl);
url = lnk.target;
} catch (e) {
url = '';
console.log(fileUrl + '获取快捷方式源目录失败');
}
}
if (url) {
let application = {};
application.url = url;
application.text = fileName;
await app.getFileIcon(url).then(fileIcon => {
application.imgSrc = fileIcon.toDataURL();
});
this.localApplicationData.push(application);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
上次更新: 2023/08/06, 22:51:57
