Skip to content

Commit

Permalink
Move all of the test webviews and commands behind an env var
Browse files Browse the repository at this point in the history
  • Loading branch information
lyonsil committed May 2, 2024
1 parent 7d3bf42 commit 0114b53
Show file tree
Hide file tree
Showing 29 changed files with 443 additions and 523 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"skipFiles": ["<node_internals>/**"],
"env": {
"MAIN_ARGS": "--inspect=5858 --remote-debugging-port=9223",
"IN_VSCODE": "true"
"IN_VSCODE": "true",
"DEV_NOISY": "false"
}
},
{
Expand Down
25 changes: 15 additions & 10 deletions c-sharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,27 @@ public static async Task Main()
return;
}

var tdp = new TimeDataProvider(papi);
var sdp = new UsfmDataProvider(papi, "assets", "WEB");
var paratextProjects = new LocalParatextProjects();
var paratextFactory = new ParatextProjectDataProviderFactory(papi, paratextProjects);

// Higher priority tasks
await Task.WhenAll(sdp.RegisterDataProvider(), paratextFactory.Initialize());

// Lower priority tasks
await Task.WhenAll(
tdp.RegisterDataProvider(),
//TODO: Delete this once we stop including test objects in the builds
papi.RegisterRequestHandler("command:test.addOne", RequestAddOne)
);
// Things that only run in our "noisy dev mode" go here
var noisyDevModeEnvVar = Environment.GetEnvironmentVariable("DEV_NOISY");
var isNoisyDevMode = noisyDevModeEnvVar != null && noisyDevModeEnvVar == "true";
if (isNoisyDevMode)
{
var tdp = new TimeDataProvider(papi);
await Task.WhenAll(
tdp.RegisterDataProvider(),
//TODO: Delete this once we stop including test objects in the builds
papi.RegisterRequestHandler("command:test.addOne", RequestAddOne)
);
}

Console.WriteLine("Paranext data provider ready!");
Console.WriteLine(
$"Paranext data provider ready! {(isNoisyDevMode ? " (noisy dev mode)" : "")}"
);
await papi.MessageHandlingCompleteTask;
Console.WriteLine("Paranext data provider message handling complete");
}
Expand Down
7 changes: 2 additions & 5 deletions extensions/src/hello-someone/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "hello-someone",
"name": "helloSomeone",
"version": "0.0.1",
"description": "Simple hello someone extension for Platform.Bible",
"author": "Paranext",
Expand All @@ -10,8 +10,5 @@
"settings": "contributions/settings.json",
"projectSettings": "contributions/projectSettings.json",
"localizedStrings": "contributions/localizedStrings.json",
"activationEvents": [
"onCommand:helloSomeone.helloSomeone",
"onCommand:helloSomeone.echoSomeoneRenderer"
]
"activationEvents": ["onCommand:helloSomeone.helloSomeone"]
}
13 changes: 0 additions & 13 deletions extensions/src/hello-someone/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,6 @@ export async function activate(context: ExecutionActivationContext): Promise<voi
},
);

const echoSomeoneRendererPromise = papi.commands.registerCommand(
'helloSomeone.echoSomeoneRenderer',
async (message: string) => {
return `echoSomeoneRenderer: ${await papi.commands.sendCommand(
'test.addThree',
2,
4,
6,
)}! ${message}`;
},
);

