Skip to content

Commit 5a68e7b

Browse files
committed
feat: Add build time browser mode configuration to package.json
refactor: Stripped out unused 'installed' flag
1 parent a81f8c6 commit 5a68e7b

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

gulpfile.mjs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const config = {
2020
buildVersion: Date.now().toString(),
2121
publish: !!process.env.PUBLISH,
2222
isRelease: process.env.NODE_ENV === 'production',
23-
isStaticInstall: packageJson.config.installed,
23+
browserBackendHost: packageJson.config.browserBackendHost || 'ws://localhost:12001/',
24+
isBrowserBackendRemote: !!packageJson.config.isBrowserBackendRemote,
2425
static: {
2526
src: './static',
2627
dest: './build',
@@ -340,7 +341,7 @@ function configVersion(done) {
340341

341342
/* ----- Version ---- */
342343

343-
function createVersionFile(done) {
344+
function updateConstants(done) {
344345
// Get the current date
345346
const currentDate = new Date();
346347

@@ -362,6 +363,22 @@ function createVersionFile(done) {
362363
const data = `export const VERSION = '${formattedDate} (${gitCommitHash})';
363364
export const VERSION_EPOCH = ${Date.now()};
364365
export const FPA_VERSION = '${fpaVersion}';
366+
export const IS_BROWSER_BACKEND_REMOTE = ${config.isBrowserBackendRemote};
367+
export const BROWSER_ISDEV = ${!config.isRelease};
368+
export const getBrowserBackendHost = () => {
369+
const host = '${config.browserBackendHost}';
370+
if (host.startsWith('ws:') || host.startsWith('wss:/')) {
371+
return host;
372+
} else {
373+
// Convert relative path to absolute WebSocket URL
374+
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
375+
const hostname = window.location.hostname;
376+
const port = window.location.port;
377+
const portSuffix = port ? ':' + port : '';
378+
const basePath = host.startsWith('/') ? host : '/' + host;
379+
return protocol + '//' + hostname + portSuffix + basePath;
380+
}
381+
};
365382
`;
366383

367384
// Write to src/shared/version.ts
@@ -483,7 +500,7 @@ async function extractTarball(inputFilePath, outputDirectory) {
483500
export const clean = series(cleanTask);
484501
export const build = series(
485502
cleanTask,
486-
createVersionFile,
503+
updateConstants,
487504
installCrossDeps,
488505
buildStatic,
489506
parallel(
@@ -497,7 +514,7 @@ export const build = series(
497514
);
498515
export const watch = series(
499516
cleanTask,
500-
createVersionFile,
517+
updateConstants,
501518
installCrossDeps,
502519
buildStatic,
503520
parallel(
@@ -511,7 +528,7 @@ export const watch = series(
511528
);
512529
export const watchStatic = series(
513530
cleanTask,
514-
createVersionFile,
531+
updateConstants,
515532
installCrossDeps,
516533
buildStatic,
517534
buildExtensions,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "A desktop application used to browse, manage and play games from Flashpoint Archive",
55
"main": "build/main/electron.js",
66
"config": {
7-
"installed": false
7+
"browserBackendHost": "ws://localhost:12001/",
8+
"isBrowserBackendRemote": false
89
},
910
"scripts": {
1011
"start": "electron ./build/main/electron.js",

src/main/Main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ export function main(init: Init): void {
492492
const url = argv.find((arg) => arg.startsWith('flashpoint://'));
493493
const data: InitRendererData = {
494494
isBackRemote: !!init.args['connect-remote'],
495-
installed: !!state._installed,
496495
host: state.backHost.href,
496+
isDev: Util.isDev,
497497
url
498498
};
499499
event.returnValue = data;

src/renderer/components/AppLoader.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const onInit = async (data: InitRendererData, dispatch: AppDispatch) => {
3737
window.Shared.isBackRemote = data.isBackRemote;
3838
window.Shared.backUrl = new URL(data.host);
3939
window.Shared.url = data.url;
40+
window.Shared.isDev = data.isDev;
4041

4142
// Register connection listener
4243
let startTime: number = 0;
@@ -152,7 +153,7 @@ window.Shared = {
152153
offset: 0,
153154
},
154155

155-
isDev: true, // TODO: fix
156+
isDev: false,
156157

157158
isBackRemote: createErrorProxy('isBackRemote'),
158159

src/renderer/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { MergeComponents } from '@mdx-js/react/lib';
33
import { init } from '@module-federation/enhanced/runtime';
44
import store from '@renderer/store/store';
55
import { InitRendererData } from '@shared/IPC';
6+
import { BROWSER_ISDEV, getBrowserBackendHost, IS_BROWSER_BACKEND_REMOTE } from '@shared/version';
67
import React from 'react';
78
import ReactDOM from 'react-dom';
89
import { createRoot } from 'react-dom/client';
@@ -43,9 +44,9 @@ import { ProgressContext } from './context/ProgressContext';
4344
const data: InitRendererData = window.electronAPI ?
4445
window.electronAPI.getInitData() :
4546
{
46-
isBackRemote: false,
47-
installed: false,
48-
host: 'ws://localhost:12001/'
47+
isDev: BROWSER_ISDEV,
48+
host: getBrowserBackendHost(),
49+
isBackRemote: IS_BROWSER_BACKEND_REMOTE,
4950
};
5051

5152
const container = document.getElementById('root')!;

src/shared/IPC.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const InitRendererChannel = 'renderer-init';
44
/** Message contents for the "initialize renderer" message. */
55
export type InitRendererData = {
66
isBackRemote: boolean;
7-
installed: boolean;
7+
isDev: boolean;
88
host: string;
99
url?: string;
1010
}

0 commit comments

Comments
 (0)