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