提交 02c9d73e authored 作者: 蔡芬's avatar 蔡芬

6

上级 aab27744
...@@ -102,7 +102,14 @@ class IpcEvents { ...@@ -102,7 +102,14 @@ class IpcEvents {
// 打开某个软件 - 执行命令 // 打开某个软件 - 执行命令
ipcMain.on("openApp", (e, data) => { ipcMain.on("openApp", (e, data) => {
exec(data.execCommand); exec(data.execCommand, (error, stdout, stderr)=>{
if(error) {
console.error(error)
return;
}
if(stderr) console.error(stderr)
if(stdout) console.log(stdout)
});
}) })
// 某个路径转成base64 // 某个路径转成base64
...@@ -112,13 +119,9 @@ class IpcEvents { ...@@ -112,13 +119,9 @@ class IpcEvents {
if(imagePath && imagePath.indexOf('.png') > 0) { if(imagePath && imagePath.indexOf('.png') > 0) {
src = this.softList.pngToBase64(imagePath); src = this.softList.pngToBase64(imagePath);
}else if(imagePath && imagePath.indexOf('.svg') > 0) { }else if(imagePath && imagePath.indexOf('.svg') > 0) {
console.log('svg获取突破base64')
src = this.softList.svgToBase64(imagePath); src = this.softList.svgToBase64(imagePath);
} }
// const imageBase64 = fs.readFileSync(imagePath, 'base64');
// let src = `data:image/png;base64,${imageBase64}`;
let apps = this.store.get("apps"); let apps = this.store.get("apps");
// src = src.replace(/[\r\n]/g, '');
apps[index].icon = src || imagePath; apps[index].icon = src || imagePath;
this.store.set("apps", apps); this.store.set("apps", apps);
......
...@@ -52,9 +52,7 @@ class SoftList { ...@@ -52,9 +52,7 @@ class SoftList {
let loMax = 0; let loMax = 0;
iconList.forEach(v => { iconList.forEach(v => {
if(v && typeof v =='string' && v.indexOf('/hicolor/')>0) { if(v && typeof v =='string' && v.indexOf('/hicolor/')>0) {
// /usr/share/icons/hicolor/48x48/apps/gvim.png
let str = v.replace('/usr/share/icons/hicolor/','') let str = v.replace('/usr/share/icons/hicolor/','')
if(name && name.indexOf('Visual Studio Code') >= 0) console.log('str',str)
if(str.indexOf('/')>0 && str.split('/')[0] && str.split('/')[0].indexOf('x')>0) { if(str.indexOf('/')>0 && str.split('/')[0] && str.split('/')[0].indexOf('x')>0) {
let curHi = Number(str.split('/')[0].split('x')[0]); let curHi = Number(str.split('/')[0].split('x')[0]);
if(name && name.indexOf('Visual Studio Code') >= 0) console.log('curHi', curHi) if(name && name.indexOf('Visual Studio Code') >= 0) console.log('curHi', curHi)
...@@ -63,10 +61,8 @@ class SoftList { ...@@ -63,10 +61,8 @@ class SoftList {
hicolorIcon = v; hicolorIcon = v;
} }
} }
// hicolorIcon = v;
} }
if(v && typeof v =='string' && v.indexOf('/locolor/')>0) { if(v && typeof v =='string' && v.indexOf('/locolor/')>0) {
// /usr/share/icons/locolor/48x48/apps/gvim.png
let str = v.replace('/usr/share/icons/locolor/','') let str = v.replace('/usr/share/icons/locolor/','')
if(str.indexOf('/')>0 && str.split('/')[0] && str.split('/')[0].indexOf('x')>0) { if(str.indexOf('/')>0 && str.split('/')[0] && str.split('/')[0].indexOf('x')>0) {
let curLo = Number(str.split('/')[0].split('x')[0]); let curLo = Number(str.split('/')[0].split('x')[0]);
...@@ -75,7 +71,6 @@ class SoftList { ...@@ -75,7 +71,6 @@ class SoftList {
locolorIcon = v; locolorIcon = v;
} }
} }
// locolorIcon = v;
} }
}) })
...@@ -85,9 +80,6 @@ class SoftList { ...@@ -85,9 +80,6 @@ class SoftList {
iconList = iconList.filter(v => v && (v.indexOf('.png')>0 || v.indexOf('.svg')>0)) iconList = iconList.filter(v => v && (v.indexOf('.png')>0 || v.indexOf('.svg')>0))
icon = iconList[0]; icon = iconList[0];
} }
console.log(name)
if(name && name.indexOf('Visual Studio Code') >= 0) console.log(iconList)
if(name && name.indexOf('Visual Studio Code') >= 0 ) console.log(hicolorIcon,locolorIcon)
return icon; return icon;
} }
/* 获取linux 快捷方式 列表 */ /* 获取linux 快捷方式 列表 */
...@@ -99,16 +91,31 @@ class SoftList { ...@@ -99,16 +91,31 @@ class SoftList {
} }
try { try {
const apps = stdout.trim().split('\n').map(file => { const apps = stdout.trim().split('\n').map(file => {
const content = fs.readFileSync(file, 'utf8'); const content = fs.readFileSync(file, 'utf-8');
const execRegExp = /^Exec=(.*)$/m;
const execMatch = content.match(execRegExp);
const lines = content.trim().split('\n'); const lines = content.trim().split('\n');
const nameLine = lines.find(line => line.startsWith('Name=')); const nameLine = lines.find(line => line.startsWith('Name='));
const name = nameLine ? nameLine.substr(5) : path.basename(file, '.desktop'); const name = nameLine ? nameLine.substr(5) : path.basename(file, '.desktop');
const iconLine = lines.find(line => line.startsWith('Icon=')); const iconLine = lines.find(line => line.startsWith('Icon='));
let icon = iconLine ? iconLine.substr(5) : null; let icon = iconLine ? iconLine.substr(5) : null;
const execLine = lines.find(line => line.startsWith('Exec='));
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(12) : '';
const typeLine = lines.find(line => line.startsWith('Type=')); //Type=Application;
const type = typeLine ? typeLine.substr(5) : null;
const noDisplayLine = lines.find(line => line.startsWith('NoDisplay='));
const noDisplay = noDisplayLine ? noDisplayLine.substr(10) : null;
console.log('execMatch', execMatch)
let execCommand = '';
if(execMatch) {
execCommand = execMatch[1];
}else {
const execLine = lines.find(line => line.startsWith('Exec='));
execCommand = execLine ? execLine.substr(5) : null;
}
let iconList = []; let iconList = [];
// icon判断是否绝对路径 // icon判断是否绝对路径
...@@ -121,33 +128,17 @@ class SoftList { ...@@ -121,33 +128,17 @@ class SoftList {
icon = this.getMaxPix({name, iconList, icon}) icon = this.getMaxPix({name, iconList, icon})
} }
} }
// 图标为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=”行。这一行包含应用程序的图标文件的路径。
// 3. 使用以下代码来将图标文件转换为base64编码:
// ```
// base64 -w 0 /usr/share/icons/hicolor/48x48/apps/${icon}
// ```
// try {
// var res = execSync(`base64 -w 0 /usr/share/icons/hicolor/48x48/apps/${icon}.png`
// , { encoding: 'utf8' });
// if(res) icon = res;
// } catch (error) {
// console.error(error)
// }
return { return {
type,
iconList: iconList || [], iconList: iconList || [],
nameOfZh, nameOfZh,
name, name,
icon, icon,
execCommand, execCommand,
noDisplay
}; };
}); });
let newApps = apps.filter(v => !!v.icon); let newApps = apps.filter(v => !!v.icon && v.type=='Application' && (v.noDisplay != true && v.noDisplay != 'true'));
this.store.set('apps', newApps); this.store.set('apps', newApps);
this.mainWindow.win.webContents.send("appsList", newApps); this.mainWindow.win.webContents.send("appsList", newApps);
} catch (error) { } catch (error) {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论