Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-vue-admin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-vue-admin
Commits
cacb2e38
提交
cacb2e38
authored
8月 13, 2023
作者:
test
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 优化更新通知以及全局消息表现形式
上级
4905c57b
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
55 行增加
和
46 行删除
+55
-46
update.ts
src-electron/main/update.ts
+9
-13
client.ts
src/store/modules/client.ts
+4
-7
AboutModal.vue
src/views/main/components/AboutModal.vue
+8
-7
Header.vue
src/views/main/components/Header.vue
+33
-18
index.vue
src/views/main/index.vue
+1
-1
没有找到文件。
src-electron/main/update.ts
浏览文件 @
cacb2e38
...
@@ -21,31 +21,31 @@ export async function useUpdater(win: BrowserWindow, store: ElectronStore<Settin
...
@@ -21,31 +21,31 @@ export async function useUpdater(win: BrowserWindow, store: ElectronStore<Settin
autoUpdater
.
checkForUpdates
()
autoUpdater
.
checkForUpdates
()
}
}
function
sendUpdateMessageToWindow
(
body
:
{
type
:
MessageType
;
text
:
string
})
{
function
sendUpdateMessageToWindow
(
body
:
{
type
:
MessageType
;
message
:
string
})
{
log
.
info
(
`
${
body
.
type
}
:
${
body
.
text
}
`
)
log
.
info
(
`
[检查更新]
${
body
.
type
}
:
${
body
.
message
}
`
)
win
.
webContents
.
send
(
'updater:message'
,
body
)
win
.
webContents
.
send
(
'updater:message'
,
body
)
}
}
autoUpdater
.
on
(
'checking-for-update'
,
()
=>
{
autoUpdater
.
on
(
'checking-for-update'
,
()
=>
{
sendUpdateMessageToWindow
({
type
:
'checking-for-update'
,
text
:
'正在检查更新...'
})
sendUpdateMessageToWindow
({
type
:
'checking-for-update'
,
message
:
'正在检查更新...'
})
})
})
autoUpdater
.
on
(
'update-available'
,
(
info
)
=>
{
autoUpdater
.
on
(
'update-available'
,
(
info
)
=>
{
sendUpdateMessageToWindow
({
type
:
'update-available'
,
text
:
`发现新版本 v
${
info
.
version
}
`
})
sendUpdateMessageToWindow
({
type
:
'update-available'
,
message
:
`发现新版本 v
${
info
.
version
}
`
})
})
})
autoUpdater
.
on
(
'update-not-available'
,
()
=>
{
autoUpdater
.
on
(
'update-not-available'
,
()
=>
{
sendUpdateMessageToWindow
({
type
:
'update-not-available'
,
text
:
'当前已是最新版本~'
})
sendUpdateMessageToWindow
({
type
:
'update-not-available'
,
message
:
'当前已是最新版本~'
})
})
})
autoUpdater
.
on
(
'error'
,
(
err
)
=>
{
autoUpdater
.
on
(
'error'
,
(
err
)
=>
{
sendUpdateMessageToWindow
({
type
:
'error'
,
text
:
err
.
message
})
sendUpdateMessageToWindow
({
type
:
'error'
,
message
:
err
.
message
})
})
})
autoUpdater
.
on
(
'download-progress'
,
(
progress
)
=>
{
autoUpdater
.
on
(
'download-progress'
,
(
progress
)
=>
{
sendUpdateMessageToWindow
({
sendUpdateMessageToWindow
({
type
:
'download-progress'
,
type
:
'download-progress'
,
text
:
`正在下载新版本
${
Number
(
progress
.
percent
).
toFixed
(
2
)}
%`
,
message
:
`正在下载新版本
${
Number
(
progress
.
percent
).
toFixed
(
2
)}
%`
,
})
})
})
})
autoUpdater
.
on
(
'update-downloaded'
,
()
=>
{
autoUpdater
.
on
(
'update-downloaded'
,
()
=>
{
sendUpdateMessageToWindow
({
type
:
'update-downloaded'
,
text
:
'下载完成'
})
sendUpdateMessageToWindow
({
type
:
'update-downloaded'
,
message
:
'下载完成'
})
setTimeout
(()
=>
{
setTimeout
(()
=>
{
// 退出并安装更新包
// 退出并安装更新包
...
@@ -72,10 +72,6 @@ export async function useUpdater(win: BrowserWindow, store: ElectronStore<Settin
...
@@ -72,10 +72,6 @@ export async function useUpdater(win: BrowserWindow, store: ElectronStore<Settin
checkForUpdate
()
checkForUpdate
()
}
}
}
catch
(
error
:
any
)
{
}
catch
(
error
:
any
)
{
log
.
info
(
`[检查更新] 出现异常:
${
error
}
`
)
sendUpdateMessageToWindow
({
type
:
'error'
,
message
:
error
.
message
})
win
.
webContents
.
send
(
'app:notify'
,
{
type
:
'error'
,
message
:
error
.
message
,
})
}
}
}
}
src/store/modules/client.ts
浏览文件 @
cacb2e38
...
@@ -20,24 +20,21 @@ export const useClientStore = defineStore('app-client', () => {
...
@@ -20,24 +20,21 @@ export const useClientStore = defineStore('app-client', () => {
function
setSystem
(
value
:
ISystem
)
{
function
setSystem
(
value
:
ISystem
)
{
// 保留 machineId 不允许修改
// 保留 machineId 不允许修改
const
machineId
=
system
.
value
.
machineId
system
.
value
=
{
...
value
,
machineId
:
system
.
value
.
machineId
}
system
.
value
=
value
system
.
value
.
machineId
=
machineId
ipc
.
invoke
(
'store:set'
,
'system'
,
toRaw
(
system
.
value
))
ipc
.
invoke
(
'store:set'
,
'system'
,
toRaw
(
system
.
value
))
}
}
function
setDebug
(
debug
:
boolean
):
void
{
function
setDebug
(
debug
:
boolean
):
void
{
system
.
value
.
debug
=
debug
ipc
.
invoke
(
'store:set'
,
'system.debug'
,
debug
)
ipc
.
invoke
(
'store:set'
,
'system'
,
toRaw
(
system
.
value
))
}
}
function
setAlwaysOnTop
(
alwaysOnTop
:
boolean
):
void
{
function
setAlwaysOnTop
(
alwaysOnTop
:
boolean
):
void
{
system
.
value
.
alwaysOnTop
=
alwaysOnTop
system
.
value
.
alwaysOnTop
=
alwaysOnTop
ipc
.
invoke
(
'store:set'
,
'system
'
,
toRaw
(
system
.
value
)
)
ipc
.
invoke
(
'store:set'
,
'system
.alwaysOnTop'
,
alwaysOnTop
)
}
}
async
function
reset
(...
keys
:
[
'system'
])
{
async
function
reset
(...
keys
:
[
'system'
])
{
ipc
.
invoke
(
'store:reset'
,
keys
)
await
ipc
.
invokeAsync
(
'store:reset'
,
keys
)
await
init
()
await
init
()
}
}
...
...
src/views/main/components/AboutModal.vue
浏览文件 @
cacb2e38
...
@@ -26,26 +26,27 @@
...
@@ -26,26 +26,27 @@
// 监听检查更新事件
// 监听检查更新事件
let
hide
=
null
let
hide
=
null
onMounted
(()
=>
{
onMounted
(()
=>
{
ipc
.
on
(
'updater:message'
,
(
_e
,
body
:
{
type
:
MessageType
;
text
:
string
})
=>
{
ipc
.
on
(
'updater:message'
,
(
_e
,
body
:
{
type
:
MessageType
;
message
:
string
})
=>
{
console
.
log
(
'updater:message'
,
body
)
console
.
log
(
'updater:message'
,
body
)
const
{
type
,
text
}
=
body
const
{
type
,
message
}
=
body
if
(
type
===
'checking-for-update'
||
type
===
'download-progress'
)
{
if
(
type
===
'checking-for-update'
||
type
===
'download-progress'
)
{
loading
.
value
=
true
loading
.
value
=
true
hide
=
createMessage
.
loading
({
hide
=
createMessage
.
loading
({
key
:
'updating'
,
key
:
'updating'
,
content
:
text
,
content
:
message
,
duration
:
0
,
duration
:
0
,
})
})
}
else
if
(
type
===
'update-available'
||
type
===
'update-not-available'
||
type
===
'update-downloaded'
)
{
}
else
if
(
type
===
'update-available'
||
type
===
'update-not-available'
||
type
===
'update-downloaded'
)
{
createMessage
.
success
(
text
)
createMessage
.
success
(
message
)
}
else
if
(
type
===
'error'
)
{
}
else
if
(
type
===
'error'
)
{
if
(
text
.
startsWith
(
'net::'
)
||
text
.
includes
(
'HttpError'
))
{
console
.
error
(
`检查更新失败:
${
message
}
`
)
if
(
message
?.
startsWith
(
'net::'
)
||
message
?.
includes
(
'HttpError'
))
{
createMessage
.
warn
(
'检查更新失败,请确认网络或者更新源配置是否正常'
)
createMessage
.
warn
(
'检查更新失败,请确认网络或者更新源配置是否正常'
)
}
else
{
}
else
{
createMessage
.
error
(
`检查更新失败:
${
text
}
`
)
createMessage
.
error
(
message
)
}
}
console
.
error
(
text
)
}
}
if
(
type
===
'error'
||
type
===
'update-downloaded'
||
type
===
'update-not-available'
)
{
if
(
type
===
'error'
||
type
===
'update-downloaded'
||
type
===
'update-not-available'
)
{
...
...
src/views/main/components/Header.vue
浏览文件 @
cacb2e38
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
const
clientStore
=
useClientStoreWithOut
()
const
clientStore
=
useClientStoreWithOut
()
const
{
ipcRenderer
:
ipc
}
=
useElectron
()
const
{
ipcRenderer
:
ipc
}
=
useElectron
()
const
{
createConfirm
,
createMessage
}
=
useMessage
()
const
{
createConfirm
,
createMessage
,
notification
}
=
useMessage
()
const
isDebug
=
computed
(()
=>
clientStore
.
system
?.
debug
)
const
isDebug
=
computed
(()
=>
clientStore
.
system
?.
debug
)
const
isAlwaysOnTop
=
computed
(()
=>
clientStore
.
system
?.
alwaysOnTop
)
const
isAlwaysOnTop
=
computed
(()
=>
clientStore
.
system
?.
alwaysOnTop
)
...
@@ -22,17 +22,13 @@
...
@@ -22,17 +22,13 @@
createConfirm
({
createConfirm
({
iconType
:
'warning'
,
iconType
:
'warning'
,
content
:
'确认关闭应用吗?'
,
content
:
'确认关闭应用吗?'
,
onOk
()
{
onOk
:
()
=>
ipc
.
invoke
(
'window:action'
,
action
),
ipc
.
invoke
(
'window:action'
,
action
)
},
})
})
return
return
}
}
if
(
action
===
'top'
)
{
if
(
action
===
'top'
)
{
clientStore
.
setAlwaysOnTop
(
!
isAlwaysOnTop
.
value
)
clientStore
.
setAlwaysOnTop
(
!
isAlwaysOnTop
.
value
)
createMessage
.
success
(
`应用
${
isAlwaysOnTop
.
value
?
''
:
'取消'
}
置顶`
)
return
}
}
ipc
.
invoke
(
'window:action'
,
action
)
ipc
.
invoke
(
'window:action'
,
action
)
...
@@ -46,16 +42,34 @@
...
@@ -46,16 +42,34 @@
openSettingModal
()
openSettingModal
()
}
}
// 监听全局通知
onMounted
(()
=>
{
ipc
.
on
(
'app:notify'
,
(
_
,
body
)
=>
{
// 监听全局通知
console
.
log
(
'app:notify'
,
body
)
ipc
.
on
(
'app:notify'
,
if
(
body
?.
message
.
startsWith
(
'net::'
)
||
body
?.
message
.
includes
(
'HttpError'
))
{
(
createMessage
.
warn
(
'检查更新失败,请确认网络或者更新源配置是否正常'
)
_
,
return
body
:
{
}
type
:
'notify'
|
'message'
icon
:
'success'
|
'warning'
|
'info'
createMessage
[
body
.
type
](
body
.
message
)
message
:
string
title
?:
string
duration
?:
number
},
)
=>
{
console
.
log
(
'app:notify'
,
body
)
if
(
body
.
type
===
'message'
)
{
createMessage
[
body
.
icon
](
body
.
message
,
body
.
duration
??
3
)
}
else
if
(
body
.
type
===
'notify'
)
{
notification
[
body
.
icon
]({
message
:
body
.
title
,
description
:
body
.
message
,
duration
:
body
.
duration
??
5
,
placement
:
'bottomRight'
,
})
}
},
)
})
})
</
script
>
</
script
>
...
@@ -93,7 +107,7 @@
...
@@ -93,7 +107,7 @@
<Icon
<Icon
:icon=
"isAlwaysOnTop ? 'ph:push-pin-fill' : 'ph:push-pin'"
:icon=
"isAlwaysOnTop ? 'ph:push-pin-fill' : 'ph:push-pin'"
:size=
"22"
:size=
"22"
:color=
"isAlwaysOnTop ? '
green
' : '#000'"
:color=
"isAlwaysOnTop ? '
#6ea2d7
' : '#000'"
/>
/>
</a-button>
</a-button>
</a-tooltip>
</a-tooltip>
...
@@ -128,7 +142,7 @@
...
@@ -128,7 +142,7 @@
display
:
flex
;
display
:
flex
;
justify-content
:
space-between
;
justify-content
:
space-between
;
padding
:
0
10px
;
padding
:
0
10px
;
background-color
:
white
;
background-color
:
#fbfbfb
;
.title
{
.title
{
-webkit-app-region
:
drag
;
-webkit-app-region
:
drag
;
...
@@ -143,6 +157,7 @@
...
@@ -143,6 +157,7 @@
.title-text
{
.title-text
{
letter-spacing
:
1px
;
letter-spacing
:
1px
;
font-family
:
'Microsoft YaHei'
,
'PingFang SC'
,
'Helvetica Neue'
,
Helvetica
,
Arial
,
sans-serif
;
}
}
.title-icon
{
.title-icon
{
...
...
src/views/main/index.vue
浏览文件 @
cacb2e38
...
@@ -25,6 +25,6 @@
...
@@ -25,6 +25,6 @@
.main-wrap
{
.main-wrap
{
width
:
100vw
;
width
:
100vw
;
height
:
100vh
;
height
:
100vh
;
background-color
:
#fbfbfb
;
background-color
:
white
;
}
}
</
style
>
</
style
>
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论