提交 4a9a085d authored 作者: macmini's avatar macmini

list

上级 f0ba692e
This source diff could not be displayed because it is too large. You can view the blob instead.
const { exec, execSync } = require('child_process'); const { exec, execSync } = require('child_process');
const fs = require('fs'); const fs = require('fs');
const path = require('path');
class SoftList { class SoftList {
constructor (mainWindow) { constructor (mainWindow) {
...@@ -29,6 +30,17 @@ class SoftList { ...@@ -29,6 +30,17 @@ class SoftList {
} }
} }
/* 查找linux icon */
findIcon(iconName) {
try {
const stdout = execSync(`find /usr/share/icons -name "${iconName}.*"`);
const iconPaths = stdout.toString().split('\n').filter(path => path.trim() !== '');
return iconPaths;
} catch (error) {
console.error(`命令执行失败: ${error}`);
return null;
}
}
/* 获取linux 快捷方式 列表 */ /* 获取linux 快捷方式 列表 */
getLinuxList() { getLinuxList() {
exec('ls /usr/share/applications/*.desktop', (error, stdout, stderr) => { exec('ls /usr/share/applications/*.desktop', (error, stdout, stderr) => {
...@@ -47,10 +59,17 @@ class SoftList { ...@@ -47,10 +59,17 @@ class SoftList {
const execCommand = execLine ? execLine.substr(5) : null; const execCommand = execLine ? execLine.substr(5) : null;
const nameOfZhLine = lines.find(line => line.startsWith('Name[zh_CN]=')); const nameOfZhLine = lines.find(line => line.startsWith('Name[zh_CN]='));
const nameOfZh = nameOfZhLine ? nameOfZhLine.substr(5) : ''; const nameOfZh = nameOfZhLine ? nameOfZhLine.substr(5) : '';
// 图标为SVG或PNG格式 // icon判断是否绝对路径
if(icon && icon.indexOf(".png") == -1) { if( !path.isAbsolute( icon ) ) {
icon = `/usr/share/icons/hicolor/48x48/apps/${icon}.png` let iconList = this.findIcon(icon );
if(iconList.length > 0) {
icon = iconList[0];
}
} }
// 图标为SVG或PNG格式
// if(icon && icon.indexOf(".png") == -1) {
// icon = `/usr/share/icons/hicolor/48x48/apps/${icon}.png`
// }
// icon = `/usr/share/icons/hicolor/48x48/apps/${icon}` // icon = `/usr/share/icons/hicolor/48x48/apps/${icon}`
// 2. 打开应用程序的.desktop文件,并查找“Icon=”行。这一行包含应用程序的图标文件的路径。 // 2. 打开应用程序的.desktop文件,并查找“Icon=”行。这一行包含应用程序的图标文件的路径。
...@@ -221,6 +240,7 @@ class SoftList { ...@@ -221,6 +240,7 @@ class SoftList {
addFile.execCommand = `open '${addFile.path}'`; addFile.execCommand = `open '${addFile.path}'`;
addFile.name = addFile.shortName; addFile.name = addFile.shortName;
// addFile.icon = ''; // addFile.icon = '';
// process.platform === 'linux'
addFile.icon = this.softList.getMacIconPath({fileName:addFile.shortName, appPath:addFile.path}); addFile.icon = this.softList.getMacIconPath({fileName:addFile.shortName, appPath:addFile.path});
addFile.icon = this.softList.icns2Png({iconPath:addFile.icon,fileNameShort:addFile.shortName}); addFile.icon = this.softList.icns2Png({iconPath:addFile.icon,fileNameShort:addFile.shortName});
addFile.icon = this.softList.pngToBase64(addFile.icon); addFile.icon = this.softList.pngToBase64(addFile.icon);
...@@ -245,7 +265,8 @@ class SoftList { ...@@ -245,7 +265,8 @@ class SoftList {
// return this.$t(i) // return this.$t(i)
return 1 return 1
} }
} }
} }
export default SoftList export default SoftList
...@@ -31,6 +31,7 @@ class MainWindow { ...@@ -31,6 +31,7 @@ class MainWindow {
} else { } else {
createProtocol('app') createProtocol('app')
this.win.loadURL('app://./index.html') this.win.loadURL('app://./index.html')
this.win.webContents.openDevTools({ mode: 'detach' })
} }
this.win.on('closed', () => { this.win.on('closed', () => {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论