Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
electron-printer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhuzhequan
electron-printer
Commits
edc10d65
Commit
edc10d65
authored
Aug 30, 2024
by
zhuzhequan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化
parent
c896ce68
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
123 deletions
+23
-123
src/update.js
+0
-89
src/views/design/head/index.vue
+2
-3
src/views/design/index.vue
+2
-3
src/views/design/update.js
+0
-27
src/views/design/updateDialog.vue
+19
-1
No files found.
src/update.js
deleted
100644 → 0
View file @
c896ce68
// 实现自动更新逻辑
const
{
autoUpdater
}
=
require
(
"electron-updater"
);
let
mainWin
=
null
;
function
downloadProgress
(
win
,
progress
)
{
if
(
win
.
isDestroyed
())
{
return
;
}
console
.
log
(
"正在下载中"
);
win
.
webContents
.
send
(
"update"
,
{
speed
:
Math
.
ceil
(
progress
.
bytesPerSecond
/
1000
),
// 网速
percent
:
Math
.
ceil
(
progress
.
percent
)
// 百分比
});
autoUpdater
.
removeListener
(
"update-downloaded"
,
progress
=>
downloadProgress
(
win
,
progress
)
);
}
function
updateAvailable
(
win
,
info
)
{
if
(
win
.
isDestroyed
())
{
return
;
}
// 检查到有新版本
win
.
webContents
.
send
(
"update-available"
,
info
);
autoUpdater
.
removeListener
(
"update-available"
,
info
=>
updateAvailable
(
win
,
info
));
}
function
downloadError
(
win
,
err
)
{
if
(
win
.
isDestroyed
())
{
return
;
}
console
.
log
(
111
);
// 自动升级遇到错误
console
.
log
(
"自动升级遇到错误"
,
err
);
win
.
webContents
.
send
(
"update-error"
,
err
);
autoUpdater
.
removeListener
(
"error"
,
err
=>
downloadError
(
win
,
err
));
}
function
updateNotAvailable
(
win
,
info
)
{
if
(
win
.
isDestroyed
())
{
return
;
}
console
.
log
(
"检查到无新版本"
,
info
);
win
.
webContents
.
send
(
"update-not-available"
,
info
);
autoUpdater
.
removeListener
(
"error"
,
err
=>
downloadError
(
win
,
err
));
}
function
updateDownloaded
(
win
,
info
)
{
if
(
win
.
isDestroyed
())
{
return
;
}
console
.
log
(
info
,
"info"
);
win
.
webContents
.
send
(
"downloaded"
,
info
);
}
const
checkUpdate
=
(
win
,
ipcMain
,
data
)
=>
{
if
(
win
.
isDestroyed
())
{
return
;
}
autoUpdater
.
autoDownload
=
true
;
// 自动下载
autoUpdater
.
autoInstallOnAppQuit
=
false
;
// 应用退出后自动安装
// autoUpdater.forceDevUpdateConfig = true;
// autoUpdater.updateConfigPath = url + "latest.yml";
mainWin
=
win
;
autoUpdater
.
setFeedURL
({
provider
:
"generic"
,
url
:
data
.
url
});
ipcMain
.
on
(
"install"
,
()
=>
{
autoUpdater
.
quitAndInstall
();
});
// 检测是否有更新包并通知
autoUpdater
.
checkForUpdatesAndNotify
({
title
:
data
.
title
,
body
:
data
.
content
})
.
catch
();
// 监听渲染进程的 install 事件,触发退出应用并安装
autoUpdater
.
on
(
"download-progress"
,
progress
=>
downloadProgress
(
win
,
progress
)
);
autoUpdater
.
on
(
"update-available"
,
info
=>
updateAvailable
(
win
,
info
));
autoUpdater
.
on
(
"error"
,
err
=>
downloadError
(
win
,
err
));
autoUpdater
.
on
(
"update-not-available"
,
info
=>
updateNotAvailable
(
win
,
info
));
autoUpdater
.
on
(
"update-downloaded"
,
info
=>
updateDownloaded
(
win
,
info
));
};
module
.
exports
=
checkUpdate
;
src/views/design/head/index.vue
View file @
edc10d65
...
@@ -4,7 +4,7 @@ import PrintDialog from "./printDialog.vue";
...
@@ -4,7 +4,7 @@ import PrintDialog from "./printDialog.vue";
import
{
ipcRenderer
}
from
"electron"
;
import
{
ipcRenderer
}
from
"electron"
;
import
{
grid
}
from
"../data"
;
import
{
grid
}
from
"../data"
;
import
pkg
from
"../../../../package.json"
;
import
pkg
from
"../../../../package.json"
;
import
update
from
"@/views/design/update"
;
import
UpdateDialog
from
"@/views/design/updateDialog.vue"
;
import
UpdateDialog
from
"@/views/design/updateDialog.vue"
;
export
default
{
export
default
{
components
:
{
PrintDialog
,
UpdateDialog
},
components
:
{
PrintDialog
,
UpdateDialog
},
...
@@ -102,8 +102,7 @@ export default {
...
@@ -102,8 +102,7 @@ export default {
},
},
methods
:
{
methods
:
{
checkUpdate
()
{
checkUpdate
()
{
const
Update
=
new
update
();
this
.
$refs
.
updateDialog
.
checkUpdate
().
then
(
data
=>
{
Update
.
checkUpdate
().
then
(
data
=>
{
if
(
data
)
{
if
(
data
)
{
// 有新版本更新
// 有新版本更新
this
.
$refs
.
updateDialog
.
open
(
data
);
this
.
$refs
.
updateDialog
.
open
(
data
);
...
...
src/views/design/index.vue
View file @
edc10d65
<
script
>
<
script
>
import
PHead
from
"./head/index.vue"
;
import
PHead
from
"./head/index.vue"
;
import
PMain
from
"./main/index.vue"
;
import
PMain
from
"./main/index.vue"
;
import
update
from
"./update"
;
import
UpdateDialog
from
"@/views/design/updateDialog.vue"
;
import
UpdateDialog
from
"@/views/design/updateDialog.vue"
;
export
default
{
export
default
{
...
@@ -15,8 +15,7 @@ export default {
...
@@ -15,8 +15,7 @@ export default {
mounted
()
{
mounted
()
{
this
.
user
=
this
.
$dataStore
.
get
(
"user"
);
this
.
user
=
this
.
$dataStore
.
get
(
"user"
);
this
.
company
=
this
.
$dataStore
.
get
(
"company"
);
this
.
company
=
this
.
$dataStore
.
get
(
"company"
);
const
Update
=
new
update
();
this
.
$refs
.
updateDialog
.
checkUpdate
().
then
(
data
=>
{
Update
.
checkUpdate
().
then
(
data
=>
{
if
(
data
)
{
if
(
data
)
{
// 有新版本更新
// 有新版本更新
this
.
$refs
.
updateDialog
.
open
(
data
);
this
.
$refs
.
updateDialog
.
open
(
data
);
...
...
src/views/design/update.js
deleted
100644 → 0
View file @
c896ce68
import
pkg
from
"../../../package.json"
;
import
axios
from
"../../utils/axios"
;
export
default
class
Update
{
version
;
constructor
()
{
this
.
version
=
pkg
.
version
;
}
async
checkUpdate
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
axios
.
get
(
`/checkUpdate?version=
${
this
.
version
}
`
)
.
then
(
res
=>
{
resolve
(
res
.
data
);
})
.
catch
(
err
=>
{
reject
(
err
);
});
}
catch
(
err
)
{
reject
(
err
);
}
});
}
}
src/views/design/updateDialog.vue
View file @
edc10d65
<
script
>
<
script
>
import
{
ipcRenderer
}
from
"electron"
;
import
{
ipcRenderer
}
from
"electron"
;
import
pkg
from
"../../../package.json"
;
import
axios
from
"@/utils/axios"
;
export
default
{
export
default
{
data
()
{
data
()
{
return
{
return
{
visible
:
false
,
visible
:
false
,
version
:
pkg
.
version
,
downloaded
:
false
,
downloaded
:
false
,
percent
:
0
,
percent
:
0
,
loading
:
false
,
loading
:
false
,
...
@@ -33,6 +35,22 @@ export default {
...
@@ -33,6 +35,22 @@ export default {
});
});
},
},
methods
:
{
methods
:
{
async
checkUpdate
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
axios
.
get
(
`/checkUpdate?version=
${
this
.
version
}
`
)
.
then
(
res
=>
{
resolve
(
res
.
data
);
})
.
catch
(
err
=>
{
reject
(
err
);
});
}
catch
(
err
)
{
reject
(
err
);
}
});
},
download
()
{
download
()
{
this
.
$confirm
(
"新版本已下载,是否立即安装?"
,
"提示"
,
{
this
.
$confirm
(
"新版本已下载,是否立即安装?"
,
"提示"
,
{
confirmButtonText
:
"确定"
,
confirmButtonText
:
"确定"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment