Skip to content

Commit c9f8606

Browse files
Merge pull request #14 from foundersandcoders/workingEXE
Working exe
2 parents eb91429 + f964e26 commit c9f8606

File tree

8 files changed

+5675
-986
lines changed

8 files changed

+5675
-986
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
data.xml
2+
data.xml
3+
out/

forge.config.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
2+
const { FuseV1Options, FuseVersion } = require('@electron/fuses');
3+
4+
module.exports = {
5+
packagerConfig: {
6+
asar: true,
7+
},
8+
rebuildConfig: {},
9+
makers: [
10+
{
11+
name: '@electron-forge/maker-squirrel',
12+
config: {},
13+
},
14+
{
15+
name: '@electron-forge/maker-zip',
16+
platforms: ['darwin'],
17+
},
18+
{
19+
name: '@electron-forge/maker-deb',
20+
config: {},
21+
},
22+
{
23+
name: '@electron-forge/maker-rpm',
24+
config: {},
25+
},
26+
],
27+
plugins: [
28+
{
29+
name: '@electron-forge/plugin-auto-unpack-natives',
30+
config: {},
31+
},
32+
// Fuses are used to enable/disable various Electron functionality
33+
// at package time, before code signing the application
34+
new FusesPlugin({
35+
version: FuseVersion.V1,
36+
[FuseV1Options.RunAsNode]: false,
37+
[FuseV1Options.EnableCookieEncryption]: true,
38+
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
39+
[FuseV1Options.EnableNodeCliInspectArguments]: false,
40+
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
41+
[FuseV1Options.OnlyLoadAppFromAsar]: true,
42+
}),
43+
],
44+
};

main.js

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
// const {xsd} = require("./schema-for-validate")
22
const xmllint = require('xmllint');
3-
const { app, BrowserWindow, ipcMain, globalShortcut } = require("electron");
3+
const { app, BrowserWindow, ipcMain, globalShortcut, dialog, shell } = require("electron");
44
const path = require("node:path");
55
const fs = require("fs");
66
const xmlbuilder = require("xmlbuilder");
77
const currentDate = new Date(Date());
88
const isoWithoutMsOrZ = currentDate.toISOString().split('.')[0];
99
const dateOnlyString = isoWithoutMsOrZ.replace(/T.*/, '');
1010
const { Worker } = require('worker_threads');
11+
const os = require('os');
1112

13+
const log = require('electron-log');
14+
const { error } = require('node:console');
1215

