切换导航条
切换导航条
当前项目
正在载入...
登录
术习电报
/
electron-vue-template
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
构建
提交
问题看板
文件
提交
网络
比较
分支
标签
作者
张恒
2019-11-19 19:14:06 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
提交
9a697f16353b5ebc8cae81c4c90c98c4c44a15d0
9a697f16
1 个父辈
6d5d9ba6
加入不使用updater进行全量更新的办法
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
156 行增加
和
44 行删除
src/main/services/downloadFile.js
src/main/services/windowManager.js
src/renderer/components/LandingPage.vue
src/main/services/downloadFile.js
0 → 100644
查看文件 @
9a697f1
/* eslint-disable no-case-declarations */
import
{
app
,
ipcMain
,
dialog
}
from
'electron'
import
path
from
'path'
import
os
from
'os'
// 版本以package.json为基准。
const
version
=
require
(
'../../../package.json'
).
version
// 您的下载地址
const
baseUrl
=
'http://127.0.0.1:25565/'
var
Sysarch
=
null
var
downloadUrL
=
null
// 识别操作系统位数
os
.
arch
().
includes
(
'64'
)
?
Sysarch
=
'win64'
:
Sysarch
=
'win32'
// 暂时忽略linux版本,因为我。。= =没有linux不过问题不大,很快就会有
os
.
platform
().
includes
(
'win'
)
?
downloadUrL
=
baseUrl
+
`electron_
${
version
}
_
${
Sysarch
}
.exe?
${
new
Date
().
getTime
()}
`
:
downloadUrL
=
baseUrl
+
`electron_
${
version
}
_mac.dmg?
${
new
Date
().
getTime
()}
`
export
default
{
download
(
mainWindow
)
{
ipcMain
.
on
(
'satrt-download'
,
(
event
,
msg
)
=>
{
console
.
log
(
1111
)
mainWindow
.
webContents
.
downloadURL
(
downloadUrL
)
event
.
reply
(
'confirm-download'
,
true
)
mainWindow
.
webContents
.
session
.
on
(
'will-download'
,
(
event
,
item
,
webContents
)
=>
{
// 将文件保存在系统的下载目录
const
filePath
=
path
.
join
(
app
.
getPath
(
'downloads'
),
item
.
getFilename
())
// 自动保存
item
.
setSavePath
(
filePath
)
// 下载进度
item
.
on
(
'updated'
,
(
event
,
state
)
=>
{
switch
(
state
)
{
case
'progressing'
:
mainWindow
.
webContents
.
send
(
'download-progress'
,
(
item
.
getReceivedBytes
()
/
item
.
getTotalBytes
()
*
100
).
toFixed
(
0
))
break
default
:
mainWindow
.
webContents
.
send
(
'download-error'
,
true
)
dialog
.
showErrorBox
(
'下载出错'
,
'由于网络或其他未知原因导致客户端下载出错,请前往官网进行重新安装'
)
break
}
})
// 下载完成或失败
item
.
once
(
'done'
,
(
event
,
state
)
=>
{
switch
(
state
)
{
case
'completed'
:
const
data
=
{
filePath
}
mainWindow
.
webContents
.
send
(
'download-done'
,
data
)
break
case
'interrupted'
:
mainWindow
.
webContents
.
send
(
'download-error'
,
true
)
dialog
.
showErrorBox
(
'下载出错'
,
'由于网络或其他未知原因导致客户端下载出错,请前往官网进行重新安装'
)
break
default
:
break
}
})
})
})
}
}
src/main/services/windowManager.js
查看文件 @
9a697f1
...
...
@@ -4,7 +4,9 @@ import config from '@config'
import
setIpc
from
'./ipcMain'
import
electronDevtoolsInstaller
,
{
VUEJS_DEVTOOLS
}
from
'electron-devtools-installer'
import
upload
from
'./checkupdate'
import
DownloadUpdate
from
'./downloadFile'
import
path
from
'path'
/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
...
...
@@ -58,6 +60,7 @@ function createMainWindow () {
setIpc
.
Mainfunc
(
ipcMain
,
mainWindow
,
config
.
IsUseSysTitle
)
upload
.
Update
(
mainWindow
)
DownloadUpdate
.
download
(
mainWindow
)
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
mainWindow
.
webContents
.
once
(
'dom-ready'
,
()
=>
{
...
...
src/renderer/components/LandingPage.vue
查看文件 @
9a697f1
...
...
@@ -22,13 +22,26 @@
<el-button type="primary" round @click="setdata">写入数据</el-button>
<el-button type="primary" round @click="getdata">读取数据</el-button>
<el-button type="primary" round @click="deledata">清除所有数据</el-button>
<el-button type="primary" round @click="CheckUpdate">检查更新</el-button>
<el-button type="primary" round @click="CheckUpdate('one')">检查更新</el-button>
<el-button type="primary" round @click="CheckUpdate('two')">检查更新(第二种方法)</el-button>
</div>
</div>
</main>
<el-dialog title="进度" :visible.sync="dialogVisible" :before-close="handleClose" center width="14%" top="45vh">
<el-dialog
title="进度"
:visible.sync="dialogVisible"
:before-close="handleClose"
center
width="14%"
top="45vh"
>
<div class="conten">
<el-progress type="dashboard" :percentage="percentage" :color="colors"></el-progress>
<el-progress
type="dashboard"
:percentage="percentage"
:color="colors"
:status="progressStaus"
></el-progress>
</div>
</el-dialog>
</div>
...
...
@@ -48,7 +61,7 @@ export default {
age: "12"
},
textarray: [],
percentage:0,
percentage:
0,
colors: [
{ color: "#f56c6c", percentage: 20 },
{ color: "#e6a23c", percentage: 40 },
...
...
@@ -56,7 +69,9 @@ export default {
{ color: "#1989fa", percentage: 80 },
{ color: "#5cb87a", percentage: 100 }
],
dialogVisible: false
dialogVisible: false,
progressStaus: null,
filePath: ""
}),
created() {},
methods: {
...
...
@@ -107,53 +122,89 @@ export default {
// }
// api.ErrorMessageBox(dialog,data)
},
CheckUpdate() {
const dialog = this.$electron.remote.dialog;
ipcApi.send("check-update");
console.log("启动检查");
ipcApi.on("UpdateMsg", (event, data) => {
console.log(data)
switch (data.state) {
case -1:
const msgdata = {
title: data.msg,
};
api.MessageBox(dialog, msgdata);
break;
case 0:
this.$message("正在检查更新");
break;
case 1:
this.$message({
type: "success",
message: "已检查到新版本,开始下载"
});
this.dialogVisible = true
break;
case 2:
this.$message({ type: "success", message: "无新版本" });
break;
case 3:
this.percentage = data.msg.percent.toFixed(1)
break;
case 4:
CheckUpdate(data) {
switch (data) {
case "one":
const dialog = this.$electron.remote.dialog;
ipcApi.send("check-update");
console.log("启动检查");
ipcApi.on("UpdateMsg", (event, data) => {
console.log(data);
switch (data.state) {
case -1:
const msgdata = {
title: data.msg
};
api.MessageBox(dialog, msgdata);
break;
case 0:
this.$message("正在检查更新");
break;
case 1:
this.$message({
type: "success",
message: "已检查到新版本,开始下载"
});
this.dialogVisible = true;
break;
case 2:
this.$message({ type: "success", message: "无新版本" });
break;
case 3:
this.percentage = data.msg.percent.toFixed(1);
break;
case 4:
this.progressStaus = "success";
this.$alert("更新下载完成!", "提示", {
confirmButtonText: "确定",
callback: action => {
ipcApi.send("confirm-update");
}
});
break;
default:
break;
}
});
break;
case "two":
console.log(111);
ipcApi.send("satrt-download");
ipcApi.on("confirm-download", (event, arg) => {
if (arg) {
this.dialogVisible = true;
}
});
ipcApi.on("download-progress", (event, arg) => {
this.percentage = Number(arg);
});
ipcApi.on("download-error", (event, arg) => {
if (arg) {
this.progressStaus = "exception";
this.percentage = 40;
this.colors = "#d81e06";
}
});
ipcApi.on("download-done", (event, age) => {
this.filePath = age.filePath;
this.progressStaus = "success";
this.$alert("更新下载完成!", "提示", {
confirmButtonText: "确定",
callback: action => {
ipcApi.send("confirm-update"
);
this.$electron.shell.openItem(this.filePath
);
}
});
break;
});
break;
default:
break;
}
});
default:
break;
}
},
handleClose(){
this.dialogVisible = false
handleClose()
{
this.dialogVisible = false
;
}
}
};
</script>
...
...
请
注册
或
登录
后发表评论