From 750dbf5d668297b25b66347cb0b6f34785c2fcbe Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Mon, 22 Mar 2021 19:39:28 +0100 Subject: [PATCH] Fixed default UI load --- modules/core/ui-loader/Loader.ts | 47 ++++++++++++++++---------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/modules/core/ui-loader/Loader.ts b/modules/core/ui-loader/Loader.ts index 708564e..958b4df 100644 --- a/modules/core/ui-loader/Loader.ts +++ b/modules/core/ui-loader/Loader.ts @@ -15,8 +15,7 @@ import {localUiCache, saveLocalUiCache} from "./Cache"; import {shippedClientUi} from "./Shipped"; import {downloadUiPack, queryRemoteUiPacks} from "./Remote"; import * as url from "url"; -import {protocol, session} from "electron"; -import {kWindowPartitionMainApp} from "../windows/main-window/controller/MainWindow"; +import {protocol} from "electron"; const kUiPackProtocol = "shared-ui"; @@ -127,31 +126,10 @@ async function unpackLocalUiPack(version: CachedUIPack) : Promise { return targetDirectory; } -async function streamFilesFromDevServer(_channel: string, _callbackStatus: (message: string, index: number) => any) : Promise { - return remoteUiUrl() + "index.html"; -} - -async function loadBundledUiPack(channel: string, callbackStatus: (message: string, index: number) => any) : Promise { - callbackStatus("Query local UI pack info", .33); - - const bundledUi = await shippedClientUi(); - if(!bundledUi) { - throw "client has no bundled UI pack"; - } - - callbackStatus("Unpacking bundled UI", .66); - const result = await unpackLocalUiPack(bundledUi); - - callbackStatus("Local UI pack loaded", 1); - console.log("Loaded bundles UI pack successfully. Version: {timestamp: %d, hash: %s}", bundledUi.packInfo.timestamp, bundledUi.packInfo.versions_hash); - return url.pathToFileURL(path.join(result, "index.html")).toString(); -} - function initializeFileSystemProtocol(directory: string) { directory = path.normalize(directory); - const sessionProtocol = session.fromPartition(kWindowPartitionMainApp).protocol; - sessionProtocol.registerFileProtocol(kUiPackProtocol, (request, callback) => { + protocol.registerFileProtocol(kUiPackProtocol, (request, callback) => { let targetPath; const pathStartIndex = request.url.indexOf('/', kUiPackProtocol.length + 3); if(pathStartIndex === -1) { @@ -173,6 +151,27 @@ function initializeFileSystemProtocol(directory: string) { }); } +async function streamFilesFromDevServer(_channel: string, _callbackStatus: (message: string, index: number) => any) : Promise { + return remoteUiUrl() + "index.html"; +} + +async function loadBundledUiPack(channel: string, callbackStatus: (message: string, index: number) => any) : Promise { + callbackStatus("Query local UI pack info", .33); + + const bundledUi = await shippedClientUi(); + if(!bundledUi) { + throw "client has no bundled UI pack"; + } + + callbackStatus("Unpacking bundled UI", .66); + const result = await unpackLocalUiPack(bundledUi); + + callbackStatus("Local UI pack loaded", 1); + console.log("Loaded bundles UI pack successfully. Version: {timestamp: %d, hash: %s}", bundledUi.packInfo.timestamp, bundledUi.packInfo.versions_hash); + initializeFileSystemProtocol(result); + return kUiPackProtocol + "://shared-ui/index.html"; +} + async function loadCachedOrRemoteUiPack(channel: string, callbackStatus: (message: string, index: number) => any, ignoreNewVersionTimestamp: boolean) : Promise { callbackStatus("Fetching info", 0);