diff --git a/git-commit.sh b/git-commit.sh index a617315..dd7655e 100644 --- a/git-commit.sh +++ b/git-commit.sh @@ -6,4 +6,4 @@ git add . git commit -m "$1" git push -uf origin paul-bastelt -git push -uf paulgit paul-bastelt +#git push -uf paulgit paul-bastelt diff --git a/updater/src/index.html b/updater/src/index.html index f529525..ab81bd2 100644 --- a/updater/src/index.html +++ b/updater/src/index.html @@ -11,6 +11,7 @@ + @@ -19,7 +20,13 @@

Hello World!

Welcome to your Electron application.

- +

Input Text

+ +

Input URL

+ +

Input Directory

+ + diff --git a/updater/src/index.js b/updater/src/index.js index a6d24b4..8cc6c94 100644 --- a/updater/src/index.js +++ b/updater/src/index.js @@ -1,6 +1,9 @@ const { app, BrowserWindow, Menu, dialog, ipcMain, nativeTheme } = require('electron'); +const { download } = require("electron-dl"); const path = require('path'); //Menu.setApplicationMenu(false); +var fs = require('fs'); +let window; // Handle creating/removing shortcuts on Windows when installing/uninstalling. // eslint-disable-next-line global-require @@ -16,8 +19,10 @@ const createWindow = () => { webPreferences: { preload: path.join(__dirname, 'preload.js'), nodeIntegration: true, + contextIsolation: true, }, }); + mainWindow.loadFile(path.join(__dirname, 'index.html')); }; @@ -46,6 +51,14 @@ app.on('activate', () => { }); +// Write to a file +ipcMain.on("saveFile", (event, location, txtVal) => { + fs.writeFile(location, txtVal.toString(), (err) => { + if (!err) { console.log("File.written"); } else { + console.log(err); + } + }); +}); ipcMain.on('select-dirs', async(event, arg) => { @@ -56,6 +69,13 @@ 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) + .then(dl => window.webContents.send("download complete", dl.getSavePath())); +}); + // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and import them here. \ No newline at end of file diff --git a/updater/src/preload.js b/updater/src/preload.js index 731bcdf..fbed960 100644 --- a/updater/src/preload.js +++ b/updater/src/preload.js @@ -1,9 +1,40 @@ const { ipcRenderer } = require('electron') + +// Change me for file save +document.addEventListener('DOMContentLoaded', function() { + let writeFile = document.getElementById("writeFile"); + writeFile.addEventListener("click", () => { + let txtBox = document.getElementById("txtBox"); + let txtval = txtBox.value; + + ipcRenderer.send("saveFile", "f:\\file1.txt", txtval); + }); +}); + +// Change me for file save //ex: https://dms.pabr.de/s/RPbgF4nmgeyigkn +document.addEventListener('DOMContentLoaded', function() { + let startDownload = document.getElementById("startDownload"); + startDownload.addEventListener("click", () => { + let urlBox = document.getElementById("txtBox"); + let urlval = urlBox.value; + let dirBox = document.getElementById("txtBox"); + let dirval = dirBox.value; + ipcRenderer.send("download", { + url: urlval, + properties: { directory: dirval } + }); + }); +}); + + + + +// Change me for select directory process.once('loaded', () => { window.addEventListener('message', evt => { if (evt.data.type === 'select-dirs') { 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 fb16117..41fa61f 100644 --- a/updater/src/renderer.js +++ b/updater/src/renderer.js @@ -5,71 +5,16 @@ const startUnzip = document.querySelector('startUnzip'); const stopUnzip = document.querySelector('stopUnzip'); const selectVersionBtn = document.querySelector('selectVersion'); const selectPathBtn = document.querySelector('selectPathBtn'); +const writeFile = document.querySelector('writeFile'); -var directoryPath = "C:"; - -const { remote } = require('electron'); -const { Menu } = remote; +const { remote, ipcRenderer } = require('electron'); const { writeFile } = require('fs'); -// Will not work -async function selectVersion() { - const versionMenu = Menu.buildFromTemplate( - inputSources.map(source => { - return { - label: release.name, - click: () => selectVersion(source) - }; - }) - ); - selectVersion.popup(); -} - -// Git version update Select -async function selectVersion(source) { - selectVersionBtn.innerText = source.name; - const constrains = { - // Maybe needed - } -} - -// select Euroscope folder - TBD -async function selectPath(source) { - selectPathBtn.innerText = source.name; - const constrains = { - // Maybe needed - } -} - -async function downloadVersion(e) { - shell = new ActiveXObject("WScript.Shell"); - const file; // File to download - - const { filepath } = await dialog.showSaveDialog({ - buttonLabel: 'Save Update Version', - defaultPath: shell.SpecialFolders('MyDocuments') + '\\Euroscope' - }); - - console.log(filepath); - writeFile(filepath, file, () => console.log('file saved successfully!')); -} - - - - - -ipcRenderer.send("download", { - url: "https://dms.pabr.de/s/SpBiQYADTNak7R5/download", - properties: { directory: directoryPath } -}); - const { ipcRenderer } = require("electron"); ipcRenderer.on("download complete", (event, file) => { console.log(file); // Full file path }); - - ipcRenderer.on("download progress", (event, progress) => { console.log(progress); // Progress in fraction, between 0 and 1 const progressInPercentages = progress * 100; // With decimal point and a bunch of numbers @@ -83,10 +28,4 @@ document.getElementById('dirs').addEventListener('click', (evt) => { window.postMessage({ type: 'select-dirs', }) -}) - - - - - -// Get releases from Gitlab \ No newline at end of file +}); \ No newline at end of file