Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
course_creation
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
蔡芬
course_creation
Commits
96fba9a7
提交
96fba9a7
authored
11月 25, 2021
作者:
蔡芬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
文件打开
上级
fdda23a4
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
39 行增加
和
5 行删除
+39
-5
background.js
src/background.js
+8
-3
backfunction.js
src/libs/utils/backfunction.js
+31
-2
没有找到文件。
src/background.js
浏览文件 @
96fba9a7
...
@@ -4,7 +4,7 @@ import { app, protocol, BrowserWindow, shell, Menu, ipcMain, globalShortcut } fr
...
@@ -4,7 +4,7 @@ import { app, protocol, BrowserWindow, shell, Menu, ipcMain, globalShortcut } fr
import
path
from
'path'
;
import
path
from
'path'
;
import
{
createProtocol
}
from
"vue-cli-plugin-electron-builder/lib"
;
import
{
createProtocol
}
from
"vue-cli-plugin-electron-builder/lib"
;
import
installExtension
,
{
VUEJS_DEVTOOLS
}
from
"electron-devtools-installer"
;
import
installExtension
,
{
VUEJS_DEVTOOLS
}
from
"electron-devtools-installer"
;
import
{
downloadFile
}
from
'@/libs/utils/backfunction.js'
;
import
{
downloadFile
,
openFile
,
openFileFolder
,
getFilePositionFromUrl
}
from
'@/libs/utils/backfunction.js'
;
const
isDevelopment
=
process
.
env
.
NODE_ENV
!==
"production"
;
const
isDevelopment
=
process
.
env
.
NODE_ENV
!==
"production"
;
// Scheme must be registered before the app is ready
// Scheme must be registered before the app is ready
...
@@ -130,13 +130,18 @@ async function createWindow() {
...
@@ -130,13 +130,18 @@ async function createWindow() {
console
.
log
(
'主进程监听到下载'
,
downLoadUrl
,
targetUrl
);
console
.
log
(
'主进程监听到下载'
,
downLoadUrl
,
targetUrl
);
downloadFile
(
downLoadUrl
,
targetUrl
,({
percentage
,
received
,
total
,
success
})
=>
{
downloadFile
(
downLoadUrl
,
targetUrl
,({
percentage
,
received
,
total
,
success
,
filepath
,
filePosition
})
=>
{
if
(
!!
success
)
{
if
(
!!
success
)
{
console
.
log
(
'文件下载成功'
);
console
.
log
(
'文件下载成功'
);
// 下载完成打开文件
let
openStatus
=
openFile
(
filepath
);
//同浏览器效果 - 打开文件
// let openStatus = openFileFolder(filepath);
// console.log('打开文件位置状态',openStatus,filepath)
return
;
return
;
}
}
console
.
log
(
percentage
+
"% | "
+
received
+
" bytes out of "
+
total
+
" bytes."
);
//
console.log(percentage + "% | " + received + " bytes out of " + total + " bytes.");
});
});
// electron 的下载一直 interrupted -- 失败
// electron 的下载一直 interrupted -- 失败
// downloadpath = downLoadUrl;
// downloadpath = downLoadUrl;
// folderpath = targetUrl;
// folderpath = targetUrl;
...
...
src/libs/utils/backfunction.js
浏览文件 @
96fba9a7
import
{
shell
}
from
'electron'
;
var
request
=
require
(
'request'
);
var
request
=
require
(
'request'
);
var
fs
=
require
(
'fs'
);
var
fs
=
require
(
'fs'
);
// 下载文件
export
const
downloadFile
=
function
(
file_url
,
targetPath
,
callback
)
{
export
const
downloadFile
=
function
(
file_url
,
targetPath
,
callback
)
{
// Save variable to know progress
// Save variable to know progress
var
received_bytes
=
0
;
var
received_bytes
=
0
;
...
@@ -14,7 +18,6 @@ export const downloadFile = function(file_url , targetPath, callback) {
...
@@ -14,7 +18,6 @@ export const downloadFile = function(file_url , targetPath, callback) {
req
.
pipe
(
out
);
req
.
pipe
(
out
);
req
.
on
(
'response'
,
function
(
data
)
{
req
.
on
(
'response'
,
function
(
data
)
{
console
.
log
(
'Response'
,
data
)
// Change the total bytes value to get progress later.
// Change the total bytes value to get progress later.
total_bytes
=
parseInt
(
data
.
headers
[
'content-length'
]);
total_bytes
=
parseInt
(
data
.
headers
[
'content-length'
]);
});
});
...
@@ -28,7 +31,7 @@ export const downloadFile = function(file_url , targetPath, callback) {
...
@@ -28,7 +31,7 @@ export const downloadFile = function(file_url , targetPath, callback) {
req
.
on
(
'end'
,
function
()
{
req
.
on
(
'end'
,
function
()
{
console
.
log
(
"File succesfully downloaded"
);
console
.
log
(
"File succesfully downloaded"
);
callback
({
success
:
true
});
callback
({
success
:
true
,
filepath
:
targetPath
,
filePosition
:
getFilePositionFromUrl
(
targetPath
)
});
});
});
}
}
export
const
showProgress
=
function
(
received
,
total
,
callback
){
export
const
showProgress
=
function
(
received
,
total
,
callback
){
...
@@ -36,3 +39,29 @@ export const showProgress = function(received, total, callback){
...
@@ -36,3 +39,29 @@ export const showProgress = function(received, total, callback){
// console.log(percentage + "% | " + received + " bytes out of " + total + " bytes.");
// console.log(percentage + "% | " + received + " bytes out of " + total + " bytes.");
callback
({
percentage
,
received
,
total
});
callback
({
percentage
,
received
,
total
});
}
}
// 打开文件
export
const
openFile
=
function
(
path
)
{
if
(
!
fs
.
existsSync
(
path
))
return
false
;
shell
.
openPath
(
path
);
return
true
;
}
// 打开文件所在位置
export
const
openFileFolder
=
function
(
fullPath
)
{
if
(
!
fs
.
existsSync
(
fullPath
))
return
false
;
shell
.
showItemInFolder
(
fullPath
);
//当前没有效果 ???
return
true
;
}
// 提取文件名
export
const
getFilenameFromUrl
=
function
(
fileUrl
)
{
return
fileUrl
.
substring
(
fileUrl
.
lastIndexOf
(
'/'
)
+
1
);
}
// 提取文件位置
export
const
getFilePositionFromUrl
=
function
(
fileUrl
)
{
return
fileUrl
.
substring
(
0
,
fileUrl
.
lastIndexOf
(
'/'
));
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论