提交 3ee1dc54 authored 作者: 蔡芬's avatar 蔡芬

合并分支 'master-0404' 到 'master'

list 查看合并请求 !1
const { exec, execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
class SoftList {
constructor (mainWindow) {
......@@ -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 快捷方式 列表 */
getLinuxList() {
exec('ls /usr/share/applications/*.desktop', (error, stdout, stderr) => {
......@@ -47,10 +59,17 @@ class SoftList {
const execCommand = execLine ? execLine.substr(5) : null;
const nameOfZhLine = lines.find(line => line.startsWith('Name[zh_CN]='));
const nameOfZh = nameOfZhLine ? nameOfZhLine.substr(5) : '';
// 图标为SVG或PNG格式
if(icon && icon.indexOf(".png") == -1) {
icon = `/usr/share/icons/hicolor/48x48/apps/${icon}.png`
// icon判断是否绝对路径
if( !path.isAbsolute( icon ) ) {
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}`
// 2. 打开应用程序的.desktop文件,并查找“Icon=”行。这一行包含应用程序的图标文件的路径。
......@@ -221,6 +240,7 @@ class SoftList {
addFile.execCommand = `open '${addFile.path}'`;
addFile.name = addFile.shortName;
// addFile.icon = '';
// process.platform === 'linux'
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.pngToBase64(addFile.icon);
......@@ -245,7 +265,8 @@ class SoftList {
// return this.$t(i)
return 1
}
}
}
}
export default SoftList
......@@ -31,6 +31,7 @@ class MainWindow {
} else {
createProtocol('app')
this.win.loadURL('app://./index.html')
this.win.webContents.openDevTools({ mode: 'detach' })
}
this.win.on('closed', () => {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论