Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
testMenu
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
蔡芬
testMenu
Commits
02c9d73e
提交
02c9d73e
authored
4月 04, 2023
作者:
蔡芬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6
上级
aab27744
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
30 行增加
和
36 行删除
+30
-36
ipc.js
src/main/events/ipc.js
+8
-5
softList.js
src/main/plugins/softList.js
+22
-31
没有找到文件。
src/main/events/ipc.js
浏览文件 @
02c9d73e
...
...
@@ -102,7 +102,14 @@ class IpcEvents {
// 打开某个软件 - 执行命令
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
...
...
@@ -112,13 +119,9 @@ class IpcEvents {
if
(
imagePath
&&
imagePath
.
indexOf
(
'.png'
)
>
0
)
{
src
=
this
.
softList
.
pngToBase64
(
imagePath
);
}
else
if
(
imagePath
&&
imagePath
.
indexOf
(
'.svg'
)
>
0
)
{
console
.
log
(
'svg获取突破base64'
)
src
=
this
.
softList
.
svgToBase64
(
imagePath
);
}
// const imageBase64 = fs.readFileSync(imagePath, 'base64');
// let src = `data:image/png;base64,${imageBase64}`;
let
apps
=
this
.
store
.
get
(
"apps"
);
// src = src.replace(/[\r\n]/g, '');
apps
[
index
].
icon
=
src
||
imagePath
;
this
.
store
.
set
(
"apps"
,
apps
);
...
...
src/main/plugins/softList.js
浏览文件 @
02c9d73e
...
...
@@ -52,9 +52,7 @@ class SoftList {
let
loMax
=
0
;
iconList
.
forEach
(
v
=>
{
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/'
,
''
)
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
)
{
let
curHi
=
Number
(
str
.
split
(
'/'
)[
0
].
split
(
'x'
)[
0
]);
if
(
name
&&
name
.
indexOf
(
'Visual Studio Code'
)
>=
0
)
console
.
log
(
'curHi'
,
curHi
)
...
...
@@ -63,10 +61,8 @@ class SoftList {
hicolorIcon
=
v
;
}
}
// hicolorIcon = v;
}
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/'
,
''
)
if
(
str
.
indexOf
(
'/'
)
>
0
&&
str
.
split
(
'/'
)[
0
]
&&
str
.
split
(
'/'
)[
0
].
indexOf
(
'x'
)
>
0
)
{
let
curLo
=
Number
(
str
.
split
(
'/'
)[
0
].
split
(
'x'
)[
0
]);
...
...
@@ -75,7 +71,6 @@ class SoftList {
locolorIcon
=
v
;
}
}
// locolorIcon = v;
}
})
...
...
@@ -85,9 +80,6 @@ class SoftList {
iconList
=
iconList
.
filter
(
v
=>
v
&&
(
v
.
indexOf
(
'.png'
)
>
0
||
v
.
indexOf
(
'.svg'
)
>
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
;
}
/* 获取linux 快捷方式 列表 */
...
...
@@ -99,16 +91,31 @@ class SoftList {
}
try
{
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
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='
));
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
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
=
[];
// icon判断是否绝对路径
...
...
@@ -121,33 +128,17 @@ class SoftList {
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
{
type
,
iconList
:
iconList
||
[],
nameOfZh
,
name
,
icon
,
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
.
mainWindow
.
win
.
webContents
.
send
(
"appsList"
,
newApps
);
}
catch
(
error
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论