diff --git a/.github/workflows/release-on-tag-netcore-desktop-electron.yml b/.github/workflows/release-on-tag-netcore-desktop-electron.yml index 8ec6d5f257..73902fada9 100644 --- a/.github/workflows/release-on-tag-netcore-desktop-electron.yml +++ b/.github/workflows/release-on-tag-netcore-desktop-electron.yml @@ -11,9 +11,9 @@ on: jobs: - build_core: + build_net: - name: Build Net Core + name: Build .NET runs-on: ubuntu-latest steps: - name: Checkout code @@ -71,10 +71,10 @@ jobs: name: starsky-tools-slack-notification path: ./starsky-tools/slack-notification - build_mac: - name: Update Mac Desktop app + build_mac_x64: + name: Build Mac Desktop app (x64) runs-on: macos-latest - needs: [build_core] + needs: [build_net] steps: - name: Checkout code uses: actions/checkout@v4 @@ -85,7 +85,7 @@ jobs: name: osx-x64 path: ./starsky - - name: Unzip Mac OS bundle + - name: Unzip Mac OS bundle (osx-x64) shell: bash working-directory: ./starsky run: unzip starsky-osx-x64.zip -d osx-x64 @@ -116,18 +116,66 @@ jobs: - name: NpmDist working-directory: ./starskydesktop - run: npm run mac + run: npm run macx64 - name: Upload starsky-mac-x64-desktop as build artifact uses: actions/upload-artifact@v4 with: name: starsky-mac-x64-desktop path: ./starskydesktop/dist-prod/starsky-mac-x64-desktop.dmg + + build_mac_arm64: + name: Build Mac Desktop app (arm64) + runs-on: macos-latest + needs: [build_net] + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download osx-arm64 as build artifact + uses: actions/download-artifact@v4 + with: + name: osx-arm64 + path: ./starsky + + - name: Unzip Mac OS bundle (osx-arm64) + shell: bash + working-directory: ./starsky + run: unzip starsky-osx-arm64.zip -d osx-arm64 + + - name: Restore rights pm2-restore-x-rights.sh (osx-arm64) + shell: bash + working-directory: ./starsky/osx-arm64 + run: chmod 777 pm2-restore-x-rights.sh + + - name: run pm2-restore-x-rights.sh (osx-arm64) + shell: bash + working-directory: ./starsky/osx-arm64 + run: bash pm2-restore-x-rights.sh + + - name: fix release version (release-version-check) + shell: bash + working-directory: ./starsky-tools/build-tools + run: npm run release-version-check + + - name: NpmCi + working-directory: ./starskydesktop + run: npm ci + + - name: NpmDist + working-directory: ./starskydesktop + run: npm run macarm64 + + - name: Upload starsky-mac-arm64-desktop as build artifact + uses: actions/upload-artifact@v4 + with: + name: starsky-mac-arm64-desktop + path: ./starskydesktop/dist-prod/starsky-mac-arm64-desktop.dmg build_win: - name: Update Windows Desktop app + name: Build Windows Desktop app runs-on: windows-latest - needs: [build_core] + needs: [build_net] steps: - name: Checkout code uses: actions/checkout@v4 @@ -169,7 +217,7 @@ jobs: create_release: name: Create Release - needs: [build_core, build_mac, build_win] + needs: [build_net, build_mac_x64, build_mac_arm64, build_win] runs-on: ubuntu-latest permissions: contents: write @@ -192,6 +240,12 @@ jobs: with: name: starsky-mac-x64-desktop path: ./starskydesktop/dist-prod + + - name: Download starsky-mac-arm64-desktop as build artifact + uses: actions/download-artifact@v4 + with: + name: starsky-mac-arm64-desktop + path: ./starskydesktop/dist-prod - name: Download linux-arm as build artifact uses: actions/download-artifact@v4 @@ -246,6 +300,7 @@ jobs: tag_name: ${{ github.ref }} files: | ./starskydesktop/dist-prod/starsky-mac-x64-desktop.dmg + ./starskydesktop/dist-prod/starsky-mac-arm64-desktop.dmg ./starskydesktop/dist-prod/starsky-win-x64-desktop.exe ./starsky/starsky-linux-arm.zip ./starsky/starsky-linux-arm64.zip @@ -258,7 +313,8 @@ jobs: body: | ## Desktop app versions: _When you are not sure pick the Desktop App_ - - starsky-mac-x64-desktop.dmg - __Starsky Desktop App for Mac OS *12.0* or newer (Intel)__ + - starsky-mac-x64-desktop.dmg - __Starsky Desktop App for Intel, Mac OS *12.0* or newer__ + - starsky-mac-arm64-desktop.dmg - __Starsky Desktop App for Apple silicon, Mac OS *12.0* or newer__ - starsky-win-x64-desktop.exe - __Starsky Desktop App for Windows 10 1607+ or Windows 11 22000+ (Intel 64 bits)__ ## Server versions: @@ -318,7 +374,8 @@ jobs: trigger_pipe: runs-on: ubuntu-latest if: ${{ !startsWith(github.ref, 'refs/tags/v') }} - needs: [build_core, build_mac, build_win] + needs: [build_net, build_mac_x64, build_win, build_mac_arm64] + # build_mac_arm64 is not used for end2end tests, but it needs to be done steps: - name: trigger end2end-ubuntu-ci.yml shell: bash diff --git a/pipelines/azure/app-ci.yml b/pipelines/azure/app-ci.yml index 6f79f3031d..21a0bb44ab 100644 --- a/pipelines/azure/app-ci.yml +++ b/pipelines/azure/app-ci.yml @@ -124,3 +124,9 @@ stages: inputs: path: '$(Build.SourcesDirectory)/starskydesktop/dist-prod/starsky-mac-x64-desktop.zip' ArtifactName: 'starsky-mac-x64-desktop' + + - task: PublishPipelineArtifact@1 + displayName: 'Publish Artifact: starsky-mac-arm64-desktop' + inputs: + path: '$(Build.SourcesDirectory)/starskydesktop/dist-prod/starsky-mac-x64-desktop.zip' + ArtifactName: 'starsky-mac-arm64-desktop' \ No newline at end of file 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/package.json b/starskydesktop/package.json index 1d0b2b4b8c..43a5b5f1cf 100644 --- a/starskydesktop/package.json +++ b/starskydesktop/package.json @@ -17,13 +17,14 @@ "test:ci": "npm run jest && npm run lint", "test-ci": "npm run jest && npm run lint", "windows": "npm run prod && electron-builder build --win --publish never", - "mac": "npm run prod && electron-builder build --mac --publish never", + "mac": "npm run prod && electron-builder build --mac --x64 --arm64 --publish never", + "macx64": "npm run prod && electron-builder build --mac --x64 --publish never", "macarm64": "npm run prod && electron-builder build --mac --arm64 true --x64 false --publish never", "macwindows": "npm run prod && echo prod-done && electron-builder build --mac zip --windows --publish never", "linux": "npm run prod && electron-builder build --linux --publish never", "dist": "npm run prod && electron-builder build --publish never", - "build:win": "electron-builder build --win", - "build:mac": "electron-builder build --mac", + "build:win": "electron-builder build --win ", + "build:mac": "electron-builder build --mac --x64 true --arm64 true", "build:runtime": "cd ../starsky && pwsh build.ps1 -runtime osx-arm64,osx-x64,win-x64 -ready-to-run -no-tests", "update": "npx --yes npm-check-updates", "update:install": "npx --yes npm-check-updates -u && npm install", @@ -42,16 +43,16 @@ ], "artifactName": "starsky-${os}-${arch}-desktop.${ext}", "mac": { - "minimumSystemVersion": "10.14", + "minimumSystemVersion": "10.15", "electronLanguages": [ "en", - "nl" + "nl", + "de" ], "icon": "src/setup/icons/baseline-searcher-detective-263238__512px.icns", "target": [ { - "target": "dmg", - "arch": "x64" + "target": "dmg" } ], "publish": [] 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 b3d24ffcf6..a334214955 100644 --- a/starskydesktop/src/app/child-process/setup-child-process.ts +++ b/starskydesktop/src/app/child-process/setup-child-process.ts @@ -4,13 +4,12 @@ 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"; import { electronCacheLocation } from "./electron-cache-location"; - -// eslint-disable-next-line import/no-mutable-exports -export let appPort = 9609; +import { SpawnCleanMacOs } from "./spawn-clean-mac-os"; function spawnChildProcess(appStarskyPath: string) { const starskyChild = spawn(appStarskyPath, { @@ -19,6 +18,10 @@ function spawnChildProcess(appStarskyPath: string) { env: process.env, }); + starskyChild.on("exit", (code) => { + logger.info(`EXIT: CODE: ${code}`); + }); + starskyChild.stdout.on("data", (data: string) => { logger.info(data.toString()); }); @@ -30,7 +33,7 @@ function spawnChildProcess(appStarskyPath: string) { return starskyChild; } -export async function setupChildProcess() { +function CreateFolder() { const thumbnailTempFolder = path.join(electronCacheLocation(), "thumbnailTempFolder"); if (!fs.existsSync(thumbnailTempFolder)) { fs.mkdirSync(thumbnailTempFolder); @@ -40,89 +43,126 @@ export async function setupChildProcess() { if (!fs.existsSync(tempFolder)) { fs.mkdirSync(tempFolder); } + return { + tempFolder, + thumbnailTempFolder, + }; +} - const appSettingsPath = path.join(electronCacheLocation(), "appsettings.json"); +function Env(appPort: number) { const databaseConnection = `Data Source=${path.join(electronCacheLocation(), "starsky.db")}`; + const appSettingsPath = path.join(electronCacheLocation(), "appsettings.json"); + const result = CreateFolder(); - appPort = await GetFreePort(); - - logger.info(`next: port: ${appPort}`); - logger.info(`-appSettingsPath > ${appSettingsPath}`); + // Set Global Helper + (global.shared as SharedSettings).port = appPort; + (global.shared as SharedSettings).remote = false; + (global.shared as SharedSettings).baseUrl = `http://localhost:${appPort}`; - const env = { + return { ASPNETCORE_URLS: `http://localhost:${appPort}`, - app__thumbnailTempFolder: thumbnailTempFolder, - app__tempFolder: tempFolder, + 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", }; - 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("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); +function StartProcess(): Promise { + let retryCount = 0; + + function retryProcess(): Promise { + return new Promise((resolve, reject) => { + if (retryCount < 3) { + retryCount += 1; + console.log(`Retry attempt ${retryCount}`); + StartProcess() + .then((e) => resolve(e)) + .catch(() => { + console.error("Retry failed"); + }); + } else { + console.error("Max retries reached"); + reject(new Error("max retries")); + } }); - }); - - 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") { - kill(); - logger.info("=> (pressed ctrl & c) to the end of starsky"); - setTimeout(() => { - process.exit(0); - }, 400); - } + 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(async () => { + await retryProcess(); + }) + .catch(reject); + }); + + starskyChild.once("spawn", () => { + logger.info("im doing something"); + resolve(appPort); + }); + + 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(); + setTimeout(() => { + process.exit(0); + }, 400); + }); + }) + .catch(reject); }); +} - app.on("before-quit", (event) => { - event.preventDefault(); - logger.info("=> end default"); - kill(); - setTimeout(() => { - process.exit(0); - }, 400); - }); +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 new file mode 100644 index 0000000000..d9d082aded --- /dev/null +++ b/starskydesktop/src/app/child-process/spawn-clean-mac-os.ts @@ -0,0 +1,85 @@ +import { spawn } from "child_process"; +import * as path from "path"; +import logger from "../logger/logger"; + +function executeXattrCommand(appStarskyPath: string): Promise { + return new Promise((resolve, reject) => { + const xattrArgs = ["-rd", "com.apple.quarantine", appStarskyPath]; + const xattrOptions = { + detached: true, + env: process.env, + argv0: "xattr", + }; + + const xattrChild = spawn("xattr", xattrArgs, xattrOptions); + + xattrChild.on("error", (err) => { + logger.info("Error occurred while running xattr command:", err); + reject(err); + }); + + xattrChild.on("exit", (code, signal) => { + if (code === 0) { + logger.info("xattr command completed successfully."); + resolve(); + } else { + logger.info(`xattr command exited with code ${code} and signal ${signal}`); + reject(new Error(`xattr command exited with code ${code} and signal ${signal}`)); + } + }); + }); +} + +function executeCodesignCommand(appStarskyPath: string): Promise { + return new Promise((resolve, reject) => { + const args = [ + "--force", + "--deep", + "-s", + "-", // Assuming this is the identity flag for the signing certificate + appStarskyPath, + ]; + + const options = { + cwd: path.dirname(appStarskyPath), + detached: true, + env: process.env, + argv0: "codesign", + }; + + const codeSignSpawn = spawn("codesign", args, options); + + codeSignSpawn.on("exit", (code) => { + logger.info(`code sign EXIT: CODE: ${code}`); + if (code === 0) { + resolve(); + } else { + reject(new Error(`codesign command exited with code ${code}`)); + } + }); + + codeSignSpawn.stdout.on("data", (data: string) => { + logger.info(data.toString()); + }); + + codeSignSpawn.stderr.on("data", (data: string) => { + logger.warn(data.toString()); + }); + }); +} + +export function SpawnCleanMacOs(appStarskyPath: string, processPlatform: string): Promise { + return new Promise((resolve, reject) => { + if (processPlatform !== "darwin") { + resolve(true); + } + + Promise.all([executeXattrCommand(appStarskyPath), executeCodesignCommand(appStarskyPath)]) + .then(() => { + resolve(true); + }) + .catch((err) => { + reject(err); + }); + }); +} diff --git a/starskydesktop/src/app/config/get-base-url-from-settings.ts b/starskydesktop/src/app/config/get-base-url-from-settings.ts index 2ebd194f14..f842454550 100644 --- a/starskydesktop/src/app/config/get-base-url-from-settings.ts +++ b/starskydesktop/src/app/config/get-base-url-from-settings.ts @@ -1,8 +1,8 @@ import * as appConfig from "electron-settings"; -import { appPort } from "../child-process/setup-child-process"; import { IlocationUrlSettings } from "./IlocationUrlSettings"; import { LocationIsRemoteSettingsKey, + LocationLocalHostSettingsKey, LocationUrlSettingsKey } from "./location-settings.const"; @@ -21,7 +21,7 @@ export async function GetBaseUrlFromSettings(): Promise { const defaultLocalLocation = { isValid: null, isLocal: true, - location: `http://localhost:${appPort}` + location: await appConfig.get(LocationLocalHostSettingsKey) // `http://localhost:${appPort}` } as IlocationUrlSettings; if (isRemote === false) { diff --git a/starskydesktop/src/app/config/location-ipc-keys.const.ts b/starskydesktop/src/app/config/location-ipc-keys.const.ts index 8c9325d03d..0e8431fd54 100644 --- a/starskydesktop/src/app/config/location-ipc-keys.const.ts +++ b/starskydesktop/src/app/config/location-ipc-keys.const.ts @@ -1,2 +1,3 @@ export const LocationUrlIpcKey = `LOCATION_URL`; +export const LocationLocalHostIpcKey = `LOCATION_LOCALHOST`; export const LocationIsRemoteIpcKey = `LOCATION_IS_REMOTE`; diff --git a/starskydesktop/src/app/config/location-settings.const.ts b/starskydesktop/src/app/config/location-settings.const.ts index a553a6b1c2..f019cd9dfc 100644 --- a/starskydesktop/src/app/config/location-settings.const.ts +++ b/starskydesktop/src/app/config/location-settings.const.ts @@ -1,6 +1,7 @@ import { isPackaged } from "../os-info/is-packaged"; import { LocationIsRemoteIpcKey, + LocationLocalHostIpcKey, LocationUrlIpcKey, } from "./location-ipc-keys.const"; @@ -9,6 +10,12 @@ import { */ export const LocationUrlSettingsKey = `${LocationUrlIpcKey}:${isPackaged().toString()}`; +/** + * string + */ +export const LocationLocalHostSettingsKey = `${LocationLocalHostIpcKey}:${isPackaged().toString()}`; + + /** * bool */ 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/file-watcher/setup-file-watcher.ts b/starskydesktop/src/app/file-watcher/setup-file-watcher.ts index d7b8a1e3b3..e82da41ca4 100644 --- a/starskydesktop/src/app/file-watcher/setup-file-watcher.ts +++ b/starskydesktop/src/app/file-watcher/setup-file-watcher.ts @@ -4,8 +4,14 @@ import { GetParentDiskPath } from "../edit-file/get-parent-disk-path"; import logger from "../logger/logger"; import { ActionWhenFileIsChanged } from "./action-when-file-is-changed"; import { FileWatcherObjects } from "./file-watcher.const"; +import { IsRemote } from "../warmup/is-remote"; export async function SetupFileWatcher() { + if (!await IsRemote()) { + logger.info(`[SetupFileWatcher] skipped, is not remote`); + return; + } + FileWatcherObjects.forEach(([watch, path]) => { watch.removeAllListeners(); FileWatcherObjects.delete([watch, path]); 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 b4037c5ff3..a2369492c9 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( @@ -38,21 +39,23 @@ async function createMainWindow(openSpecificUrl: string, offset = 0): Promise
{ + logger.info("ready to show"); newWindow.show(); }); newWindow.webContents.setWindowOpenHandler(({ url }) => { - console.log(url); - + logger.info(`[setWindowOpenHandler] ${url}`); return { action: "allow", overrideBrowserWindowOptions: { @@ -91,7 +94,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.spec.ts b/starskydesktop/src/app/main-window/restore-main-window.spec.ts index c18d0d136c..42a453e980 100644 --- a/starskydesktop/src/app/main-window/restore-main-window.spec.ts +++ b/starskydesktop/src/app/main-window/restore-main-window.spec.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/ban-types */ import * as appConfig from "electron-settings"; import * as createMainWindow from "./create-main-window"; -import { restoreMainWindow } from "./restore-main-window"; +import { RestoreMainWindow } from "./restore-main-window"; jest.mock("electron-settings", () => { return { @@ -60,7 +60,7 @@ describe("restore main window", () => { return Promise.resolve(); }); - await restoreMainWindow(); + await RestoreMainWindow("base"); expect(createMainWindowSpy).toHaveBeenCalled(); expect(createMainWindowSpy).toHaveBeenCalledWith("?f=/", 0); @@ -85,7 +85,7 @@ describe("restore main window", () => { console.log("---!"); - await restoreMainWindow(); + await RestoreMainWindow("base"); expect(createMainWindowSpy).toHaveBeenCalled(); expect(createMainWindowSpy).toHaveBeenCalledWith("url_get", 0); @@ -110,7 +110,7 @@ describe("restore main window", () => { .mockImplementationOnce(() => Promise.resolve() as any) .mockImplementationOnce(() => Promise.resolve() as any); - await restoreMainWindow(); + await RestoreMainWindow("base"); expect(createMainWindowSpy).toHaveBeenCalled(); expect(createMainWindowSpy).toHaveBeenNthCalledWith(1, "url_get0", 0); diff --git a/starskydesktop/src/app/main-window/restore-main-window.ts b/starskydesktop/src/app/main-window/restore-main-window.ts index c193c03784..11574f38e1 100644 --- a/starskydesktop/src/app/main-window/restore-main-window.ts +++ b/starskydesktop/src/app/main-window/restore-main-window.ts @@ -1,34 +1,30 @@ 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(rememberUrls: any) { - let i = 0; - // eslint-disable-next-line no-restricted-syntax, @typescript-eslint/no-unsafe-argument - for (const key of Object.keys(rememberUrls)) { - // eslint-disable-next-line no-await-in-loop, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access - await createMainWindow(rememberUrls[key], i * 20); - // eslint-disable-next-line no-plusplus - 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; } return fallbackConfig; } -export async function restoreMainWindow(): Promise { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment +export async function RestoreMainWindow(baseUrl: string): Promise { const rememberUrls = await getRememberUrl(); - logger.info("[restoreMainWindow] rememberUrls"); + logger.info("[RestoreMainWindow] rememberUrls"); logger.info(rememberUrls); // remove the config and set it when the new windows open, so the id's are matching @@ -38,5 +34,5 @@ export async function restoreMainWindow(): Promise { } catch (error) { // nothing in } - await runCreateWindow(rememberUrls); + await runCreateWindow(baseUrl, 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 87c982cfcc..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 @@ -1,4 +1,4 @@ -import * as restoreMainWindow from "../main-window/restore-main-window"; +import * as RestoreMainWindow from "../main-window/restore-main-window"; import * as WarmupServer from "../warmup/warmup-server"; import * as RestoreWarmupMainWindowAndCloseSplash from "./restore-warmup-main-window-and-close-splash"; @@ -40,11 +40,11 @@ describe("RestoreWarmupMainWindowAndCloseSplash", () => { ]; const restoreMainWindowSpy = jest - .spyOn(restoreMainWindow, "restoreMainWindow") + .spyOn(RestoreMainWindow, "RestoreMainWindow") .mockImplementationOnce(() => Promise.resolve()); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - RestoreWarmupMainWindowAndCloseSplash.default(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") + .spyOn(RestoreMainWindow, "RestoreMainWindow") .mockImplementationOnce(() => Promise.resolve()); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - RestoreWarmupMainWindowAndCloseSplash.default(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 969a4144f0..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,30 +1,49 @@ import { BrowserWindow } from "electron"; -import { appPort } from "../child-process/setup-child-process"; -import { restoreMainWindow } from "../main-window/restore-main-window"; +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"; -export function RestoreMainWindowAndCloseSplash( - splashWindows: BrowserWindow[] -) { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - restoreMainWindow().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( - splashWindows: BrowserWindow[], - isRemote: boolean -) { - if (!isRemote) { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - WarmupServer(appPort).then(() => { - RestoreMainWindowAndCloseSplash(splashWindows); - }); - return; - } - RestoreMainWindowAndCloseSplash(splashWindows); +export default async function RestoreWarmupMainWindowAndCloseSplash( + appPort: number, + 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/startup/will-navigate-security.ts b/starskydesktop/src/app/startup/will-navigate-security.ts index 6f49a33ac9..a97612d1f6 100644 --- a/starskydesktop/src/app/startup/will-navigate-security.ts +++ b/starskydesktop/src/app/startup/will-navigate-security.ts @@ -4,7 +4,7 @@ import { LocationUrlSettingsKey } from "../config/location-settings.const"; export async function willNavigateSecurity( event: Electron.Event, - navigationUrl: string, + navigationUrl: string ): Promise { const parsedUrl = new URL(navigationUrl); @@ -14,13 +14,8 @@ export async function willNavigateSecurity( } // // to allow remote connections - const currentSettings = await appConfig.get(LocationUrlSettingsKey); - if ( - currentSettings - && currentSettings - && currentSettings - && parsedUrl.origin.startsWith(new URL(currentSettings.toString()).origin) - ) { + const currentSettings = (await appConfig.get(LocationUrlSettingsKey)) as string; + if (currentSettings && parsedUrl.origin.startsWith(new URL(currentSettings.toString()).origin)) { return true; } 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/client/script/reload-warmup-local-or-remote.ts b/starskydesktop/src/client/script/reload-warmup-local-or-remote.ts index 3c71275ae4..51f3774b30 100644 --- a/starskydesktop/src/client/script/reload-warmup-local-or-remote.ts +++ b/starskydesktop/src/client/script/reload-warmup-local-or-remote.ts @@ -38,36 +38,44 @@ export function warmupLocalOrRemote() { window.api.receive( LocationUrlIpcKey, (locationData: IlocationUrlSettings) => { - document.title += ` going to ${locationData?.location}`; - warmupScript(locationData.location, 0, 300, (isOk: boolean) => { - if (isOk) { - checkForUpdates(locationData.location, appVersion) - .then(() => redirecter(locationData.location)) - .catch((e) => { - console.log(e); - }); - return; - } - const notFoundWarning = document.querySelectorAll(".not-found-warning"); - if (notFoundWarning && notFoundWarning[0]) { - const preloaderIcon = document.querySelectorAll(".preloader--icon"); - if (preloaderIcon && preloaderIcon[0]) { - preloaderIcon[0].classList.add("hide"); - } - - notFoundWarning[0].classList.add("show"); - notFoundWarning[0].innerHTML = `There was an error loading ${locationData.location}`; - if (!locationData.isLocal) { - notFoundWarning[0].innerHTML += "
This is a remote service"; - } else { - notFoundWarning[0].innerHTML += "
This is a local service"; - } - } else { - // eslint-disable-next-line no-alert - alert(`There was an error loading: ${locationData.location} isLocal:${locationData.isLocal.valueOf.toString()}`); - } - }); + locationUrlKeyReceive(locationData, appVersion) } ); }); } + +function locationUrlKeyReceive(locationData: IlocationUrlSettings, appVersion: string) { + document.title = `Loading Starsky - going to ${locationData?.location}`; + warmupScript(locationData.location, 0, 300, (isOk: boolean) => { + if (isOk) { + checkForUpdates(locationData.location, appVersion) + .then(() => redirecter(locationData.location)) + .catch((e) => { + console.log(e); + }); + return; + } + setErrorMessage(locationData) + }); +} + +function setErrorMessage(locationData: IlocationUrlSettings) { + const notFoundWarning = document.querySelectorAll(".not-found-warning"); + if (notFoundWarning && notFoundWarning[0]) { + const preloaderIcon = document.querySelectorAll(".preloader--icon"); + if (preloaderIcon && preloaderIcon[0]) { + preloaderIcon[0].classList.add("hide"); + } + + notFoundWarning[0].classList.add("show"); + notFoundWarning[0].innerHTML = `There was an error loading ${locationData.location}`; + if (!locationData.isLocal) { + notFoundWarning[0].innerHTML += "
This is a remote service"; + } else { + notFoundWarning[0].innerHTML += "
This is a local service"; + } + } else { + // eslint-disable-next-line no-alert + alert(`There was an error loading: ${locationData.location} isLocal:${locationData.isLocal.valueOf.toString()}`); + } +} \ No newline at end of file diff --git a/starskydesktop/src/main/main.spec.ts b/starskydesktop/src/main/main.spec.ts index 0959025368..d404ffb9cb 100644 --- a/starskydesktop/src/main/main.spec.ts +++ b/starskydesktop/src/main/main.spec.ts @@ -11,7 +11,7 @@ import * as SetupFileWatcher from "../app/file-watcher/setup-file-watcher"; import * as ipcBridge from "../app/ipc-bridge/ipc-bridge"; import * as logger from "../app/logger/logger"; import * as createMainWindow from "../app/main-window/create-main-window"; -import * as restoreMainWindow from "../app/main-window/restore-main-window"; +import * as RestoreMainWindow from "../app/main-window/restore-main-window"; import * as AppMenu from "../app/menu/app-menu"; import * as DockMenu from "../app/menu/dock-menu"; import * as defaultAppSettings from "../app/startup/app-settings"; @@ -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") - .mockImplementationOnce(() => Promise.resolve()); - jest - .spyOn(MakeTempPath, "MakeTempPath") - .mockImplementationOnce(() => "test"); - jest - .spyOn(MakeLogsPath, "MakeLogsPath") - .mockImplementationOnce(() => "test"); + .spyOn(setupChildProcess, "SetupChildProcess") + .mockImplementationOnce(() => Promise.resolve(1)); + 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(), }; }); @@ -149,22 +143,18 @@ describe("main", () => { it("should create main window", () => { jest - .spyOn(restoreMainWindow, "restoreMainWindow") + .spyOn(RestoreMainWindow, "RestoreMainWindow") .mockImplementationOnce(() => Promise.resolve() as any); 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,36 +166,32 @@ 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") + .spyOn(RestoreMainWindow, "RestoreMainWindow") .mockImplementationOnce(() => Promise.resolve() as any); 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,14 +210,12 @@ 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(() => {}); jest - .spyOn(restoreMainWindow, "restoreMainWindow") + .spyOn(RestoreMainWindow, "RestoreMainWindow") .mockReset() .mockImplementationOnce(() => Promise.resolve() as any); @@ -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 ef757d9af7..44648d8751 100755 --- a/starskydesktop/src/main/main.ts +++ b/starskydesktop/src/main/main.ts @@ -1,24 +1,23 @@ /* 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(); ipcBridge(); defaultAppSettings(); -setupChildProcess(); MakeTempPath(); SetupFileWatcher(); @@ -31,9 +30,16 @@ app.on("ready", () => { AppMenu(); DockMenu(); - IsRemote().then(async (isRemote) => { - const splashWindows = await SetupSplash(); - RestoreWarmupMainWindowAndCloseSplash(splashWindows, isRemote); + logger.info(`app ready`); + + SetupSplash().then((splashWindows) => { + SetupChildProcess().then((appPort) => { + logger.info("done child process"); + RestoreWarmupMainWindowAndCloseSplash(appPort, splashWindows).catch(() => { + logger.warn("skldfnksdlnksdlfk"); + throw new Error("retry"); + }); + }); }); app.on("activate", () => { 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",