Small changes

This commit is contained in:
PaulaBras 2022-09-25 10:12:02 +02:00
parent 92bda5a4bf
commit efc63943c3
5 changed files with 65 additions and 68 deletions

View File

@ -6,4 +6,4 @@
git add . git add .
git commit -m "$1" git commit -m "$1"
git push -uf origin paul-bastelt git push -uf origin paul-bastelt
git push -uf paulgit paul-bastelt #git push -uf paulgit paul-bastelt

View File

@ -11,6 +11,7 @@
<script defer src="render.js"></script> <script defer src="render.js"></script>
</head> </head>
<body> <body>
<button id="writeFile" class"button is-primary">Write File</button>
<button id="startDownload" class"button is-primary">Start Download</button> <button id="startDownload" class"button is-primary">Start Download</button>
<button id="stopDownload" class"button is-warning">Stop Download</button> <button id="stopDownload" class"button is-warning">Stop Download</button>
<button id="startUnzip" class"button is-primary">Start Unzip</button> <button id="startUnzip" class"button is-primary">Start Unzip</button>
@ -19,7 +20,13 @@
<button id="selectPathBtn" class"button is-warning">Path</button> <button id="selectPathBtn" class"button is-warning">Path</button>
<h1>Hello World!</h1> <h1>Hello World!</h1>
<p>Welcome to your Electron application.</p> <p>Welcome to your Electron application.</p>
<p>Input Text</p>
<input type="text" id="txtBox" name="name" size="80">
<p>Input URL</p>
<input type="text" id="urlBox" name="name" size="80">
<p>Input Directory</p>
<input type="text" id="dirBox" name="name" size="80">
<progress id="file" max="100" value="70"></progress>
<input type="file" id="dirs" webkitdirectory directory/> <input type="file" id="dirs" webkitdirectory directory/>
</body> </body>
</html> </html>

View File

@ -1,6 +1,9 @@
const { app, BrowserWindow, Menu, dialog, ipcMain, nativeTheme } = require('electron'); const { app, BrowserWindow, Menu, dialog, ipcMain, nativeTheme } = require('electron');
const { download } = require("electron-dl");
const path = require('path'); const path = require('path');
//Menu.setApplicationMenu(false); //Menu.setApplicationMenu(false);
var fs = require('fs');
let window;
// Handle creating/removing shortcuts on Windows when installing/uninstalling. // Handle creating/removing shortcuts on Windows when installing/uninstalling.
// eslint-disable-next-line global-require // eslint-disable-next-line global-require
@ -16,8 +19,10 @@ const createWindow = () => {
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'preload.js'), preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true, nodeIntegration: true,
contextIsolation: true,
}, },
}); });
mainWindow.loadFile(path.join(__dirname, 'index.html')); 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) => { 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 // 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. // code. You can also put them in separate files and import them here.

View File

@ -1,9 +1,40 @@
const { ipcRenderer } = require('electron') 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', () => { process.once('loaded', () => {
window.addEventListener('message', evt => { window.addEventListener('message', evt => {
if (evt.data.type === 'select-dirs') { if (evt.data.type === 'select-dirs') {
ipcRenderer.send('select-dirs') ipcRenderer.send('select-dirs')
} }
}) });
}) });

View File

@ -5,71 +5,16 @@ const startUnzip = document.querySelector('startUnzip');
const stopUnzip = document.querySelector('stopUnzip'); const stopUnzip = document.querySelector('stopUnzip');
const selectVersionBtn = document.querySelector('selectVersion'); const selectVersionBtn = document.querySelector('selectVersion');
const selectPathBtn = document.querySelector('selectPathBtn'); const selectPathBtn = document.querySelector('selectPathBtn');
const writeFile = document.querySelector('writeFile');
var directoryPath = "C:"; const { remote, ipcRenderer } = require('electron');
const { remote } = require('electron');
const { Menu } = remote;
const { writeFile } = require('fs'); 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"); const { ipcRenderer } = require("electron");
ipcRenderer.on("download complete", (event, file) => { ipcRenderer.on("download complete", (event, file) => {
console.log(file); // Full file path console.log(file); // Full file path
}); });
ipcRenderer.on("download progress", (event, progress) => { ipcRenderer.on("download progress", (event, progress) => {
console.log(progress); // Progress in fraction, between 0 and 1 console.log(progress); // Progress in fraction, between 0 and 1
const progressInPercentages = progress * 100; // With decimal point and a bunch of numbers const progressInPercentages = progress * 100; // With decimal point and a bunch of numbers
@ -83,10 +28,4 @@ document.getElementById('dirs').addEventListener('click', (evt) => {
window.postMessage({ window.postMessage({
type: 'select-dirs', type: 'select-dirs',
}) })
}) });
// Get releases from Gitlab