Update browser window calls.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "bodyshop-desktop",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.7-alpha.1",
|
||||
"description": "Shop Management System Partner",
|
||||
"main": "./out/main/index.js",
|
||||
"author": "Convenient Brands, LLC",
|
||||
|
||||
@@ -4,6 +4,7 @@ import { GraphQLClient, RequestMiddleware } from "graphql-request";
|
||||
import errorTypeCheck from "../../util/errorTypeCheck.js";
|
||||
import ipcTypes from "../../util/ipcTypes.json";
|
||||
import store from "../store/store.js";
|
||||
import getMainWindow from "../../util/getMainWindow.js";
|
||||
|
||||
const requestMiddleware: RequestMiddleware = async (request) => {
|
||||
const token = await getTokenFromRenderer();
|
||||
@@ -32,9 +33,9 @@ const client: GraphQLClient = new GraphQLClient(
|
||||
export async function getTokenFromRenderer(): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
try {
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0]; //TODO: Filter to only main window once a proper key has been set.
|
||||
const mainWindow = getMainWindow();
|
||||
//TODO: Verify that this will work if the app is minimized/closed.
|
||||
mainWindow.webContents.send(ipcTypes.toRenderer.user.getToken);
|
||||
mainWindow?.webContents.send(ipcTypes.toRenderer.user.getToken);
|
||||
} catch (error) {
|
||||
log.error(
|
||||
"Unable to send request to renderer process for token",
|
||||
|
||||
@@ -501,6 +501,7 @@ app.whenReady().then(async () => {
|
||||
// Do nothing if already running
|
||||
return;
|
||||
} else {
|
||||
log.info("Received Media URL: ", url);
|
||||
openInExplorer(url);
|
||||
}
|
||||
}
|
||||
@@ -568,19 +569,19 @@ app.whenReady().then(async () => {
|
||||
|
||||
autoUpdater.on("checking-for-update", () => {
|
||||
log.info("Checking for update...");
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0];
|
||||
const mainWindow = getMainWindow();
|
||||
mainWindow?.webContents.send(ipcTypes.toRenderer.updates.checking);
|
||||
});
|
||||
autoUpdater.on("update-available", (info) => {
|
||||
log.info("Update available.", info);
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0];
|
||||
const mainWindow = getMainWindow();
|
||||
mainWindow?.webContents.send(ipcTypes.toRenderer.updates.available, info);
|
||||
});
|
||||
autoUpdater.on("download-progress", (progress) => {
|
||||
log.info(`Download speed: ${progress.bytesPerSecond}`);
|
||||
log.info(`Downloaded ${progress.percent}%`);
|
||||
log.info(`Total downloaded ${progress.transferred}/${progress.total}`);
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0];
|
||||
const mainWindow = getMainWindow();
|
||||
mainWindow?.webContents.send(
|
||||
ipcTypes.toRenderer.updates.downloading,
|
||||
progress,
|
||||
@@ -588,7 +589,7 @@ app.whenReady().then(async () => {
|
||||
});
|
||||
autoUpdater.on("update-downloaded", (info) => {
|
||||
log.info("Update downloaded", info);
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0];
|
||||
const mainWindow = getMainWindow();
|
||||
mainWindow?.webContents.send(ipcTypes.toRenderer.updates.downloaded, info);
|
||||
});
|
||||
|
||||
@@ -599,7 +600,7 @@ app.whenReady().then(async () => {
|
||||
}
|
||||
|
||||
//The update itself will run when the bodyshop record is queried to know what release channel to use.
|
||||
createWindow();
|
||||
openMainWindow();
|
||||
ongoingMemoryDump();
|
||||
|
||||
app.on("activate", function () {
|
||||
@@ -658,7 +659,7 @@ function preQuitMethods(): void {
|
||||
}
|
||||
|
||||
function openMainWindow(): void {
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0];
|
||||
const mainWindow = getMainWindow();
|
||||
if (mainWindow) {
|
||||
mainWindow.show();
|
||||
} else {
|
||||
|
||||
@@ -7,6 +7,7 @@ import errorTypeCheck from "../../util/errorTypeCheck";
|
||||
import ipcTypes from "../../util/ipcTypes.json";
|
||||
import ImportJob from "../decoder/decoder";
|
||||
import store from "../store/store";
|
||||
import getMainWindow from "../../util/getMainWindow";
|
||||
let watcher: FSWatcher | null;
|
||||
|
||||
async function StartWatcher(): Promise<boolean> {
|
||||
@@ -107,23 +108,23 @@ function addWatcherPath(path: string | string[]): void {
|
||||
|
||||
function onWatcherReady(): void {
|
||||
if (watcher) {
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0]; //TODO: Filter to only main window once a proper key has been set.
|
||||
const mainWindow = getMainWindow();
|
||||
new Notification({
|
||||
title: "Watcher Started",
|
||||
body: "Newly exported estimates will be automatically uploaded.",
|
||||
}).show();
|
||||
log.info("Confirmed watched paths:", watcher.getWatched());
|
||||
mainWindow.webContents.send(ipcTypes.toRenderer.watcher.started);
|
||||
mainWindow?.webContents.send(ipcTypes.toRenderer.watcher.started);
|
||||
}
|
||||
}
|
||||
|
||||
async function StopWatcher(): Promise<boolean> {
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0]; //TODO: Filter to only main window once a proper key has been set.
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
if (watcher) {
|
||||
await watcher.close();
|
||||
log.info("Watcher stopped.");
|
||||
mainWindow.webContents.send(ipcTypes.toRenderer.watcher.stopped);
|
||||
mainWindow?.webContents.send(ipcTypes.toRenderer.watcher.stopped);
|
||||
|
||||
new Notification({
|
||||
title: "Watcher Stopped",
|
||||
|
||||
5
src/util/getMainWindow.ts
Normal file
5
src/util/getMainWindow.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { BrowserWindow } from "electron";
|
||||
|
||||
export default function getMainWindow(): BrowserWindow | null {
|
||||
return BrowserWindow.getAllWindows()[0] || null;
|
||||
}
|
||||
@@ -297,7 +297,7 @@ function ongoingMemoryDump() {
|
||||
log.warn("Unexpected error while writing memory stats log", err);
|
||||
}
|
||||
},
|
||||
5000, // 60 * 60 * 1000,
|
||||
60 * 60 * 1000,
|
||||
); // every 60 minutes
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user