提交 2c08361f authored 作者: 蔡芬's avatar 蔡芬

1

上级 baa75ac6
import { BrowserWindow, Menu, app, globalShortcut, shell, remote } from 'electron'
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
const fs = require('fs');
const path = require('path')
const Store = require('electron-store');
const { exec } = require('child_process');
const store = new Store({
defaults: {
apps: [],
},
});
class MainWindow {
constructor (win) {
......@@ -87,7 +96,8 @@ class MainWindow {
this.openWithBrowser()
// 应用程序的“关于”面板
this.setAboutPanel()
// 读取Linux系统中已经安装的软件
this.updateAppsList()
}
setWindowMenu () {
......@@ -179,6 +189,34 @@ class MainWindow {
// };
// });
}
updateAppsList() {
exec('ls /usr/share/applications/*.desktop', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
const apps = stdout.trim().split('\n').map(file => {
const content = fs.readFileSync(file, 'utf8');
const lines = content.trim().split('\n');
const nameLine = lines.find(line => line.startsWith('Name='));
const name = nameLine ? nameLine.substr(5) : path.basename(file, '.desktop');
const iconLine = lines.find(line => line.startsWith('Icon='));
const icon = iconLine ? iconLine.substr(5) : null;
const execLine = lines.find(line => line.startsWith('Exec='));
const execCommand = execLine ? execLine.substr(5) : null;
return {
name,
icon,
execCommand,
};
});
store.set('apps', apps);
// updateContextMenu();
});
}
}
export default MainWindow
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论