Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
testMenu
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
蔡芬
testMenu
Commits
f0ba692e
提交
f0ba692e
authored
3月 23, 2023
作者:
蔡芬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
not finished
上级
893cf9db
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
60 行增加
和
8 行删除
+60
-8
linux.js
linux.js
+1
-1
ipc.js
src/main/events/ipc.js
+7
-7
softList.js
src/main/plugins/softList.js
+52
-0
没有找到文件。
linux.js
浏览文件 @
f0ba692e
...
...
@@ -13,7 +13,7 @@
```
echo $(grep -i "^Icon=" /usr/share/applications/<application-name>.desktop | cut -d'=' -f2 | sed 's/\s//g') | xargs -I{} xdg-icon-resource lookup --size 48 {}
```
```
。
其中,`48`是您想要获取的图标大小。如果应用程序没有指定图标,则此方法将无法获取图标URL。
在Linux中,应用程序图标的大小通常有以下几个:
...
...
src/main/events/ipc.js
浏览文件 @
f0ba692e
...
...
@@ -142,13 +142,13 @@ class IpcEvents {
appList
.
splice
(
resIndex
,
1
,
temp
);
}
else
{
// 新增
//mac
addFile
.
execCommand
=
`open '
${
addFile
.
path
}
'`
;
addFile
.
name
=
addFile
.
shortName
;
// addFile.icon = '';
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
);
if
(
process
.
platform
===
'linux'
)
{
// 当前是Linux平台
this
.
softList
.
getFileInfo_linux
()
;
}
else
if
(
process
.
platform
===
'darwin'
)
{
// 当前是macOS平台
addFile
=
this
.
softList
.
getFileInfo_mac
(
addFile
);
}
appList
.
splice
(
targetIndex
,
0
,
addFile
)
}
// 刷新渲染进程app列表
...
...
src/main/plugins/softList.js
浏览文件 @
f0ba692e
...
...
@@ -137,6 +137,14 @@ class SoftList {
console
.
log
(
'getMacIconPath'
,
appPath
)
let
tempPathArr
=
[];
let
lastIndexItem
=
''
;
if
(
!
fileName
)
{
console
.
log
(
'fileName缺少'
)
return
''
;
}
if
(
!
appPath
)
{
console
.
log
(
'appPath缺少'
)
return
''
;
}
fileName
=
fileName
.
indexOf
(
'.app'
)
?
fileName
:
fileName
+
'.app'
;
if
(
appPath
)
{
tempPathArr
=
appPath
.
split
(
'/'
);
...
...
@@ -163,6 +171,17 @@ class SoftList {
icon
=
icon
.
length
>
0
?
icon
[
0
]
:
''
;
return
icon
;
}
// 获取linux 图标
getLinuxIconPath
()
{
try
{
// 获取图标
var
res
=
execSync
(
`echo $(grep -i "^Icon=" /usr/share/applications/<application-name>.desktop | cut -d'=' -f2 | sed 's/\s//g') | xargs -I{} xdg-icon-resource lookup --size 48 {}`
,
{
encoding
:
'utf8'
});
}
catch
(
e
)
{
// console.log("Errors:", e);
return
icon
;
}
}
// 将.icns文件转为.png文件
icns2Png
({
iconPath
,
fileNameShort
})
{
...
...
@@ -187,6 +206,39 @@ class SoftList {
return
src
;
}
// SVG文件转换为Base64
svgToBase64
(
svgPath
)
{
const
svg
=
fs
.
readFileSync
(
svgPath
,
'utf-8'
);
// 把SVG文件转换为Base64字符串
const
base64
=
Buffer
.
from
(
svg
).
toString
(
'base64'
);
// <img src="data:image/svg+xml;base64,${base64}" />
return
`data:image/svg+xml;base64,
${
base64
}
`
;
}
// 获取linux软件信息
getFileInfo_linux
(
addFile
=
{})
{
//Object: {path,shortName,name}
//linux
addFile
.
execCommand
=
`open '
${
addFile
.
path
}
'`
;
addFile
.
name
=
addFile
.
shortName
;
// addFile.icon = '';
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
);
return
addFile
;
}
// 获取mac软件信息
getFileInfo_mac
(
addFile
=
{})
{
//Object: {path,shortName,name}
//mac
addFile
.
execCommand
=
`open '
${
addFile
.
path
}
'`
;
addFile
.
name
=
addFile
.
shortName
;
// addFile.icon = '';
addFile
.
icon
=
this
.
getMacIconPath
({
fileName
:
addFile
.
shortName
,
appPath
:
addFile
.
path
});
addFile
.
icon
=
this
.
icns2Png
({
iconPath
:
addFile
.
icon
,
fileNameShort
:
addFile
.
shortName
});
addFile
.
icon
=
this
.
pngToBase64
(
addFile
.
icon
);
return
addFile
;
}
/* 获取翻译函数(为了保持this正确指向)*/
get
()
{
return
i
=>
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论