diff --git a/elsrc/TopMenu.js b/elsrc/TopMenu.js index f182679..1b273cf 100644 --- a/elsrc/TopMenu.js +++ b/elsrc/TopMenu.js @@ -28,7 +28,7 @@ const readDirLocal=async (filePath) => { } return fileStateList } -exports.menuRebuild = (mainWindow) => { +exports.menuRebuild = (mainWindow,uploadUtil) => { return template = [ { label: '文件', @@ -105,14 +105,14 @@ exports.menuRebuild = (mainWindow) => { submenu: [ { label: '同步上传', - click: async () => { - await shell.openExternal('http://www.huaruyu.com') + click: () => { + uploadUtil.upLoadFileUtil(uploadUtil.getActiveFile()) } }, { label: '同步下载', - click: async () => { - await shell.openExternal('http://www.huaruyu.com') + click: () => { + uploadUtil.downLoadFileUtil(uploadUtil.getActiveFile()) } } ] diff --git a/elsrc/sync/tencent/UploadUtils.js b/elsrc/sync/tencent/UploadUtils.js index 95dc89b..db5dca6 100644 --- a/elsrc/sync/tencent/UploadUtils.js +++ b/elsrc/sync/tencent/UploadUtils.js @@ -1,6 +1,6 @@ const COS = require('cos-nodejs-sdk-v5'); const {dialog} = require('electron') -const {readFileSync,createWriteStream}=require('node:fs') +const {readFileSync}=require('node:fs') const md5 = require("md5"); class UploadUtils { @@ -17,6 +17,10 @@ class UploadUtils { constructor(store) { this.store = store; } + + upLoadFileUtil(activeFile){UploadUtils.selfUploadFile(activeFile)} + downLoadFileUtil(activeFile){UploadUtils.selfDownLoadFile(activeFile)} + static selfUploadFile(activeFile){ console.log("cos.uploadFile") UploadUtils.cos.uploadFile({ @@ -53,12 +57,16 @@ class UploadUtils { }); } - syncActiveFile() { + getActiveFile(){ let tableBarItem = JSON.parse(this.store.get("persist:tableBarItem")); if (!tableBarItem) { return; } - let activeFile = tableBarItem.activeKey?tableBarItem.activeKey.replaceAll('"',""):undefined; + return tableBarItem.activeKey?tableBarItem.activeKey.replaceAll('"',""):undefined; + } + + syncActiveFile() { + let activeFile = this.getActiveFile(); console.log("activeFile:", activeFile) if (activeFile) { let dirMessage = JSON.parse(this.store.get("persist:dirMessage")); diff --git a/main.js b/main.js index d70dfb7..d919c7e 100644 --- a/main.js +++ b/main.js @@ -4,6 +4,7 @@ const {menuRebuild} = require('./elsrc/TopMenu.js') const UploadUtils = require("./elsrc/sync/tencent/UploadUtils") const Store = require('electron-store'); const store = new Store(); +const uploadUtil = new UploadUtils(store); const isDev = require('electron-is-dev') const createWindow = () => { // Create the browser window. @@ -51,7 +52,7 @@ const createWindow = () => { } }) - Menu.setApplicationMenu(Menu.buildFromTemplate(menuRebuild(win))) + Menu.setApplicationMenu(Menu.buildFromTemplate(menuRebuild(win,uploadUtil))) win.once('ready-to-show', () => { win.show() }) @@ -68,7 +69,6 @@ app.whenReady().then(() => { if (BrowserWindow.getAllWindows().length === 0) createWindow() // 同步数据 }) - const uploadUtil = new UploadUtils(store); uploadUtil.syncFile() ipcMain.handle("saveFileWithName",(listen,args)=>{ console.log("saveFileWithName")