Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions platform.bible-extension/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import papi, { logger } from '@papi/backend';
import type { ExecutionActivationContext } from '@papi/core';
import { ChildProcessByStdio } from 'child_process';
import type { BrowseWebViewOptions } from 'lexicon';
import os from 'os';
import path from 'path';
import { Stream } from 'stream';
import { EntryService } from './services/entry-service';
import { WebViewType } from './types/enums';
Expand Down Expand Up @@ -241,6 +243,14 @@ export async function deactivate(): Promise<boolean> {
return await shutDownFwLite();
}

/**
* Returns a stable per-user directory for FW Lite data (projects, auth cache).
* Mirrors Platform.Bible's own app:// convention so the path survives extension updates.
*/
function getFwLiteDataDir(): string {
return path.join(os.homedir(), '.platform.bible', 'extensions', 'lexicon');
}

/** Launches the FieldWorks Lite process and returns its URL domain. */
function launchFwLite(context: ExecutionActivationContext): string {
const binaryPath = 'fw-lite/FwLiteWeb.exe';
Expand All @@ -253,6 +263,7 @@ function launchFwLite(context: ExecutionActivationContext): string {
// TODO: Instead of hardcoding the URL and port we should run it and find them in the output.
const baseUrl = 'http://localhost:29348';

const dataDir = getFwLiteDataDir();
fwLiteProcess = context.elevatedPrivileges.createProcess.spawn(
context.executionToken,
binaryPath,
Expand All @@ -263,6 +274,8 @@ function launchFwLite(context: ExecutionActivationContext): string {
'--FwLiteWeb:CorsAllowAny=true',
'--FwLiteWeb:EnableFileLogging=false', // already piped to P.B (and triggers npm watch)
'--FwLiteWeb:OpenBrowser=false',
`--LcmCrdt:ProjectPath=${dataDir}`,
`--Auth:CacheFileName=${path.join(dataDir, 'msal.json')}`,
],
{ stdio: ['pipe', 'pipe', 'pipe'] },
);
Expand Down
Loading