Fixed default UI load

This commit is contained in:
WolverinDEV 2021-03-22 19:39:28 +01:00
parent c158f2930f
commit 750dbf5d66
1 changed files with 23 additions and 24 deletions

View File

@ -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<string> {
return targetDirectory;
}
async function streamFilesFromDevServer(_channel: string, _callbackStatus: (message: string, index: number) => any) : Promise<string> {
return remoteUiUrl() + "index.html";
}
async function loadBundledUiPack(channel: string, callbackStatus: (message: string, index: number) => any) : Promise<string> {
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<string> {
return remoteUiUrl() + "index.html";
}
async function loadBundledUiPack(channel: string, callbackStatus: (message: string, index: number) => any) : Promise<string> {
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<string> {
callbackStatus("Fetching info", 0);