16+
log.info('Application starting...');
17+
18+
process.on('uncaughtException', (error) => {
19+
log.error('Uncaught Exception:', error);
20+
});
21+
22+
const tempDir = path.join(os.tmpdir(), `electron-${app.name}-xmls`);
23+
let XMLfilePath = ""
24+
let versionForExport = ""
25+
const formatDateTime = (date) => {
26+
const yyyymmdd = date.toISOString().split('T')[0].replace(/-/g, '');
27+
const hhmmss = date.toTimeString().split(' ')[0].replace(/:/g, '');
28+
return `${yyyymmdd}-${hhmmss}`;
29+
};
1330
let xmlBase = {
1431

1532
Header: {
@@ -72,6 +89,7 @@ app.whenReady().then(() => {
7289

7390
ipcMain.on("upload-csv", (event, dataArray, version) => {
7491
try {
92+
versionForExport = version
7593
if (dataArray.some((learner, learnerIndex) =>
7694
learner.some((item, index) => {
7795
let exceptionIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192,193];
@@ -478,68 +496,104 @@ console.log(result); // Outputs: "ab-cd"*/
478496
.att('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance')
479497
.end({ pretty: true });
480498

481-
const formatDateTime = (date) => {
482-
const yyyymmdd = date.toISOString().split('T')[0].replace(/-/g, '');
483-
const hhmmss = date.toTimeString().split(' ')[0].replace(/:/g, '');
484-
return `${yyyymmdd}-${hhmmss}`;
485-
};
499+
486500

487501

488-
502+
XMLfilePath = path.join(tempDir, `ILR-10085696-${version.split('.')[0]}-${formatDateTime(currentDate)}-01.xml`)
489503

490-
fs.writeFile(`ILR-10085696-${version.split('.')[0]}-${formatDateTime(currentDate)}-01.xml`, xml, (err) => {
504+
fs.writeFile(XMLfilePath, xml, (err) => {
491505
if (err) {
492506
console.error(err);
493507
event.reply('xml-creation-failed', err.message);
494508
} else {
495509
console.log("The XML file was saved successfully.");
496510
event.reply('xml-created', `ILR-10085696-${version.split('.')[0]}-${formatDateTime(currentDate)}-01.xml`);
511+
log.info('xml file created');
512+
497513
}
498514

499515
});
500-
let xsd = fs.readFileSync("ILR-2024-25-schemafile-January.xsd", 'utf-8');
516+
let xsd = fs.readFileSync(path.join(__dirname, "ILR-2024-25-schemafile-January.xsd"), 'utf-8');
517+
log.info('schema declared');
501518

502519

503520

504-
const worker = new Worker('./xmlValidator.js', {
505-
workerData: { xml, xsd }
506-
});
521+
log.info('Attempting to create worker...');
522+
// log.info('xml before worker creation ', xml, ' xsd before worker creation ', xsd)
523+
const worker = new Worker(path.join(__dirname, 'xmlValidator.js'), {
524+
workerData: { xml, xsd }
525+
});
526+
log.info('Worker created successfully');
527+
507528

529+
log.info('worker created')
508530
worker.on('message', (result) => {
531+
log.info('information received')
532+
509533
if (result.valid) {
510534
console.log("The XML is valid!");
535+
511536
// event.reply('xml-validation-success', result);
512537
} else {
538+
log.info("results being sent ", result)
513539
event.reply('xml-validation-errors', result);
540+
514541
}
515542
});
516543

517544
worker.on('error', (error) => {
518545
console.error("Worker error:", error);
546+
log.error('Worker error:', error);
519547
event.reply('xml-validation-errors', [error.message]);
520548
});
521549

522550
worker.on('exit', (code) => {
523551
if (code !== 0) {
524552
console.error(`Worker stopped with exit code ${code}`);
553+
log.error(`Worker stopped with exit code ${code}`)
554+
525555
}
526556
});
527557

528-
529-
530-
531-
532-
533-
xml = null;
534-
xsd = null;
535558

536559

537560
}
538561
} catch (error) {
539562
console.error("An error occurred during XML validation:", error);
540563
}
564+
log.info('end of csv upload')
541565
});
542566

567+
ipcMain.on("openSave",event => {
568+
async function saveDialouge() {
569+
570+
try {
571+
572+
573+
// Show save dialog
574+
const result = await dialog.showSaveDialog({
575+
title: 'Export XML File',
576+
defaultPath: path.join(app.getPath('documents'), `ILR-10085696-${versionForExport.split('.')[0]}-${formatDateTime(currentDate)}-01.xml`),
577+
filters: [
578+
{ name: 'XML Files', extensions: ['xml'] }
579+
]
580+
});
581+
console.log('result.cancled', result.canceled, " result filepath " , result.filePath)
582+
// If user didn't cancel
583+
if (!result.canceled && result.filePath) {
584+
// Copy from temp to chosen location
585+
console.log('copy file from ',XMLfilePath, ' to ', result.filePath)
586+
await fs.promises.copyFile(XMLfilePath, result.filePath);
587+
}
588+
else{
589+
console.log('result canceled or has no file path')
590+
}
591+
} catch (error) {
592+
console.error('Error exporting temporary XML:', error);
593+
throw error;
594+
}}
595+
saveDialouge();
596+
});
543597

544598

545599
app.on("window-all-closed", () => {

0 commit comments

Comments
 (0)