diff --git a/gui_vue/electron/main/index.ts b/gui_vue/electron/main/index.ts index e9dfcacb..4e7d4494 100644 --- a/gui_vue/electron/main/index.ts +++ b/gui_vue/electron/main/index.ts @@ -1,10 +1,9 @@ -import { app, BrowserWindow, shell, ipcMain } from 'electron' -import { release, platform } from 'node:os' -import { join } from 'node:path' -import { autoUpdater } from "electron-updater" -import { existsSync } from "fs" -import { spawn } from "child_process" - +import { app, BrowserWindow, shell, ipcMain } from "electron"; +import { release, platform } from "node:os"; +import { join } from "node:path"; +import { autoUpdater } from "electron-updater"; +import { existsSync } from "fs"; +import { spawn } from "child_process"; // The built directory structure // @@ -16,22 +15,22 @@ import { spawn } from "child_process" // ├─┬ dist // │ └── index.html > Electron-Renderer // -process.env.DIST_ELECTRON = join(__dirname, '..') -process.env.DIST = join(process.env.DIST_ELECTRON, '../dist') +process.env.DIST_ELECTRON = join(__dirname, ".."); +process.env.DIST = join(process.env.DIST_ELECTRON, "../dist"); process.env.VITE_PUBLIC = process.env.VITE_DEV_SERVER_URL - ? join(process.env.DIST_ELECTRON, '../public') - : process.env.DIST + ? join(process.env.DIST_ELECTRON, "../public") + : process.env.DIST; // Disable GPU Acceleration for Windows 7 -if (release().startsWith('6.1')) app.disableHardwareAcceleration() +if (release().startsWith("6.1")) app.disableHardwareAcceleration(); // Set application name for Windows 10+ notifications -if (process.platform === 'win32') app.setAppUserModelId(app.getName()) +if (process.platform === "win32") app.setAppUserModelId(app.getName()); if (!app.requestSingleInstanceLock()) { - close_sub_processes() - app.quit() - process.exit(0) + close_sub_processes(); + app.quit(); + process.exit(0); } // Remove electron security warnings @@ -41,18 +40,18 @@ if (!app.requestSingleInstanceLock()) { // set daemon process var var daemonProcess = null; -let win: BrowserWindow | null = null +let win: BrowserWindow | null = null; // Here, you can also use other preload -const preload = join(__dirname, '../preload/index.js') -const url = process.env.VITE_DEV_SERVER_URL -const indexHtml = join(process.env.DIST, 'index.html') +const preload = join(__dirname, "../preload/index.js"); +const url = process.env.VITE_DEV_SERVER_URL; +const indexHtml = join(process.env.DIST, "index.html"); async function createWindow() { win = new BrowserWindow({ - title: 'FreeDATA', + title: "FreeDATA", width: 1200, height: 670, - icon: join(process.env.VITE_PUBLIC, 'icon_cube_border.png'), + icon: join(process.env.VITE_PUBLIC, "icon_cube_border.png"), autoHideMenuBar: true, webPreferences: { preload, @@ -64,29 +63,29 @@ async function createWindow() { nodeIntegration: true, contextIsolation: false, }, - }) + }); - if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298 - win.loadURL(url) + if (process.env.VITE_DEV_SERVER_URL) { + // electron-vite-vue#298 + win.loadURL(url); // Open devTool if the app is not packaged - win.webContents.openDevTools() + win.webContents.openDevTools(); } else { - win.loadFile(indexHtml) + win.loadFile(indexHtml); } // Test actively push message to the Electron-Renderer - win.webContents.on('did-finish-load', () => { - win?.webContents.send('main-process-message', new Date().toLocaleString()) - }) + win.webContents.on("did-finish-load", () => { + win?.webContents.send("main-process-message", new Date().toLocaleString()); + }); // Make all links open with the browser, not with the application win.webContents.setWindowOpenHandler(({ url }) => { - if (url.startsWith('https:')) shell.openExternal(url) - return { action: 'deny' } - }) + if (url.startsWith("https:")) shell.openExternal(url); + return { action: "deny" }; + }); // win.webContents.on('will-navigate', (event, url) => { }) #344 - win.once("ready-to-show", () => { //autoUpdater.logger = log.scope("updater"); //autoUpdater.channel = config.update_channel; @@ -95,14 +94,11 @@ async function createWindow() { autoUpdater.checkForUpdatesAndNotify(); //autoUpdater.quitAndInstall(); }); - - } //app.whenReady().then( app.whenReady().then(() => { - -createWindow() + createWindow(); //Generate daemon binary path var daemonPath = ""; @@ -114,11 +110,7 @@ createWindow() break; case "win32": case "win64": - daemonPath = join( - process.resourcesPath, - "modem", - "freedata-daemon.exe", - ); + daemonPath = join(process.resourcesPath, "modem", "freedata-daemon.exe"); break; default: console.log("Unhandled OS Platform: ", platform()); @@ -156,59 +148,49 @@ createWindow() console.log("Daemon binary doesn't exist--normal for dev environments."); } - - - -//) + //) }); +app.on("window-all-closed", () => { + win = null; + if (process.platform !== "darwin") app.quit(close_sub_processes()); +}); -app.on('window-all-closed', () => { - win = null - if (process.platform !== 'darwin') app.quit( - close_sub_processes() - - ) -}) - -app.on('second-instance', () => { +app.on("second-instance", () => { if (win) { // Focus on the main window if the user tried to open another - if (win.isMinimized()) win.restore() - win.focus() + if (win.isMinimized()) win.restore(); + win.focus(); } -}) +}); -app.on('activate', () => { - const allWindows = BrowserWindow.getAllWindows() +app.on("activate", () => { + const allWindows = BrowserWindow.getAllWindows(); if (allWindows.length) { - allWindows[0].focus() + allWindows[0].focus(); } else { - createWindow() + createWindow(); } -}) +}); // New window example arg: new windows url -ipcMain.handle('open-win', (_, arg) => { +ipcMain.handle("open-win", (_, arg) => { const childWindow = new BrowserWindow({ webPreferences: { preload, nodeIntegration: true, contextIsolation: false, }, - }) + }); if (process.env.VITE_DEV_SERVER_URL) { - childWindow.loadURL(`${url}#${arg}`) + childWindow.loadURL(`${url}#${arg}`); } else { - childWindow.loadFile(indexHtml, { hash: arg }) + childWindow.loadFile(indexHtml, { hash: arg }); } -}) +}); - - - - //restart and install udpate +//restart and install udpate ipcMain.on("request-restart-and-install-update", (event, data) => { close_sub_processes(); autoUpdater.quitAndInstall(); @@ -275,7 +257,6 @@ autoUpdater.on("error", (error) => { console.log("AUTO UPDATER : " + error); }); - function close_sub_processes() { console.log("closing sub processes"); @@ -307,4 +288,4 @@ function close_sub_processes() { } catch (e) { console.log(e); } -} \ No newline at end of file +} diff --git a/gui_vue/electron/preload/index.ts b/gui_vue/electron/preload/index.ts index 55028e7e..ff129a25 100644 --- a/gui_vue/electron/preload/index.ts +++ b/gui_vue/electron/preload/index.ts @@ -1,34 +1,34 @@ -import { ipcRenderer } from "electron" -import { autoUpdater } from "electron-updater" +import { ipcRenderer } from "electron"; +import { autoUpdater } from "electron-updater"; - - -function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) { +function domReady( + condition: DocumentReadyState[] = ["complete", "interactive"], +) { return new Promise((resolve) => { if (condition.includes(document.readyState)) { - resolve(true) + resolve(true); } else { - document.addEventListener('readystatechange', () => { + document.addEventListener("readystatechange", () => { if (condition.includes(document.readyState)) { - resolve(true) + resolve(true); } - }) + }); } - }) + }); } const safeDOM = { append(parent: HTMLElement, child: HTMLElement) { - if (!Array.from(parent.children).find(e => e === child)) { - return parent.appendChild(child) + if (!Array.from(parent.children).find((e) => e === child)) { + return parent.appendChild(child); } }, remove(parent: HTMLElement, child: HTMLElement) { - if (Array.from(parent.children).find(e => e === child)) { - return parent.removeChild(child) + if (Array.from(parent.children).find((e) => e === child)) { + return parent.removeChild(child); } }, -} +}; /** * https://tobiasahlin.com/spinkit @@ -37,7 +37,7 @@ const safeDOM = { * https://matejkustec.github.io/SpinThatShit */ function useLoading() { - const className = `loaders-css__square-spin` + const className = `loaders-css__square-spin`; const styleContent = ` @keyframes square-spin { 0% { @@ -82,55 +82,48 @@ function useLoading() { background: #282c34; z-index: 99999; } - ` - const oStyle = document.createElement('style') - const oDiv = document.createElement('div') + `; + const oStyle = document.createElement("style"); + const oDiv = document.createElement("div"); - oStyle.id = 'app-loading-style' - oStyle.innerHTML = styleContent - oDiv.className = 'app-loading-wrap' - oDiv.innerHTML = `
` + oStyle.id = "app-loading-style"; + oStyle.innerHTML = styleContent; + oDiv.className = "app-loading-wrap"; + oDiv.innerHTML = `
`; return { appendLoading() { - safeDOM.append(document.head, oStyle) - safeDOM.append(document.body, oDiv) + safeDOM.append(document.head, oStyle); + safeDOM.append(document.body, oDiv); }, removeLoading() { - safeDOM.remove(document.head, oStyle) - safeDOM.remove(document.body, oDiv) + safeDOM.remove(document.head, oStyle); + safeDOM.remove(document.body, oDiv); }, - } + }; } // ---------------------------------------------------------------------- -const { appendLoading, removeLoading } = useLoading() -domReady().then(appendLoading) - +const { appendLoading, removeLoading } = useLoading(); +domReady().then(appendLoading); window.onmessage = (ev) => { - ev.data.payload === 'removeLoading' && removeLoading() -} - -setTimeout(removeLoading, 4999) - - - + ev.data.payload === "removeLoading" && removeLoading(); +}; +setTimeout(removeLoading, 4999); window.addEventListener("DOMContentLoaded", () => { - // we are using this area for implementing the electron runUpdater - // we need access to DOM for displaying updater results in GUI - // close app, update and restart + // we are using this area for implementing the electron runUpdater + // we need access to DOM for displaying updater results in GUI + // close app, update and restart document .getElementById("update_and_install") .addEventListener("click", () => { ipcRenderer.send("request-restart-and-install-update"); }); - -}) - +}); // IPC ACTION FOR AUTO UPDATER ipcRenderer.on("action-updater", (event, arg) => { @@ -181,11 +174,12 @@ ipcRenderer.on("action-updater", (event, arg) => { //autoUpdater.quitAndInstall(); } if (arg.status == "update-not-available") { - - document.getElementById("updater_last_version").innerHTML = arg.info.releaseName - document.getElementById("updater_last_update").innerHTML = arg.info.releaseDate - document.getElementById("updater_release_notes").innerHTML = arg.info.releaseNotes - + document.getElementById("updater_last_version").innerHTML = + arg.info.releaseName; + document.getElementById("updater_last_update").innerHTML = + arg.info.releaseDate; + document.getElementById("updater_release_notes").innerHTML = + arg.info.releaseNotes; document.getElementById("updater_status").innerHTML = ''; diff --git a/gui_vue/src/components/chat_conversations.vue b/gui_vue/src/components/chat_conversations.vue index bef11117..2865fc5b 100644 --- a/gui_vue/src/components/chat_conversations.vue +++ b/gui_vue/src/components/chat_conversations.vue @@ -14,29 +14,30 @@ const state = useStateStore(pinia); import { useChatStore } from "../store/chatStore.js"; const chat = useChatStore(pinia); -import {getNewMessagesByDXCallsign, resetIsNewMessage} from '../js/chatHandler' - +import { + getNewMessagesByDXCallsign, + resetIsNewMessage, +} from "../js/chatHandler"; import chat_conversations_entry from "./chat_conversations_entry.vue"; - function chatSelected(callsign) { chat.selectedCallsign = callsign.toUpperCase(); // scroll message container to bottom var messageBody = document.getElementById("message-container"); - if (messageBody != null ) { + if (messageBody != null) { // needs sensible defaults messageBody.scrollTop = messageBody.scrollHeight - messageBody.clientHeight; } - if (getNewMessagesByDXCallsign(callsign)[1] > 0){ - let messageArray = getNewMessagesByDXCallsign(callsign)[2] - console.log(messageArray) + if (getNewMessagesByDXCallsign(callsign)[1] > 0) { + let messageArray = getNewMessagesByDXCallsign(callsign)[2]; + console.log(messageArray); - for (const key in messageArray){ - resetIsNewMessage(messageArray[key].uuid, false) - } + for (const key in messageArray) { + resetIsNewMessage(messageArray[key].uuid, false); + } } try { @@ -58,7 +59,7 @@ function chatSelected(callsign) {