diff --git a/updater/src/copy/copy.js b/updater/src/copy/copy.js deleted file mode 100644 index b1b4d2c..0000000 --- a/updater/src/copy/copy.js +++ /dev/null @@ -1,9 +0,0 @@ -app.on('copy-me', () => { - const fs = require('fs'); - - // File destination.txt will be created or overwritten by default. - fs.copyFile('source.txt', 'destination.txt', (err) => { - if (err) throw err; - console.log('source.txt was copied to destination.txt'); - }); -}); \ No newline at end of file diff --git a/updater/src/download/downloader.js b/updater/src/download/downloader.js deleted file mode 100644 index 214246a..0000000 --- a/updater/src/download/downloader.js +++ /dev/null @@ -1,21 +0,0 @@ -const { app, BrowserWindow, ipcMain } = require("electron"); -const { download } = require("electron-dl"); -let window; -app.on("ready", () => { - window = new BrowserWindow({ - width: someWidth, - height: someHeight - }); - window.loadURL(`file://${__dirname}/index.html`); - ipcMain.on("download", (event, info) => { - download(BrowserWindow.getFocusedWindow(), info.url, info.properties) - .then(dl => window.webContents.send("download complete", dl.getSavePath())); - }); -}); - - -ipcMain.on("download", (event, info) => { - info.properties.onProgress = status => window.webContents.send("download progress", status); - download(BrowserWindow.getFocusedWindow(), info.url, info.properties) - .then(dl => window.webContents.send("download complete", dl.getSavePath())); -}); \ No newline at end of file diff --git a/updater/src/index.html b/updater/src/index.html index ab81bd2..acb18e5 100644 --- a/updater/src/index.html +++ b/updater/src/index.html @@ -3,22 +3,21 @@ Sectorfile Updater - + - + - + + + + + + File path: + diff --git a/updater/src/index.js b/updater/src/index.js index 8cc6c94..17c63a7 100644 --- a/updater/src/index.js +++ b/updater/src/index.js @@ -11,18 +11,29 @@ if (require('electron-squirrel-startup')) { app.quit(); } + +async function handleFileOpen() { + const { canceled, filePaths } = await dialog.showOpenDialog() + if (canceled) { + return + } else { + return filePaths[0] + } +} +app.whenReady(() => { + ipcMain.handle('dialog:openFile', handleFileOpen) + createWindow() +}) + const createWindow = () => { // Create the browser window. const mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { - preload: path.join(__dirname, 'preload.js'), - nodeIntegration: true, - contextIsolation: true, + preload: path.join(__dirname, 'preload.js') }, }); - mainWindow.loadFile(path.join(__dirname, 'index.html')); }; @@ -70,9 +81,9 @@ ipcMain.on('select-dirs', async(event, arg) => { // Download a file -ipcMain.on("download", (event, url, properties) => { - properties.onProgress = status => window.webContents.send("download progress", status); - download(BrowserWindow.getFocusedWindow(), url, properties) +ipcMain.on("download", async(event, url) => { + //properties.onProgress = status => window.webContents.send("download progress", status); + download(BrowserWindow.getFocusedWindow(), url) .then(dl => window.webContents.send("download complete", dl.getSavePath())); }); diff --git a/updater/src/preload.js b/updater/src/preload.js index fbed960..9319ed4 100644 --- a/updater/src/preload.js +++ b/updater/src/preload.js @@ -1,4 +1,10 @@ -const { ipcRenderer } = require('electron') +const { contextBridge, ipcRenderer } = require('electron') + +contextBridge.exposeInMainWorld('electronAPI', { + openFile: () => ipcRenderer.invoke('dialog:openFile') +}); + + // Change me for file save @@ -28,7 +34,7 @@ document.addEventListener('DOMContentLoaded', function() { }); - +/* // Change me for select directory process.once('loaded', () => { @@ -37,4 +43,4 @@ process.once('loaded', () => { ipcRenderer.send('select-dirs') } }); -}); \ No newline at end of file +});*/ \ No newline at end of file diff --git a/updater/src/renderer.js b/updater/src/renderer.js index 41fa61f..8277518 100644 --- a/updater/src/renderer.js +++ b/updater/src/renderer.js @@ -10,8 +10,12 @@ const writeFile = document.querySelector('writeFile'); const { remote, ipcRenderer } = require('electron'); const { writeFile } = require('fs'); +document.getElementById('btn').addEventListener('click', () => { + const filePath = window.electronAPI.openFile() + document.getElementById('filePath').innerText = filePath +}); + -const { ipcRenderer } = require("electron"); ipcRenderer.on("download complete", (event, file) => { console.log(file); // Full file path }); @@ -28,4 +32,11 @@ document.getElementById('dirs').addEventListener('click', (evt) => { window.postMessage({ type: 'select-dirs', }) +}); + + + +document.getElementById('openButton').addEventListener('click', () => { + console.log("Test"); + ipcRenderer.send('openFile', {}) }); \ No newline at end of file diff --git a/updater/src/unzip/unzip.js b/updater/src/unzip/unzip.js deleted file mode 100644 index 76e8394..0000000 --- a/updater/src/unzip/unzip.js +++ /dev/null @@ -1,28 +0,0 @@ -var ZIP_FILE_PATH = "C:/path/to/file/myzipfile.zip"; -var DESTINATION_PATH = "C:/desktop/examplefolder"; -var unzipper = new DecompressZip(ZIP_FILE_PATH); - -// Add the error event listener -unzipper.on('error', function(err) { - console.log('Caught an error', err); -}); - -// Notify when everything is extracted -unzipper.on('extract', function(log) { - console.log('Finished extracting', log); -}); - -// Notify "progress" of the decompressed files -unzipper.on('progress', function(fileIndex, fileCount) { - console.log('Extracted file ' + (fileIndex + 1) + ' of ' + fileCount); -}); - -// Start extraction of the content -unzipper.extract({ - path: DESTINATION_PATH - // You can filter the files that you want to unpack using the filter option - //filter: function (file) { - //console.log(file); - //return file.type !== "SymbolicLink"; - //} -}); \ No newline at end of file