diff --git a/src/main/file.js b/src/main/file.js index c0b8810..eecd08c 100644 --- a/src/main/file.js +++ b/src/main/file.js @@ -5,13 +5,27 @@ import { dialog } from 'electron' const manager = new ElectronDownloadManager() export default async function ({ app, shell, BrowserWindow, ipcMain }) { const userDataPath = app.getPath('userData') + const appRootFilePath = userDataPath + '\\selfFile\\' + ipcMain.on('is-have-local-file', (e, fileNewName) => { + let filePath = appRootFilePath + fileNewName + fs.access(filePath, fs.constants.F_OK, (err) => { + if (err) { + e.reply('is-have-local-file-reply'+fileNewName, false) + return + } + e.reply('is-have-local-file-reply'+fileNewName, true) + }) + }) //默认浏览器打开url ipcMain.on('open-url-browser', (e, url) => { shell.openPath(url) }) //使用默认应用打开本地文件 - ipcMain.on('open-path-app', (e, path) => { - shell.openExternal(path) + ipcMain.on('open-path-app', (e, destination) => { + let path = appRootFilePath + destination + shell.openExternal(path).catch((error) => { + console.log(error) + }) }) //复制文件 @@ -21,32 +35,42 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) { }) }) + //获取应用文件目录 + ipcMain.on('get-root-file-path', (e) => { + e.reply('get-root-file-path-reply', appRootFilePath) + }) + //下载文件 - ipcMain.on('download-file-default', (e, url) => { + ipcMain.on('download-file-default', (e, { url, fileName }) => { createFolder('selfFile').then(async () => { const browserWindow = BrowserWindow.fromId(e.sender.id) const id = await manager.download({ window: browserWindow, url: url, - directory: userDataPath + '/selfFile/', + saveAsFilename: fileName, + directory: appRootFilePath, callbacks: { onDownloadStarted: async ({ id, item, webContents }) => { // Do something with the download id }, onDownloadProgress: async ({ id, item, percentCompleted }) => { - browserWindow.webContents.invoke('download-progress', { - id, - percentCompleted, - // Get the number of bytes received so far - bytesReceived: item.getReceivedBytes() - }) }, onDownloadCompleted: async ({ id, item }) => { - console.log(item) + console.log('完成') + e.reply('download-file-default'+fileName,true) }, - onDownloadCancelled: async () => {}, - onDownloadInterrupted: async () => {}, - onError: (err, data) => {} + onDownloadCancelled: async () => { + console.log('取消') + e.reply('download-file-default'+fileName,false) + }, + onDownloadInterrupted: async () => { + console.log('中断') + e.reply('download-file-default'+fileName,false) + }, + onError: (err, data) => { + console.log(err.toString()) + e.reply('download-file-default'+fileName,false) + } } }) }) @@ -59,7 +83,7 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) { * @param {String} fileName 文件名称包括后缀名,例如图1.png */ ipcMain.on('save-as', function (event, url, fileName) { - let win = BrowserWindow.getFocusedWindow(); + let win = BrowserWindow.getFocusedWindow() //通过扩展名识别文件类型 let filters = [{ name: '全部文件', extensions: ['*'] }] let ext = path.extname(fileName) //获取扩展名 @@ -101,7 +125,7 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) { }) function copyFile(source, destination, callback) { - let path = userDataPath + '\\selfFile\\' + destination + let path = appRootFilePath + destination createFolder('selfFile').then(() => { const readStream = fs.createReadStream(source) const writeStream = fs.createWriteStream(path) diff --git a/src/main/index.js b/src/main/index.js index 60f902a..6cab157 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -8,8 +8,8 @@ File({ app, shell, BrowserWindow, ipcMain }) function createWindow() { // Create the browser window. const mainWindow = new BrowserWindow({ - width: 1050, - height: 650, + width: 888, + height: 520, show: false, frame: false, autoHideMenuBar: true, @@ -107,4 +107,5 @@ ipcMain.on('close-window', () => { ipcMain.on('set-winsize', (e, {x, y})=>{ const win = BrowserWindow.getFocusedWindow(); win.setSize(x,y); + win.center() }) diff --git a/src/renderer/src/App.vue b/src/renderer/src/App.vue index 4ece3da..1c467ca 100644 --- a/src/renderer/src/App.vue +++ b/src/renderer/src/App.vue @@ -8,7 +8,6 @@ import { ref } from 'vue' const size = ref('default') -// const size = computed(() => store.state.app.elementSize) \ No newline at end of file diff --git a/src/renderer/src/components/upload-dialog/index.vue b/src/renderer/src/components/upload-dialog/index.vue index 61df734..41df2f9 100644 --- a/src/renderer/src/components/upload-dialog/index.vue +++ b/src/renderer/src/components/upload-dialog/index.vue @@ -16,7 +16,7 @@
标题: - + .{{ getFileSuffix(item.name) }}
diff --git a/src/renderer/src/layout/components/Uploader.vue b/src/renderer/src/layout/components/Uploader.vue index 5d554ce..1dc7d9d 100644 --- a/src/renderer/src/layout/components/Uploader.vue +++ b/src/renderer/src/layout/components/Uploader.vue @@ -1,5 +1,5 @@