Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
testMenu
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
蔡芬
testMenu
Commits
aab27744
提交
aab27744
authored
4月 04, 2023
作者:
蔡芬
浏览文件
操作
浏览文件
下载
差异文件
合并分支 'test-001' 到 'master'
3 查看合并请求
!5
上级
ce90732f
c4be389e
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
149 行增加
和
65 行删除
+149
-65
ipc.js
src/main/events/ipc.js
+11
-4
softList.js
src/main/plugins/softList.js
+125
-56
mainWindow.js
src/main/windows/mainWindow.js
+1
-1
App.vue
src/renderer/App.vue
+12
-4
没有找到文件。
src/main/events/ipc.js
浏览文件 @
aab27744
...
...
@@ -108,11 +108,18 @@ class IpcEvents {
// 某个路径转成base64
ipcMain
.
on
(
"getBase64"
,
(
e
,
{
imagePath
,
index
})
=>
{
try
{
const
imageBase64
=
fs
.
readFileSync
(
imagePath
,
'base64'
);
let
src
=
`data:image/png;base64,
${
imageBase64
}
`
;
let
src
=
''
;
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
;
//
src = src.replace(/[\r\n]/g, '');
apps
[
index
].
icon
=
src
||
imagePath
;
this
.
store
.
set
(
"apps"
,
apps
);
e
.
sender
.
send
(
"base64Info"
,
{
url
:
src
,
index
});
...
...
src/main/plugins/softList.js
浏览文件 @
aab27744
...
...
@@ -11,19 +11,22 @@ class SoftList {
/* 获取app列表 */
getList
()
{
console
.
log
(
'获取app列表'
)
this
.
mainWindow
.
win
.
webContents
.
send
(
'getMsg'
,
'获取app列表'
)
let
appsList
=
this
.
store
.
get
(
'apps'
);
if
(
appsList
&&
appsList
.
length
>
0
)
{
// 已有app列表
console
.
log
(
'apps-length'
,
appsList
.
length
)
return
;
}
//
if(appsList && appsList.length > 0) {
//
// 已有app列表
//
console.log('apps-length', appsList.length)
//
return;
//
}
if
(
process
.
platform
===
'linux'
)
{
// 当前是Linux平台
console
.
log
(
'当前是Linux平台'
)
this
.
mainWindow
.
win
.
webContents
.
send
(
'getMsg'
,
'当前是Linux平台'
)
this
.
getLinuxList
();
}
else
if
(
process
.
platform
===
'darwin'
)
{
// 当前是macOS平台
console
.
log
(
'当前是macOS平台'
)
this
.
mainWindow
.
win
.
webContents
.
send
(
'getMsg'
,
'当前是macOS平台'
)
this
.
getMacList
();
}
else
{
// 其他平台
...
...
@@ -31,16 +34,62 @@ class SoftList {
}
/* 查找linux icon */
findIcon
(
iconName
)
{
findIcon
(
iconName
,
pathBase
)
{
///usr/share/icons
try
{
const
stdout
=
execSync
(
`find
/usr/share/icons
-name "
${
iconName
}
.*"`
);
const
iconPaths
=
stdout
.
toString
().
split
(
'
\
n'
).
filter
(
path
=>
path
.
trim
()
!==
''
);
const
stdout
=
execSync
(
`find
${
pathBase
}
-name "
${
iconName
}
.*"`
);
const
iconPaths
=
stdout
.
toString
().
split
(
'
\
n'
).
filter
(
path
=>
path
&&
path
.
trim
()
!==
''
);
return
iconPaths
;
}
catch
(
error
)
{
console
.
error
(
`命令执行失败:
${
error
}
`
);
return
null
;
}
}
/* 获取最大像素图片 */
getMaxPix
({
name
,
iconList
,
icon
})
{
let
hicolorIcon
=
''
;
let
locolorIcon
=
''
;
let
hiMax
=
0
;
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
)
if
(
curHi
>
hiMax
)
{
hiMax
=
curHi
;
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
]);
if
(
curLo
>
loMax
)
{
loMax
=
curLo
;
locolorIcon
=
v
;
}
}
// locolorIcon = v;
}
})
if
(
hicolorIcon
)
icon
=
hicolorIcon
;
else
if
(
locolorIcon
)
icon
=
locolorIcon
;
else
{
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 快捷方式 列表 */
getLinuxList
()
{
exec
(
'ls /usr/share/applications/*.desktop'
,
(
error
,
stdout
,
stderr
)
=>
{
...
...
@@ -48,52 +97,62 @@ class SoftList {
console
.
error
(
`exec error:
${
error
}
`
);
return
;
}
const
apps
=
stdout
.
trim
().
split
(
'
\
n'
).
map
(
file
=>
{
const
content
=
fs
.
readFileSync
(
file
,
'utf8'
);
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
)
:
''
;
// icon判断是否绝对路径
if
(
!
path
.
isAbsolute
(
icon
)
)
{
let
iconList
=
this
.
findIcon
(
icon
);
if
(
iconList
.
length
>
0
)
{
icon
=
iconList
[
0
];
try
{
const
apps
=
stdout
.
trim
().
split
(
'
\
n'
).
map
(
file
=>
{
const
content
=
fs
.
readFileSync
(
file
,
'utf8'
);
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
)
:
''
;
let
iconList
=
[];
// icon判断是否绝对路径
if
(
icon
&&
!
path
.
isAbsolute
(
icon
)
)
{
iconList
=
this
.
findIcon
(
icon
,
'/usr/share/icons'
);
if
(
iconList
.
length
>
0
)
{
icon
=
this
.
getMaxPix
({
name
,
iconList
,
icon
})
}
else
{
iconList
=
this
.
findIcon
(
icon
,
'/usr/share'
);
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
{
nameOfZh
,
name
,
icon
,
execCommand
,
};
});
// 图标为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=”行。这一行包含应用程序的图标文件的路径。
this
.
store
.
set
(
'apps'
,
apps
);
this
.
mainWindow
.
win
.
webContents
.
send
(
"appsList"
,
apps
);
// 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
{
iconList
:
iconList
||
[],
nameOfZh
,
name
,
icon
,
execCommand
,
};
});
let
newApps
=
apps
.
filter
(
v
=>
!!
v
.
icon
);
this
.
store
.
set
(
'apps'
,
newApps
);
this
.
mainWindow
.
win
.
webContents
.
send
(
"appsList"
,
newApps
);
}
catch
(
error
)
{
console
.
error
(
error
)
}
});
}
...
...
@@ -219,19 +278,29 @@ class SoftList {
// png转base64
pngToBase64
(
imagePath
)
{
let
src
=
imagePath
;
try
{
const
imageBase64
=
fs
.
readFileSync
(
imagePath
,
'base64'
);
let
src
=
`data:image/png;base64,
${
imageBase64
}
`
;
src
=
`data:image/png;base64,
${
imageBase64
}
`
;
src
=
src
.
replace
(
/
[\r\n]
/g
,
''
);
return
src
;
}
catch
(
error
)
{
}
return
src
;
}
// SVG文件转换为Base64
svgToBase64
(
svgPath
)
{
let
src
=
svgPath
;
try
{
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
}
`
;
src
=
`data:image/svg+xml;base64,
${
base64
}
`
;
}
catch
(
error
)
{
console
.
log
(
error
)
}
return
src
;
}
// 获取linux软件信息
...
...
src/main/windows/mainWindow.js
浏览文件 @
aab27744
...
...
@@ -102,7 +102,7 @@ class MainWindow {
this
.
setAboutPanel
()
// 读取Linux系统中已经安装的软件
//
this.softList.getList();
this
.
softList
.
getList
();
}
setWindowMenu
()
{
...
...
src/renderer/App.vue
浏览文件 @
aab27744
...
...
@@ -68,6 +68,7 @@ export default {
}
},
created
()
{
},
mounted
()
{
...
...
@@ -155,19 +156,26 @@ export default {
// 获取到app列表
this
.
ipcRenderer
.
on
(
"appsList"
,
(
event
,
list
)
=>
{
//
console.log('获取到app列表', list)
console
.
log
(
'获取到app列表'
,
list
)
this
.
appList
=
list
;
this
.
appList
.
forEach
((
item
,
index
)
=>
{
item
.
icon
&&
item
.
icon
.
indexOf
(
'data:image/png'
)
==
-
1
&&
this
.
ipcRenderer
.
send
(
"getBase64"
,
{
'imagePath'
:
item
.
icon
,
index
});
console
.
log
(
item
.
icon
)
if
(
item
.
icon
&&
item
.
icon
.
indexOf
(
'data:image/png'
)
==
-
1
)
{
this
.
ipcRenderer
.
send
(
"getBase64"
,
{
'imagePath'
:
item
.
icon
,
index
});
}
});
});
this
.
ipcRenderer
.
on
(
"appsList_update"
,
(
event
,
list
)
=>
{
//
console.log('刷新app列表', list)
console
.
log
(
'刷新app列表'
,
list
)
this
.
appList
=
list
;
});
// 获取到app消息
this
.
ipcRenderer
.
on
(
"getMsg"
,
(
event
,
msgStr
)
=>
{
console
.
log
(
'获取到app消息'
,
msgStr
)
});
// 右键菜单点击-切换模式
this
.
ipcRenderer
.
on
(
"context-menu-command"
,(
event
,
mode
)
=>
{
console
.
log
(
'context-menu-command'
,
mode
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论