diff --git a/starsky/starsky.foundation.database/Helpers/SetupDatebaseTypes.cs b/starsky/starsky.foundation.database/Helpers/SetupDatebaseTypes.cs index b02cc12b2f..34053c3275 100644 --- a/starsky/starsky.foundation.database/Helpers/SetupDatebaseTypes.cs +++ b/starsky/starsky.foundation.database/Helpers/SetupDatebaseTypes.cs @@ -104,11 +104,6 @@ internal DbContextOptions BuilderDbFactorySwitch( public void BuilderDb(string? foundationDatabaseName = "") { if ( _services == null ) throw new AggregateException("services is missing"); - if ( _logger != null && _appSettings.IsVerbose() ) - { - _logger.LogInformation($"Database connection: {_appSettings.DatabaseConnection}"); - } - _services.AddScoped(_ => new ApplicationDbContext(BuilderDbFactorySwitch(foundationDatabaseName))); } diff --git a/starsky/starskytest/starsky.foundation.database/Helpers/SetupDatabaseTypesTest.cs b/starsky/starskytest/starsky.foundation.database/Helpers/SetupDatabaseTypesTest.cs index fc5dd0bab5..5ed52a1ea3 100644 --- a/starsky/starskytest/starsky.foundation.database/Helpers/SetupDatabaseTypesTest.cs +++ b/starsky/starskytest/starsky.foundation.database/Helpers/SetupDatabaseTypesTest.cs @@ -87,20 +87,5 @@ public void BuilderDb_fail() new SetupDatabaseTypes(appSettings).BuilderDb(); // expect exception } - - [TestMethod] - public void BuilderDb_console() - { - var console = new FakeIWebLogger(); - var appSettings = new AppSettings - { - Verbose = true, DatabaseType = AppSettings.DatabaseTypeList.InMemoryDatabase - }; - var services = new ServiceCollection(); - - new SetupDatabaseTypes(appSettings, services, console).BuilderDb(); - - Assert.IsTrue(console.TrackedInformation[0].Item2?.Contains("Database connection:")); - } } } diff --git a/starskydesktop/src/app/child-process/setup-child-process.spec.ts b/starskydesktop/src/app/child-process/setup-child-process.spec.ts index 2daa61f3fb..e17af6f7cd 100644 --- a/starskydesktop/src/app/child-process/setup-child-process.spec.ts +++ b/starskydesktop/src/app/child-process/setup-child-process.spec.ts @@ -4,7 +4,7 @@ import * as fs from "fs"; import * as readline from "readline"; import * as GetPortProxy from "../get-free-port/get-free-port"; import logger from "../logger/logger"; -import { setupChildProcess } from "./setup-child-process"; +import { SetupChildProcess } from "./setup-child-process"; jest.mock("child_process", () => { return { @@ -84,7 +84,7 @@ describe("setupChildProcess", () => { return null; }); - await setupChildProcess(); + await SetupChildProcess(); expect(mkdirSpy).toHaveBeenCalled(); expect(mkdirSpy).toHaveBeenCalledTimes(2); diff --git a/starskydesktop/src/app/child-process/setup-child-process.ts b/starskydesktop/src/app/child-process/setup-child-process.ts index 06dfc66120..aa1a0356b2 100644 --- a/starskydesktop/src/app/child-process/setup-child-process.ts +++ b/starskydesktop/src/app/child-process/setup-child-process.ts @@ -4,6 +4,7 @@ import * as fs from "fs"; import * as path from "path"; import * as readline from "readline"; import { GetFreePort } from "../get-free-port/get-free-port"; +import global, { SharedSettings } from "../global/global"; import logger from "../logger/logger"; import { isPackaged } from "../os-info/is-packaged"; import { childProcessPath } from "./child-process-path"; @@ -17,8 +18,8 @@ function spawnChildProcess(appStarskyPath: string) { env: process.env, }); - starskyChild.on("exit", function (code) { - logger.info("EXIT: CODE: " + code); + starskyChild.on("exit", (code) => { + logger.info(`EXIT: CODE: ${code}`); }); starskyChild.stdout.on("data", (data: string) => { @@ -32,116 +33,116 @@ function spawnChildProcess(appStarskyPath: string) { return starskyChild; } -export function setupChildProcess() :Promise { - return new Promise((resolve) => { - const thumbnailTempFolder = path.join(electronCacheLocation(), "thumbnailTempFolder"); - if (!fs.existsSync(thumbnailTempFolder)) { - fs.mkdirSync(thumbnailTempFolder); - } - - const tempFolder = path.join(electronCacheLocation(), "tempFolder"); - if (!fs.existsSync(tempFolder)) { - fs.mkdirSync(tempFolder); - } - - const appSettingsPath = path.join(electronCacheLocation(), "appsettings.json"); - const databaseConnection = `Data Source=${path.join(electronCacheLocation(), "starsky.db")}`; - - GetFreePort().then((appPort)=>{ - logger.info(`next: port: ${appPort}`); - logger.info(`-appSettingsPath > ${appSettingsPath}`); - - const env = { - ASPNETCORE_URLS: `http://localhost:${appPort}`, - app__thumbnailTempFolder: thumbnailTempFolder, - app__tempFolder: tempFolder, - app__appsettingspath: appSettingsPath, - app__NoAccountLocalhost: "true", - app__UseLocalDesktop: "true", - app__databaseConnection: databaseConnection, - app__ThumbnailGenerationIntervalInMinutes: !isPackaged() ? "-1" : "300", - app__AccountRegisterDefaultRole: "Administrator", - app__Verbose: !isPackaged() ? "true" : "false", - }; - process.env = { ...process.env, ...env }; - - logger.info("env settings ->"); - logger.info(env); - logger.info(`app data folder -> ${path.join(app.getPath("appData"), "starsky")}`); - - const appStarskyPath = childProcessPath(); - - try { - fs.chmodSync(appStarskyPath, 0o755); - } catch (error) { - // do nothing - } - - let starskyChild = spawnChildProcess(appStarskyPath); - - starskyChild.addListener("exit", () => { - logger.info("restart process"); - - SpawnCleanMacOs(appStarskyPath, process.platform).then(() => { - starskyChild = spawnChildProcess(appStarskyPath); - starskyChild.stdout.on("data",()=> resolve(appPort)) +function CreateFolder() { + const thumbnailTempFolder = path.join(electronCacheLocation(), "thumbnailTempFolder"); + if (!fs.existsSync(thumbnailTempFolder)) { + fs.mkdirSync(thumbnailTempFolder); + } + + const tempFolder = path.join(electronCacheLocation(), "tempFolder"); + if (!fs.existsSync(tempFolder)) { + fs.mkdirSync(tempFolder); + } + return { + tempFolder, + thumbnailTempFolder, + }; +} + +function Env(appPort: number) { + const databaseConnection = `Data Source=${path.join(electronCacheLocation(), "starsky.db")}`; + const appSettingsPath = path.join(electronCacheLocation(), "appsettings.json"); + const result = CreateFolder(); + + // Set Global Helper + (global.shared as SharedSettings).port = appPort; + (global.shared as SharedSettings).remote = false; + (global.shared as SharedSettings).baseUrl = `http://localhost:${appPort}`; + + return { + ASPNETCORE_URLS: `http://localhost:${appPort}`, + app__thumbnailTempFolder: result.thumbnailTempFolder, + app__tempFolder: result.tempFolder, + app__appsettingspath: appSettingsPath, + app__NoAccountLocalhost: "true", + app__UseLocalDesktop: "true", + app__databaseConnection: databaseConnection, + app__ThumbnailGenerationIntervalInMinutes: !isPackaged() ? "-1" : "300", + app__AccountRegisterDefaultRole: "Administrator", + app__Verbose: !isPackaged() ? "true" : "false", + }; +} + +function StartProcess(): Promise { + return new Promise((resolve, reject) => { + CreateFolder(); + GetFreePort() + .then((appPort) => { + const env = Env(appPort); + process.env = { ...process.env, ...env }; + + const appStarskyPath = childProcessPath(); + + try { + fs.chmodSync(appStarskyPath, 0o755); + } catch (error) { + // do nothing + } + + const starskyChild = spawnChildProcess(appStarskyPath); + + starskyChild.on("exit", () => { + SpawnCleanMacOs(appStarskyPath, process.platform) + .then(() => { + reject(new Error("Retry please: process failed")); + }) + .catch(reject); }); - }); - - starskyChild.stdout.on("data",()=> resolve(appPort)) - - starskyChild.addListener("close", () => { - logger.info("restart process"); - // eslint-disable-next-line @typescript-eslint/no-floating-promises - GetFreePort().then((p) => { - appPort = p; - env.ASPNETCORE_URLS = `http://localhost:${appPort}`; - logger.info(`next: port: ${appPort}`); - starskyChild = spawnChildProcess(appStarskyPath); + starskyChild.stdout.on("data", () => { + resolve(appPort); }); - }); - - readline.emitKeypressEvents(process.stdin); - - /** - * Needed for terminals - * @param {bool} modes true or false - */ - function setRawMode(modes: boolean) { - if (!process.stdin.setRawMode) return; - process.stdin.setRawMode(modes); - } - - function kill() { - setRawMode(false); - if (!starskyChild) return; - starskyChild.stdin.end(); - starskyChild.kill(); - } - - setRawMode(true); - - process.stdin.on("keypress", (_, key: { name: string; ctrl: string }) => { - if (key.ctrl && key.name === "c") { + + readline.emitKeypressEvents(process.stdin); + + function setRawMode(modes: boolean) { + if (!process.stdin.setRawMode) return; + process.stdin.setRawMode(modes); + } + + function kill() { + setRawMode(false); + if (!starskyChild) return; + starskyChild.stdin.end(); + starskyChild.kill(); + } + + setRawMode(true); + + process.stdin.on("keypress", (_, key: { name: string; ctrl: string }) => { + if (key.ctrl && key.name === "c") { + kill(); + logger.info("=> (pressed ctrl & c) to the end of starsky"); + setTimeout(() => { + process.exit(0); + }, 400); + } + }); + + app.on("before-quit", (event) => { + event.preventDefault(); + logger.info("=> end default"); kill(); - logger.info("=> (pressed ctrl & c) to the end of starsky"); setTimeout(() => { process.exit(0); }, 400); - } - }); - - app.on("before-quit", (event) => { - event.preventDefault(); - logger.info("=> end default"); - kill(); - setTimeout(() => { - process.exit(0); - }, 400); - }); - }); - - + }); + }) + .catch(reject); }); } + +export async function SetupChildProcess(): Promise { + // Start the process + return StartProcess(); +} diff --git a/starskydesktop/src/app/child-process/spawn-clean-mac-os.ts b/starskydesktop/src/app/child-process/spawn-clean-mac-os.ts index b6a8bbedd5..d9d082aded 100644 --- a/starskydesktop/src/app/child-process/spawn-clean-mac-os.ts +++ b/starskydesktop/src/app/child-process/spawn-clean-mac-os.ts @@ -50,7 +50,7 @@ function executeCodesignCommand(appStarskyPath: string): Promise { const codeSignSpawn = spawn("codesign", args, options); codeSignSpawn.on("exit", (code) => { - logger.info("code sign EXIT: CODE: " + code); + logger.info(`code sign EXIT: CODE: ${code}`); if (code === 0) { resolve(); } else { @@ -68,15 +68,15 @@ function executeCodesignCommand(appStarskyPath: string): Promise { }); } -export function SpawnCleanMacOs(appStarskyPath: string, processPlatform: string): Promise { +export function SpawnCleanMacOs(appStarskyPath: string, processPlatform: string): Promise { return new Promise((resolve, reject) => { if (processPlatform !== "darwin") { - return resolve(); + resolve(true); } Promise.all([executeXattrCommand(appStarskyPath), executeCodesignCommand(appStarskyPath)]) .then(() => { - resolve(); + resolve(true); }) .catch((err) => { reject(err); diff --git a/starskydesktop/src/app/global/global.ts b/starskydesktop/src/app/global/global.ts new file mode 100644 index 0000000000..e8eee8f08d --- /dev/null +++ b/starskydesktop/src/app/global/global.ts @@ -0,0 +1,12 @@ +export interface SharedSettings { + port: number; + remote: boolean | undefined; + baseUrl: string; +} + +global.shared = { + port: -1, + remote: undefined, + baseUrl: ``, +} as SharedSettings; +export default global; diff --git a/starskydesktop/src/app/main-window/create-main-window.ts b/starskydesktop/src/app/main-window/create-main-window.ts index 163a872333..5e55bbcf0c 100644 --- a/starskydesktop/src/app/main-window/create-main-window.ts +++ b/starskydesktop/src/app/main-window/create-main-window.ts @@ -1,13 +1,14 @@ import { BrowserWindow } from "electron"; import * as path from "path"; import { GetAppVersion } from "../config/get-app-version"; +import logger from "../logger/logger"; import { windowStateKeeper } from "../window-state-keeper/window-state-keeper"; import { getNewFocusedWindow } from "./get-new-focused-window"; import { mainWindows } from "./main-windows.const"; import { removeRememberUrl, saveRememberUrl } from "./save-remember-url"; import { spellCheck } from "./spellcheck"; -async function createMainWindow(openSpecificUrl: string, offset = 0): Promise { +async function CreateMainWindow(openSpecificUrl: string, offset = 0): Promise { const mainWindowStateKeeper = await windowStateKeeper("main"); const { x, y } = getNewFocusedWindow( @@ -24,7 +25,7 @@ async function createMainWindow(openSpecificUrl: string, offset = 0): Promise
{ - console.log(url); - + logger.info(`[setWindowOpenHandler] ${url}`); return { action: "allow", overrideBrowserWindowOptions: { @@ -91,7 +92,9 @@ async function createMainWindow(openSpecificUrl: string, offset = 0): Promise
{ - newWindow.webContents - .executeJavaScript( - "window.api.send('APP_VERSION',null); window.api.receive('APP_VERSION')", - true - ) - .then((result) => { - console.log(result); // Will be the JSON object from the fetch call - }); - }); \ No newline at end of file diff --git a/starskydesktop/src/app/main-window/restore-main-window.ts b/starskydesktop/src/app/main-window/restore-main-window.ts index 3d7aca362c..11574f38e1 100644 --- a/starskydesktop/src/app/main-window/restore-main-window.ts +++ b/starskydesktop/src/app/main-window/restore-main-window.ts @@ -1,21 +1,20 @@ import * as appConfig from "electron-settings"; import RememberUrl from "../config/remember-url-settings.const"; import logger from "../logger/logger"; -import createMainWindow from "./create-main-window"; +import CreateMainWindow from "./create-main-window"; -async function runCreateWindow(baseUrl: string, rememberUrls: string[]) { - let i = 0; - for (const key of Object.keys(rememberUrls)) { - const url = baseUrl + rememberUrls[key]; - await createMainWindow(url, i * 20); - i++; - } +async function runCreateWindow(baseUrl: string, rememberUrls: { [key: string]: string }) { + await Promise.all( + Object.values(rememberUrls).map(async (url, index) => { + await CreateMainWindow(baseUrl + url, index * 20); + }) + ); } -async function getRememberUrl(): Promise { +async function getRememberUrl(): Promise<{ [key: string]: string }> { const fallbackConfig = { 0: "?f=/" }; if (await appConfig.has(RememberUrl)) { - const getConfig = (await appConfig.get(RememberUrl)) as object; + const getConfig = (await appConfig.get(RememberUrl)) as { [key: string]: string }; if (Object.keys(getConfig).length >= 1) return getConfig; return fallbackConfig; } @@ -23,7 +22,6 @@ async function getRememberUrl(): Promise { } export async function RestoreMainWindow(baseUrl: string): Promise { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const rememberUrls = await getRememberUrl(); logger.info("[RestoreMainWindow] rememberUrls"); diff --git a/starskydesktop/src/app/startup/restore-warmup-main-window-and-close-splash.spec.ts b/starskydesktop/src/app/startup/restore-warmup-main-window-and-close-splash.spec.ts index b2e59fac49..87eb96375e 100644 --- a/starskydesktop/src/app/startup/restore-warmup-main-window-and-close-splash.spec.ts +++ b/starskydesktop/src/app/startup/restore-warmup-main-window-and-close-splash.spec.ts @@ -44,7 +44,7 @@ describe("RestoreWarmupMainWindowAndCloseSplash", () => { .mockImplementationOnce(() => Promise.resolve()); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - RestoreWarmupMainWindowAndCloseSplash.default(1, window as any, true); + RestoreWarmupMainWindowAndCloseSplash.default(1, window as any); expect(window[0].close).toHaveBeenCalled(); expect(restoreMainWindowSpy).toHaveBeenCalled(); @@ -57,18 +57,16 @@ describe("RestoreWarmupMainWindowAndCloseSplash", () => { }, ]; - const warmupServerSpy = jest - .spyOn(WarmupServer, "WarmupServer") - .mockImplementationOnce(() => { - return Promise.resolve(true); - }); + const warmupServerSpy = jest.spyOn(WarmupServer, "WarmupServer").mockImplementationOnce(() => { + return Promise.resolve(true); + }); const restoreMainWindowSpy = jest .spyOn(RestoreMainWindow, "RestoreMainWindow") .mockImplementationOnce(() => Promise.resolve()); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - RestoreWarmupMainWindowAndCloseSplash.default(1, window as any, false); + RestoreWarmupMainWindowAndCloseSplash.default(1, window as any); expect(warmupServerSpy).toHaveBeenCalled(); expect(restoreMainWindowSpy).toHaveBeenCalled(); diff --git a/starskydesktop/src/app/startup/restore-warmup-main-window-and-close-splash.ts b/starskydesktop/src/app/startup/restore-warmup-main-window-and-close-splash.ts index 50ef8c12d5..0c9d291990 100644 --- a/starskydesktop/src/app/startup/restore-warmup-main-window-and-close-splash.ts +++ b/starskydesktop/src/app/startup/restore-warmup-main-window-and-close-splash.ts @@ -1,35 +1,49 @@ import { BrowserWindow } from "electron"; +import global, { SharedSettings } from "../global/global"; +import logger from "../logger/logger"; import { RestoreMainWindow } from "../main-window/restore-main-window"; import createCheckForUpdatesContainerWindow from "../updates-warning-window/updates-warning-window"; import { CloseSplash } from "../warmup/splash"; import { WarmupServer } from "../warmup/warmup-server"; -import logger from "../logger/logger"; -export function RestoreMainWindowAndCloseSplash(baseUrl: string, - splashWindows: BrowserWindow[] -) { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - RestoreMainWindow(baseUrl).then(() => { - createCheckForUpdatesContainerWindow().catch(() => {}); +export function RestoreMainWindowAndCloseSplash(baseUrl: string, splashWindows: BrowserWindow[]) { + return new Promise((resolve, reject) => { + RestoreMainWindow(baseUrl) + .then(() => { + createCheckForUpdatesContainerWindow() + .catch(() => {}) + .then(() => resolve) + .catch(() => reject); + }) + .then(() => { + CloseSplash(splashWindows[0]); + }) + .catch(() => reject); }); - CloseSplash(splashWindows[0]); } -export default function RestoreWarmupMainWindowAndCloseSplash( +export default async function RestoreWarmupMainWindowAndCloseSplash( appPort: number, - splashWindows: BrowserWindow[], - isRemote: boolean -) { - if (!isRemote) { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - WarmupServer(appPort).then((result) => { - if (result) { - RestoreMainWindowAndCloseSplash(`http://localhost:${appPort}`,splashWindows); - return; - } - }); - return; - } - // TODO TEST - // RestoreMainWindowAndCloseSplash(splashWindows); + splashWindows: BrowserWindow[] +): Promise { + return new Promise((resolve, reject) => { + logger.info(`[RestoreWarmupMainWindowAndCloseSplash] appPort:: ${appPort}`); + const { baseUrl } = global.shared as SharedSettings; + + WarmupServer(appPort) + .then(async (result) => { + logger.info(`[RestoreWarmupMainWindowAndCloseSplash] result:: ${result}`); + + if (result) { + await RestoreMainWindowAndCloseSplash(baseUrl, splashWindows); + resolve(appPort); + return; + } + reject(new Error("WarmupServer failed")); + }) + .catch(() => {}); + // resolve(true) + // TODO TEST + // RestoreMainWindowAndCloseSplash(splashWindows); + }); } diff --git a/starskydesktop/src/app/warmup/is-remote.ts b/starskydesktop/src/app/warmup/is-remote.ts index 1370f7f73c..5f2f70ab33 100644 --- a/starskydesktop/src/app/warmup/is-remote.ts +++ b/starskydesktop/src/app/warmup/is-remote.ts @@ -3,7 +3,7 @@ import { LocationIsRemoteSettingsKey } from "../config/location-settings.const"; /* eslint-disable @typescript-eslint/no-base-to-string */ export async function IsRemote(): Promise { - const currentSettings = await appConfig.get(LocationIsRemoteSettingsKey); + const currentSettings = (await appConfig.get(LocationIsRemoteSettingsKey)) as string; let isLocationRemote = false; if (currentSettings !== undefined && currentSettings !== null) { diff --git a/starskydesktop/src/client/pages/error/___legacy___ b/starskydesktop/src/client/pages/error/___legacy___ new file mode 100644 index 0000000000..e69de29bb2 diff --git a/starskydesktop/src/client/pages/redirect/__legacy___ b/starskydesktop/src/client/pages/redirect/__legacy___ new file mode 100644 index 0000000000..e69de29bb2 diff --git a/starskydesktop/src/client/pages/start/start.html b/starskydesktop/src/client/pages/start/start.html new file mode 100644 index 0000000000..067e62db06 --- /dev/null +++ b/starskydesktop/src/client/pages/start/start.html @@ -0,0 +1,18 @@ + + + + + + Loading Starsky + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/starskydesktop/src/main/main.spec.ts b/starskydesktop/src/main/main.spec.ts index 6988af5818..d404ffb9cb 100644 --- a/starskydesktop/src/main/main.spec.ts +++ b/starskydesktop/src/main/main.spec.ts @@ -56,9 +56,16 @@ jest.mock("electron", () => { __esModule: true, }, // eslint-disable-next-line object-shorthand, func-names, @typescript-eslint/no-unused-vars - BrowserWindow: function (_x:object, _y: number, _w: number, _h: number, _s: boolean, _w2: object) { + BrowserWindow: function ( + _x: object, + _y: number, + _w: number, + _h: number, + _s: boolean, + _w2: object + ) { return mockBrowserWindow; - } + }, }; }); @@ -77,54 +84,41 @@ describe("main", () => { let isRemoteSpy: any = jest.fn(); beforeAll(() => { - jest - .spyOn(updatesWarningWindow, "default") - .mockImplementationOnce(() => Promise.resolve(true)); + jest.spyOn(updatesWarningWindow, "default").mockImplementationOnce(() => Promise.resolve(true)); jest.spyOn(ipcBridge, "default").mockImplementationOnce(() => {}); - jest - .spyOn(defaultAppSettings, "default") - .mockImplementationOnce(() => "test"); + jest.spyOn(defaultAppSettings, "default").mockImplementationOnce(() => "test"); setupChildProcessSpy = jest - .spyOn(setupChildProcess, "setupChildProcess") + .spyOn(setupChildProcess, "SetupChildProcess") .mockImplementationOnce(() => Promise.resolve(1)); - jest - .spyOn(MakeTempPath, "MakeTempPath") - .mockImplementationOnce(() => "test"); - jest - .spyOn(MakeLogsPath, "MakeLogsPath") - .mockImplementationOnce(() => "test"); + jest.spyOn(MakeTempPath, "MakeTempPath").mockImplementationOnce(() => "test"); + jest.spyOn(MakeLogsPath, "MakeLogsPath").mockImplementationOnce(() => "test"); jest .spyOn(SetupFileWatcher, "SetupFileWatcher") .mockImplementationOnce(() => Promise.resolve()); - restoreWarmupMainWindowAndCloseSplashSpy = jest.spyOn( - RestoreWarmupMainWindowAndCloseSplash, - "default" - ).mockImplementationOnce(() => {}); + restoreWarmupMainWindowAndCloseSplashSpy = jest + .spyOn(RestoreWarmupMainWindowAndCloseSplash, "default") + .mockImplementationOnce(() => { + return Promise.resolve(1); + }); isRemoteSpy = jest.spyOn(IsRemote, "IsRemote").mockImplementationOnce(() => { return Promise.resolve(false); }); - jest - .spyOn(SetupSplash, "SetupSplash") - .mockImplementationOnce(() => { - return {} as any; - }); + jest.spyOn(SetupSplash, "SetupSplash").mockImplementationOnce(() => { + return {} as any; + }); - jest - .spyOn(SetupSplash, "CloseSplash") - .mockImplementationOnce(() => { - return { - close: jest.fn() - } as any; - }); + jest.spyOn(SetupSplash, "CloseSplash").mockImplementationOnce(() => { + return { + close: jest.fn(), + } as any; + }); - jest - .spyOn(WarmupServer, "WarmupServer") - .mockImplementation(() => Promise.resolve(true)); + jest.spyOn(WarmupServer, "WarmupServer").mockImplementation(() => Promise.resolve(true)); // this excuted only once jest.spyOn(app, "on").mockImplementation((name: any, func) => { @@ -136,7 +130,7 @@ describe("main", () => { jest.spyOn(logger, "default").mockImplementation(() => { return { info: jest.fn(), - warn: jest.fn() + warn: jest.fn(), }; }); @@ -154,17 +148,13 @@ describe("main", () => { jest.spyOn(DockMenu, "default").mockImplementationOnce(() => {}); jest.spyOn(AppMenu, "default").mockImplementationOnce(() => {}); - jest - .spyOn(SetupSplash, "SetupSplash") - .mockImplementation(() => { - return {} as any; - }); + jest.spyOn(SetupSplash, "SetupSplash").mockImplementation(() => { + return {} as any; + }); - jest - .spyOn(SetupSplash, "CloseSplash") - .mockImplementation(() => { - return {} as any; - }); + jest.spyOn(SetupSplash, "CloseSplash").mockImplementation(() => { + return {} as any; + }); // eslint-disable-next-line @typescript-eslint/no-unused-vars jest.spyOn(app, "on").mockImplementation((_: any, _2) => { @@ -176,9 +166,7 @@ describe("main", () => { }); it("when activate and there a no windows it should create one", () => { - jest - .spyOn(updatesWarningWindow, "default") - .mockImplementationOnce(() => Promise.resolve(true)); + jest.spyOn(updatesWarningWindow, "default").mockImplementationOnce(() => Promise.resolve(true)); jest .spyOn(RestoreMainWindow, "RestoreMainWindow") @@ -186,26 +174,24 @@ describe("main", () => { jest.spyOn(DockMenu, "default").mockImplementationOnce(() => {}); jest.spyOn(AppMenu, "default").mockImplementationOnce(() => {}); - jest - .spyOn(createMainWindow, "default") - .mockImplementationOnce(() => Promise.resolve() as any); - - jest.spyOn(RestoreWarmupMainWindowAndCloseSplash, "RestoreMainWindowAndCloseSplash") - .mockImplementationOnce(() => {}).mockImplementationOnce(() => { }); + jest.spyOn(createMainWindow, "default").mockImplementationOnce(() => Promise.resolve() as any); jest - .spyOn(SetupSplash, "CloseSplash") - .mockImplementation(() => { - return {} as any; + .spyOn(RestoreWarmupMainWindowAndCloseSplash, "RestoreMainWindowAndCloseSplash") + .mockImplementationOnce(() => { + return Promise.resolve(1); + }) + .mockImplementationOnce(() => { + return Promise.resolve(1); }); - jest - .spyOn(WarmupServer, "WarmupServer") - .mockImplementation(() => Promise.resolve(true)); + jest.spyOn(SetupSplash, "CloseSplash").mockImplementation(() => { + return {} as any; + }); - jest - .spyOn(SetupSplash, "SetupSplash") - .mockImplementation(() => Promise.resolve({}) as any); + jest.spyOn(WarmupServer, "WarmupServer").mockImplementation(() => Promise.resolve(true)); + + jest.spyOn(SetupSplash, "SetupSplash").mockImplementation(() => Promise.resolve({}) as any); jest.spyOn(app, "on").mockImplementation((name: any, func) => { if (name === "activate") { @@ -224,9 +210,7 @@ describe("main", () => { }); it("when activate and there windows it not should create one", () => { - jest - .spyOn(BrowserWindow, "getAllWindows") - .mockImplementation(() => ["t"] as any); + jest.spyOn(BrowserWindow, "getAllWindows").mockImplementation(() => ["t"] as any); jest.spyOn(DockMenu, "default").mockImplementationOnce(() => {}); jest.spyOn(AppMenu, "default").mockImplementationOnce(() => {}); @@ -253,31 +237,25 @@ describe("main", () => { beforeAll(() => { originalPlatform = process.platform; Object.defineProperty(process, "platform", { - value: "MockOS" + value: "MockOS", }); }); afterAll(() => { Object.defineProperty(process, "platform", { - value: originalPlatform + value: originalPlatform, }); }); it("window all closed", () => { - const appQuitSpy = jest - .spyOn(app, "quit") - .mockReset() - .mockImplementation(); + const appQuitSpy = jest.spyOn(app, "quit").mockReset().mockImplementation(); onState.windowallclosed(); expect(appQuitSpy).toHaveBeenCalled(); }); it("window all closed (but not for mac os)", () => { - const appQuitSpy = jest - .spyOn(app, "quit") - .mockReset() - .mockImplementation(); + const appQuitSpy = jest.spyOn(app, "quit").mockReset().mockImplementation(); Object.defineProperty(process, "platform", { - value: "darwin" + value: "darwin", }); onState.windowallclosed(); expect(appQuitSpy).toHaveBeenCalledTimes(0); @@ -295,7 +273,7 @@ describe("main", () => { // eslint-disable-next-line @typescript-eslint/ban-types on: (_: string, func: Function) => { func(); - } + }, }; onState.webcontentscreated("t", props); expect(willNavigateSecuritySpy).toHaveBeenCalled(); diff --git a/starskydesktop/src/main/main.ts b/starskydesktop/src/main/main.ts index d8925dc13b..3049e33a0c 100755 --- a/starskydesktop/src/main/main.ts +++ b/starskydesktop/src/main/main.ts @@ -1,18 +1,18 @@ /* eslint-disable @typescript-eslint/no-floating-promises */ import { app, BrowserWindow } from "electron"; import * as os from "os"; -import { setupChildProcess } from "../app/child-process/setup-child-process"; +import { SetupChildProcess } from "../app/child-process/setup-child-process"; import { MakeLogsPath } from "../app/config/logs-path"; import { MakeTempPath } from "../app/config/temp-path"; import { SetupFileWatcher } from "../app/file-watcher/setup-file-watcher"; import ipcBridge from "../app/ipc-bridge/ipc-bridge"; +import logger from "../app/logger/logger"; import createMainWindow from "../app/main-window/create-main-window"; import AppMenu from "../app/menu/app-menu"; import DockMenu from "../app/menu/dock-menu"; import defaultAppSettings from "../app/startup/app-settings"; import RestoreWarmupMainWindowAndCloseSplash from "../app/startup/restore-warmup-main-window-and-close-splash"; import { willNavigateSecurity } from "../app/startup/will-navigate-security"; -import { IsRemote } from "../app/warmup/is-remote"; import { SetupSplash } from "../app/warmup/splash"; MakeLogsPath(); @@ -23,41 +23,57 @@ SetupFileWatcher(); console.log(`running in: :${os.arch()}`); -setupChildProcess().then((appPort) => { - // This method will be called when Electron has finished - // initialization and is ready to create browser windows. - // Some APIs can only be used after this event occurs. - app.on("ready", () => { - AppMenu(); - DockMenu(); +// This method will be called when Electron has finished +// initialization and is ready to create browser windows. +// Some APIs can only be used after this event occurs. +app.on("ready", () => { + AppMenu(); + DockMenu(); - IsRemote().then(async (isRemote) => { - const splashWindows = await SetupSplash(); - RestoreWarmupMainWindowAndCloseSplash(appPort, splashWindows, isRemote); - }); + logger.info(`app ready`); - app.on("activate", () => { - // On macOS it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (BrowserWindow.getAllWindows().length === 0) { - createMainWindow("?f=/"); - } + SetupChildProcess() + .then(async (appPort) => { + logger.info("done child process"); + const splashWindows = await SetupSplash(); + RestoreWarmupMainWindowAndCloseSplash(appPort, splashWindows).catch(() => { + logger.warn("skldfnksdlnksdlfk"); + throw new Error("retry"); + }); + }) + .catch(() => { + SetupChildProcess() + .then(async (appPort) => { + logger.info("retry 2"); + const splashWindows = await SetupSplash(); + RestoreWarmupMainWindowAndCloseSplash(appPort, splashWindows); + }) + .catch(() => { + logger.warn("sdfdf"); + }); }); - }); - // Quit when all windows are closed, except on macOS. There, it's common - // for applications and their menu bar to stay active until the user quits - // explicitly with Cmd + Q. - app.on("window-all-closed", () => { - if (process.platform !== "darwin") { - app.quit(); + app.on("activate", () => { + // On macOS it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) { + createMainWindow("?f=/"); } }); +}); - // https://github.com/electron/electron/blob/master/docs/tutorial/security.md - app.on("web-contents-created", (_, contents) => { - contents.on("will-navigate", (event, navigationUrl) => { - willNavigateSecurity(event, navigationUrl); - }); +// Quit when all windows are closed, except on macOS. There, it's common +// for applications and their menu bar to stay active until the user quits +// explicitly with Cmd + Q. +app.on("window-all-closed", () => { + if (process.platform !== "darwin") { + app.quit(); + } +}); + +// https://github.com/electron/electron/blob/master/docs/tutorial/security.md +app.on("web-contents-created", (_, contents) => { + contents.on("will-navigate", (event, navigationUrl) => { + willNavigateSecurity(event, navigationUrl); }); }); diff --git a/starskydesktop/webpack.config.mjs b/starskydesktop/webpack.config.mjs index 64a4596fb7..fa55142628 100644 --- a/starskydesktop/webpack.config.mjs +++ b/starskydesktop/webpack.config.mjs @@ -96,18 +96,6 @@ const preloadConfig = merge(commonConfig, { output: { filename: 'preload-main.bundle.js' }, }); -// import HtmlWebpackPlugin from 'html-webpack-plugin'; -// const rendererConfig = merge(commonConfig, { -// entry: './src/renderer/renderer.tsx', -// target: 'electron-renderer', -// output: { filename: 'renderer.bundle.js' }, -// plugins: [ -// new HtmlWebpackPlugin({ -// template: path.resolve(__dirname, './public/index.html'), -// }), -// ], -// }); - const clientConfig = merge(commonConfig, { entry: { 'reload-redirect': "./src/client/script/reload-redirect.ts",