// Create a webview or get the existing webview if ours already exists
// Note: here, we are storing a created webview's id when we create it, and using that id on
// `existingId` to look specifically for the webview that we previously created if we have ever
Expand Down Expand Up @@ -355,7 +343,6 @@ export async function activate(context: ExecutionActivationContext): Promise<voi
await peopleWebViewProviderPromise,
await emotionTestWebViewProviderPromise,
await helloSomeoneCommandPromise,
await echoSomeoneRendererPromise,
papi.webViews.onDidAddWebView((addWebViewEvent) => {
if (addWebViewEvent.webView.webViewType === peopleWebViewType)
logger.info(
Expand Down
1 change: 0 additions & 1 deletion extensions/src/hello-someone/src/types/hello-someone.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ declare module 'papi-shared-types' {

export interface CommandHandlers {
'helloSomeone.helloSomeone': (name: string) => string;
'helloSomeone.echoSomeoneRenderer': (message: string) => Promise<string>;
}

export interface DataProviders {
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/hello-world/contributions/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"label": "%settings_hello_world_group1_label%",
"properties": {
"hello-world.personName": {
"helloWorld.personName": {
"label": "%settings_hello_world_personName_label%",
"default": "Bill"
}
Expand Down
4 changes: 2 additions & 2 deletions extensions/src/hello-world/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const reactWebViewProvider: IWebViewProviderWithType = {
`${this.webViewType} provider received request to provide a ${savedWebView.webViewType} web view`,
);
return {
iconUrl: 'papi-extension://hello-world/assets/offline.svg',
iconUrl: 'papi-extension://helloWorld/assets/offline.svg',
title: 'Hello World React',
...savedWebView,
content: helloWorldReactWebView,
Expand Down Expand Up @@ -191,7 +191,7 @@ export async function activate(context: ExecutionActivationContext): Promise<voi
);

const helloWorldPersonNamePromise = papi.settings.registerValidator(
'hello-world.personName',
'helloWorld.personName',
async (newValue) => typeof newValue === 'string',
);

Expand Down
2 changes: 1 addition & 1 deletion extensions/src/hello-world/src/types/hello-world.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ declare module 'papi-shared-types' {

export interface SettingTypes {
/** Selected Person's Name on Hello World Web View */
'hello-world.personName': string;
'helloWorld.personName': string;
}
}
34 changes: 2 additions & 32 deletions extensions/src/hello-world/src/web-views/hello-world.web-view.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<style>
Expand All @@ -10,14 +10,12 @@
<body>
<div class="title">Hello World!!</div>
<div><button id="hello-world" type="button">Hello World 0</button></div>
<div><button id="echo-renderer" type="button">Echo Renderer</button></div>
<div id="echo-renderer-output"></div>
<div><button id="hello-someone" type="button">Hello Someone</button></div>
<div id="hello-someone-output"></div>
<div id="root"></div>
<!-- Test the papi-extension protocol in a webView -->
<img
src="papi-extension://quick-verse/assets/letter-q.png"
src="papi-extension://quickVerse/assets/letter-q.png"
alt="Q icon"
style="max-height: 25px; max-width: 25px"
/>
Expand All @@ -44,14 +42,6 @@
useCallback(({ times }) => setClicks(times), []),
);

const [echoResult] = usePromise(
useCallback(async () => {
await new Promise((resolve) => setTimeout(() => resolve(), 3000));
return papi.commands.sendCommand('test.echoRenderer', `From ${NAME}`);
}, []),
'retrieving',
);

return createElement(
'div',
null,
Expand All @@ -71,7 +61,6 @@
clicks,
),
),
createElement('div', null, echoResult),
);
}

Expand Down Expand Up @@ -102,25 +91,6 @@
updateHelloWorldClicks(helloWorldClicks + 1);
});

// Attach handler for echo-renderer
const echoRendererButton = document.getElementById('echo-renderer');
echoRendererButton.addEventListener('click', () =>
papi.commands
.sendCommand('test.echoRenderer', 'From Hello World WebView')
.then((message) => {
const echoRendererOutput = document.getElementById('echo-renderer-output');
echoRendererOutput.textContent = papi.utils.htmlEncode(message);
print(message);
}),
);
echoRendererButton.addEventListener('contextmenu', (e) => {
e.preventDefault();
const promises = new Array(10000);
for (let i = 0; i < 10000; i += 1)
promises[i] = papi.commands.sendCommand('echoRenderer', 'From Hello World WebView');
Promise.all(promises).then(() => print('Done'));
});

// Attach handler for hello-someone
const helloSomeoneButton = document.getElementById('hello-someone');
helloSomeoneButton.addEventListener('click', () =>
Expand Down
19 changes: 4 additions & 15 deletions extensions/src/hello-world/src/web-views/hello-world.web-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ globalThis.webViewComponent = function HelloWorld({
updateWebViewDefinition({ title: `Hello World ${clicks}` });
}, [getWebViewDefinitionUpdatableProperties, updateWebViewDefinition, clicks]);

const [echoResult] = usePromise(
useCallback(async () => {
// Not using the promise's resolved value
// eslint-disable-next-line no-promise-executor-return
await new Promise<void>((resolve) => setTimeout(() => resolve(), 3000));
return papi.commands.sendCommand('test.echoRenderer', `From ${NAME}`);
}, []),
'retrieving',
);

const [project, setProject] = useWebViewState<string>('project', '');

const currentRender = useRef(-1);
Expand All @@ -110,7 +100,7 @@ globalThis.webViewComponent = function HelloWorld({
// testing below to make sure `useDialogCallback` returns the same callback every time
{
prompt: `Please select a Scripture project for Hello World WebView: (Render ${currentRender.current})`,
iconUrl: 'papi-extension://hello-world/assets/offline.svg',
iconUrl: 'papi-extension://helloWorld/assets/offline.svg',
title: 'Select Hello World Project',
maximumOpenDialogs: 2,
// Test ref parameter properly getting latest value
Expand Down Expand Up @@ -158,7 +148,7 @@ globalThis.webViewComponent = function HelloWorld({
useMemo(
() => ({
prompt: 'Please select one or more Scripture projects for Hello World WebView:',
iconUrl: 'papi-extension://hello-world/assets/offline.svg',
iconUrl: 'papi-extension://helloWorld/assets/offline.svg',
title: 'Select List of Hello World Projects',
selectedProjectIds: projects,
includeProjectTypes: '^ParatextStandard$',
Expand All @@ -173,7 +163,7 @@ globalThis.webViewComponent = function HelloWorld({
),
);

const [name, setNameInternal] = useSetting('hello-world.personName', 'Kathy');
const [name, setNameInternal] = useSetting('helloWorld.personName', 'Kathy');

// Name used for display and editing in the input field while debouncing the actual setting change
const [nameTemp, setNameTemp] = useState(name);
Expand Down Expand Up @@ -222,7 +212,7 @@ globalThis.webViewComponent = function HelloWorld({
const [localizedString] = usePromise(
useCallback(() => {
return papi.localization.getLocalizedString({
localizeKey: 'submitButton',
localizeKey: '%submitButton%',
locales: ['fr', 'en'],
});
}, []),
Expand Down Expand Up @@ -253,7 +243,6 @@ globalThis.webViewComponent = function HelloWorld({
Hello World {clicks}
</Button>
</div>
<div>{echoResult}</div>
<div>
<Button
onClick={() => {
Expand Down
28 changes: 19 additions & 9 deletions lib/papi-dts/papi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ declare module 'shared/global-this.model' {
* ```
*/
var updateWebViewDefinition: UpdateWebViewDefinition;
/** Indicates whether test code meant just for developers to see should be run */
var isNoisyDevModeEnabled: boolean;
}
/** Type of Paranext process */
export enum ProcessType {
Expand Down Expand Up @@ -2242,7 +2244,6 @@ declare module 'papi-shared-types' {
*/
interface CommandHandlers {
'test.echo': (message: string) => string;
'test.echoRenderer': (message: string) => Promise<string>;
'test.echoExtensionHost': (message: string) => Promise<string>;
'test.throwError': (message: string) => void;
'platform.restartExtensionHost': () => Promise<void>;
Expand Down Expand Up @@ -2591,14 +2592,6 @@ declare module 'papi-shared-types' {
declare module 'shared/services/command.service' {
import { UnsubscriberAsync } from 'platform-bible-utils';
import { CommandHandlers, CommandNames } from 'papi-shared-types';
module 'papi-shared-types' {
interface CommandHandlers {
'test.addThree': typeof addThree;
'test.squareAndConcat': typeof squareAndConcat;
}
}
function addThree(a: number, b: number, c: number): Promise<number>;
function squareAndConcat(a: number, b: string): Promise<string>;
/** Sets up the CommandService. Only runs once and always returns the same promise after that */
export const initialize: () => Promise<void>;
/** Send a command to the backend. */
Expand Down Expand Up @@ -4459,6 +4452,12 @@ declare module 'node/utils/util' {
* @returns One uri that combines the uri and the paths in left-to-right order
*/
export function joinUriPaths(uri: Uri, ...paths: string[]): Uri;
/**
* Determines if running in noisy dev mode
*
* @returns True if the process is running in noisy dev mode, false otherwise
*/
export const isNoisyDevModeEnvVariableSet: () => boolean;
}
declare module 'node/services/node-file-system.service' {
/** File system calls from Node */
Expand Down Expand Up @@ -5650,6 +5649,7 @@ declare module '@papi/frontend' {
* WARNING: DO NOT IMPORT papi IN ANY FILE THAT papi IMPORTS AND EXPOSES.
*/
import * as commandService from 'shared/services/command.service';
import * as papiUtil from 'platform-bible-utils';
import { PapiNetworkService } from 'shared/services/network.service';
import { WebViewServiceType } from 'shared/services/web-view.service-model';
import { InternetService } from 'shared/services/internet.service';
Expand Down Expand Up @@ -5687,6 +5687,11 @@ declare module '@papi/frontend' {
* other services and extensions that have registered commands.
*/
commands: typeof commandService;
/**
*
* Miscellaneous utility functions and classes
*/
utils: typeof papiUtil;
/**
*
* Service exposing various functions related to using webViews
Expand Down Expand Up @@ -5774,6 +5779,11 @@ declare module '@papi/frontend' {
* other services and extensions that have registered commands.
*/
export const commands: typeof commandService;
/**
*
* Miscellaneous utility functions and classes
*/
export const utils: typeof papiUtil;
/**
*
* Service exposing various functions related to using webViews
Expand Down
1 change: 0 additions & 1 deletion src/declarations/papi-shared-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ declare module 'papi-shared-types' {
// These commands are provided in `main.ts`. They are only here because I needed them to use in
// other places, but building `papi-dts` wasn't working because it didn't see `main.ts`
'test.echo': (message: string) => string;
'test.echoRenderer': (message: string) => Promise<string>;
'test.echoExtensionHost': (message: string) => Promise<string>;
'test.throwError': (message: string) => void;
'platform.restartExtensionHost': () => Promise<void>;
Expand Down
Loading

0 comments on commit 0114b53

Please sign in to comment.