From e16a489b345ece2ae5772ae0a33b87a8092d9308 Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 8 Mar 2024 18:48:23 +0100 Subject: [PATCH] WIP --- .../app/child-process/setup-child-process.ts | 3 +- .../file-selector-window.spec.ts | 84 ------------------- .../file-selector-window.ts | 41 --------- .../src/app/main-window/create-main-window.ts | 14 ++-- 4 files changed, 10 insertions(+), 132 deletions(-) delete mode 100644 starskydesktop/src/app/file-selector-window/file-selector-window.spec.ts delete mode 100644 starskydesktop/src/app/file-selector-window/file-selector-window.ts diff --git a/starskydesktop/src/app/child-process/setup-child-process.ts b/starskydesktop/src/app/child-process/setup-child-process.ts index e72220aca1..a334214955 100644 --- a/starskydesktop/src/app/child-process/setup-child-process.ts +++ b/starskydesktop/src/app/child-process/setup-child-process.ts @@ -118,7 +118,8 @@ function StartProcess(): Promise { .catch(reject); }); - starskyChild.stdout.on("data", () => { + starskyChild.once("spawn", () => { + logger.info("im doing something"); resolve(appPort); }); diff --git a/starskydesktop/src/app/file-selector-window/file-selector-window.spec.ts b/starskydesktop/src/app/file-selector-window/file-selector-window.spec.ts deleted file mode 100644 index 7572a4d706..0000000000 --- a/starskydesktop/src/app/file-selector-window/file-selector-window.spec.ts +++ /dev/null @@ -1,84 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { BrowserWindow, dialog } from "electron"; -import { fileSelectorWindow } from "./file-selector-window"; - -jest.mock("electron-settings", () => { - return { - get: () => "data", - __esModule: true, - }; -}); - -jest.mock('electron', () => { - return { - // eslint-disable-next-line object-shorthand, func-names - BrowserWindow: function (_:object) { - return { - setMenu(_2:object) { - }, - close() { - return jest.fn(); - }, - }; - }, - dialog: { - showOpenDialog(_4:object, _5: object) { - return Promise.resolve({ - canceled: false, - filePaths: ["test"], - }); - }, - }, - }; -}); - -describe("create main window", () => { - it("test mock", () => { - const result = new BrowserWindow({}); - result.setMenu(null); - expect(result).toBeDefined(); - }); - - it("test mock 2", async () => { - const result = await dialog.showOpenDialog({} as BrowserWindow, {}); - expect(result).toBeDefined(); - }); - - it("create a new window", async () => { - const result = await fileSelectorWindow(); - - expect(result).toBeDefined(); - }); - - it("canceled", async () => { - jest - .spyOn(dialog, "showOpenDialog") - .mockImplementationOnce(() => Promise.resolve({ canceled: true, filePaths: [""] })); - - let error : string; - try { - await fileSelectorWindow(); - } catch (err : unknown) { - error = err as string; - } - - expect(error).toBe("canceled"); - }); - - it("rejected by openFile", async () => { - jest - .spyOn(dialog, "showOpenDialog") - // eslint-disable-next-line prefer-promise-reject-errors - .mockImplementationOnce(() => Promise.reject("reason_rejected")); - - let error; - try { - await fileSelectorWindow(); - } catch (err: unknown) { - error = err as string; - } - - expect(error).toBe("reason_rejected"); - }); -}); diff --git a/starskydesktop/src/app/file-selector-window/file-selector-window.ts b/starskydesktop/src/app/file-selector-window/file-selector-window.ts deleted file mode 100644 index 57cb65e128..0000000000 --- a/starskydesktop/src/app/file-selector-window/file-selector-window.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { BrowserWindow, dialog } from "electron"; - -export async function fileSelectorWindow(): Promise { - return new Promise((resolve, reject) => { - const newOpenedWindow = new BrowserWindow({ - height: 40, - width: 500, - title: "Open File", - resizable: false, - fullscreen: false, - backgroundColor: "#ccc", - webPreferences: { - devTools: false, - contextIsolation: true, - }, - }); - - // for windows - newOpenedWindow.setMenu(null); - - const selected = dialog.showOpenDialog(newOpenedWindow, { - properties: ["openFile"], - }); - - selected - .then((data) => { - if (data.canceled) { - newOpenedWindow.close(); - // eslint-disable-next-line prefer-promise-reject-errors - reject("canceled"); - return; - } - resolve(data.filePaths); - newOpenedWindow.close(); - }) - .catch((e) => { - newOpenedWindow.close(); - reject(e); - }); - }); -} diff --git a/starskydesktop/src/app/main-window/create-main-window.ts b/starskydesktop/src/app/main-window/create-main-window.ts index 5e55bbcf0c..a2369492c9 100644 --- a/starskydesktop/src/app/main-window/create-main-window.ts +++ b/starskydesktop/src/app/main-window/create-main-window.ts @@ -25,7 +25,7 @@ async function CreateMainWindow(openSpecificUrl: string, offset = 0): Promise
{ + logger.info("ready to show"); newWindow.show(); });