Skip to content

Commit

Permalink
Switch to electron 20, temporal (?) removal of custom-electron-titlebar
Browse files Browse the repository at this point in the history
  • Loading branch information
jstaerk committed Nov 10, 2022
1 parent 7923c47 commit 09cd4af
Show file tree
Hide file tree
Showing 6 changed files with 1,032 additions and 973 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ general and some Electron and E-Invoice peculiarities like [interprocess (IPC) c
History
=============

<details>
<summary>1.2.1 13.10.2022</summary>
- upgrade to Electron 20 enabling e.g. newer Mac versions to run it
</details>

<details>
<summary>1.2.0 26.09.2022</summary>
- Allow to validate files via Mustangserver
</details>

<details>
<summary>1.1.5 15.08.2022</summary>
- XML invoice with large PDF (approx. > 1.4 MB) attached can't be opened #16
Expand Down
16 changes: 6 additions & 10 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ const Store = require("electron-store");
const isDev = require("electron-is-dev");
const https = require("https");
const menuFactoryService = require("./menuConfig");
const {
setupTitlebar,
attachTitlebarToWindow,
} = require("custom-electron-titlebar/main");

const i18next = require("i18next");
const Backend = require("i18next-fs-backend");
Expand All @@ -29,23 +25,21 @@ const config = require("./config/app.config");
const fs = require("fs");
const path = require("path");
const store = new Store();
setupTitlebar();

let mainWindow;
let currentLanguage = store.get("language") || config.fallbackLng;
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: false,
frame: true,
webPreferences: {
plugins: true,
preload: path.join(__dirname, "preload.js"),
},
});

mainWindow.loadFile(path.join(__dirname, "../dist/index.html"));
attachTitlebarToWindow(mainWindow);
mainWindow.on("closed", function () {
//store.clear();
//store.delete("access_token");
Expand Down Expand Up @@ -109,6 +103,8 @@ function createWindow() {
setTimeout(() => {
mainWindow.webContents.send("goToHome");
}, 200);
menuFactoryService.buildMenu(app, mainWindow, i18next, openFile);

}

app.on("ready", async () => {
Expand Down Expand Up @@ -407,7 +403,7 @@ function validateFile(xmlFilePath) {
const agent = new https.Agent({ rejectUnauthorized: false });
axios
.post(
"https://gw.usegroup.de:8243/mustang/v0.5.0/mustang/validate",
"https://gw.usegroup.de:8243/mustang/mustang/validate",
formData,
{
headers: {
Expand All @@ -428,8 +424,8 @@ function validateFile(xmlFilePath) {
?.criterion;
status = result?.validation?.summary[0]?.$?.status ?? "Invalid";
const isValid = status === "valid";
console.log("error", error);
console.log("status", status);
// console.log("error", error);
// console.log("status", status);
const request = {
path: xmlFilePath,
valid: isValid,
Expand Down
73 changes: 18 additions & 55 deletions app/preload.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
const { contextBridge, ipcRenderer, Menu, app, remote } = require('electron');
const { Titlebar, Color } = require("custom-electron-titlebar");

let myTitleBar;

const setTitleBar = () => {
let options = {
backgroundColor: Color.fromHex("#1f2c40"),
shadow: true,
icon: "../src/assets/img/logoonly.svg",
};
myTitleBar = new Titlebar(options);
};

window.addEventListener('DOMContentLoaded', () => {
setTitleBar();
});

const API = {
sendOpenMenu: () => {
Expand All @@ -25,10 +10,6 @@ const API = {
},
sendSyncValidateFile: (path) => {
const response = ipcRenderer.sendSync("validate-file", path);
if (response.code === 'ERR_UNAUTHORIZED') {
myTitleBar.dispose();
setTitleBar();
}
return response;
},
sendAppVersion: () => {
Expand All @@ -43,61 +24,49 @@ const API = {
sendOpenLink: () => {
ipcRenderer.send('open-link');
},
sendLoginSubmit: () => {
console.log("sendLoginSubmit");
ipcRenderer.send('login-submit');
sendLoginSubmit: () => {
console.log("sendLoginSubmit");
ipcRenderer.send('login-submit');
},
onPdfOpen: (callback) => {
ipcRenderer.on("pdf-open", (event, ...args) => callback(event, ...args));
ipcRenderer.on("pdf-open", (event, ...args) => callback(event, ...args));
},
onXmlOpen: (callback) => {
ipcRenderer.on("xml-open", (event, ...args) => callback(event, ...args));
ipcRenderer.on("xml-open", (event, ...args) => callback(event, ...args));
},
onLanguageChange: (callback) => {
ipcRenderer.on("language-change", (event, ...args) => callback(event, ...args));
ipcRenderer.on("language-change", (event, ...args) => callback(event, ...args));
},
onAppVersion: (callback) => {
ipcRenderer.on("app_version", (event, ...args) =>
callback(event, ...args));
ipcRenderer.on("app_version", (event, ...args) =>
callback(event, ...args));
},
onUpdateAvailable: (callback) => {
ipcRenderer.on("update_available", (event, ...args) => callback(event, ...args));
ipcRenderer.on("update_available", (event, ...args) => callback(event, ...args));
},
onUpdateDownloaded: (callback) => {
ipcRenderer.on("update_downloaded", (event, ...args) => callback(event, ...args));
ipcRenderer.on("update_downloaded", (event, ...args) => callback(event, ...args));
},
onFilePrintXml: (callback) => {
ipcRenderer.on("file-print-xml", (event, ...args) => callback(event, ...args));
ipcRenderer.on("file-print-xml", (event, ...args) => callback(event, ...args));
},
onFilePrintPdf: (callback) => {
ipcRenderer.on("file-print-pdf", (event, ...args) => callback(event, ...args));
ipcRenderer.on("file-print-pdf", (event, ...args) => callback(event, ...args));
},
onValidateComplete: (callback) => {
ipcRenderer.on("validate-complete", (event, ...args) => callback(event, ...args));
onValidateComplete: (callback) => {
ipcRenderer.on("validate-complete", (event, ...args) => callback(event, ...args));
},
onValidateClick: (callback) => {
ipcRenderer.on("validate-click", (event, ...args) => callback(event, ...args));
ipcRenderer.on("validate-click", (event, ...args) => callback(event, ...args));
},
onShowLoginMessage: (callback) => {
ipcRenderer.on("show-login-message", (event, ...args) =>
onShowLoginMessage: (callback) => {
ipcRenderer.on("show-login-message", (event, ...args) =>
{
if (args[0].type === 'success') {
myTitleBar.dispose();
setTitleBar();
}
console.log("onShowLoginMessage", args);
/*if (args[0].isDefaultUser) {
localStorage.setItem('isDefaultUser', true);
} else {
localStorage.setItem('isDefaultUser', false);
}*/
callback(event, ...args)});

},
onLogoutSubmit: (callback) => {
ipcRenderer.on("logout-submit", (event, ...args) => {
myTitleBar.dispose();
setTitleBar();
callback(event, ...args);
});
},
Expand All @@ -114,12 +83,6 @@ const API = {
setTitleBar();
},
updateMenuLanguage: (appName) => {
if (myTitleBar) {
myTitleBar.dispose();

setTitleBar();
myTitleBar.updateTitle(appName);
}
},
};

Expand Down
Loading

0 comments on commit 09cd4af

Please sign in to comment.