Skip to content

Commit

Permalink
Moved paratext registration to its own extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcouch-sil committed Nov 1, 2024
1 parent 8b6bda9 commit d2bec2c
Show file tree
Hide file tree
Showing 23 changed files with 335 additions and 228 deletions.
4 changes: 2 additions & 2 deletions c-sharp/Users/ParatextRegistrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public async Task InitializeAsync()
{
// Set up commands on the PAPI
await PapiClient.RegisterRequestHandlerAsync(
"command:platformScripture.getParatextRegistrationData",
"command:paratextRegistration.getParatextRegistrationData",
GetParatextRegistrationData
);
await PapiClient.RegisterRequestHandlerAsync(
"command:platformScripture.setParatextRegistrationData",
"command:paratextRegistration.setParatextRegistrationData",
SetParatextRegistrationData
);
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/paratext-registration/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) <year> <copyright_holder_name>
Copyright © 2024 SIL International

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 4 additions & 4 deletions extensions/src/paratext-registration/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# paranext-extension-template
# paratext-registration

Basic extension template for Platform.Bible
Platform.Bible extension that helps users to set up authentication with the Paratext Registry

<!-- <!-- Opening comment tag for Template Info Section. Ignore this for now. More info in [Hide Template Info](#hide-template-info). -->
<!-- Opening comment tag for Template Info Section. Ignore this for now. More info in [Hide Template Info](#hide-template-info).
## Template Info
Expand Down Expand Up @@ -85,7 +85,7 @@ The general file structure is as follows:
- `manifest.json` is the manifest file that defines the extension and important properties for Platform.Bible. It is copied into the build folder
- `src/` contains the source code for the extension
- `src/main.ts` is the main entry file for the extension
- `src/types/paranext-extension-template.d.ts` is this extension's types file that defines how other extensions can use this extension through the `papi`. It is copied into the build folder
- `src/types/paratext-registration.d.ts` is this extension's types file that defines how other extensions can use this extension through the `papi`. It is copied into the build folder
- `*.web-view.tsx` files will be treated as React WebViews
- `*.web-view.html` files are a conventional way to provide HTML WebViews (no special functionality)
- `assets/` contains asset files the extension and its WebViews can retrieve using the `papi-extension:` protocol, as well as textual descriptions in various languages. It is copied into the build folder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Extension template for Platform.Bible. Powered by webpack.

This is a webpack project template pre-configured to build a Platform.Bible extension. It contains the bare minimum of what an extension needs.
Platform.Bible extension that helps users to set up authentication with the Paratext Registry.
4 changes: 2 additions & 2 deletions extensions/src/paratext-registration/assets/displayData.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"supportUrl": "",
"localizedDisplayInfo": {
"en": {
"displayName": "Paranext Extension Template",
"shortSummary": "Base template for a Platform.Bible Extension",
"displayName": "Paratext Registration",
"shortSummary": "Set up authentication with the Paratext Registry.",
"description": "assets/descriptions/description-en.md"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
{
"metadata": {},
"metadata": {
"%paratextRegistration_commit_comment_changing_user%": {
"fallbackKey": "%Paratext.&quot;Before changing registered user&quot;%"
},
"%paratextRegistration_warning_invalid_email%": {
"fallbackKey": "%Paratext.RegistrationForm.cmdOK_Click.&quot;Enter valid email address&quot;%"
}
},
"localizedStrings": {
"en": {}
"en": {
"%mainMenu_openParatextRegistration%": "Paratext Registration Information...",
"%paratextRegistration_alert_updatedRegistration%": "Updated registration information",
"%paratextRegistration_alert_updatedRegistration_description%": "Changes applied! The application will restart in a few seconds.",
"%paratextRegistration_button_saveAndRestart%": "Save and restart",
"%paratextRegistration_commit_comment_changing_user%": "Before changing registered user",
"%paratextRegistration_label_registrationName%": "Registration name",
"%paratextRegistration_label_registrationCode%": "Registration code",
"%paratextRegistration_label_emailAddress%": "Email address",
"%paratextRegistration_warning_invalid_email%": "Please enter a valid email address.",
"%paratextRegistration_warning_invalid_registration%": "This registration code is not correct for this user.",
"%paratextRegistration_webView_title%": "Paratext Registration Information",
"%paratextRegistration_webView_tooltip%": "Enter your Paratext Registration Information into this form.",
"%settings_paratextRegistration_registration_internet_group_label%": "Paratext Registration and Internet Settings",
"%settings_paratextRegistration_registration_internet_group_description%": "Settings related to the user's Paratext Registry connection and some internet access controls",
"%settings_paratextRegistration_shouldShowOnStartup_label%": "Show Paratext Registration Web View on Startup",
"%settings_paratextRegistration_shouldShowOnStartup_description%": "Whether to show the form to enter Paratext Registration information when the application starts if it has not been entered previously."
}
}
}
10 changes: 9 additions & 1 deletion extensions/src/paratext-registration/contributions/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
"mainMenu": {
"columns": {},
"groups": {},
"items": []
"items": [
{
"label": "%mainMenu_openParatextRegistration%",
"localizeNotes": "Application main menu > Help > Paratext Registration Information...",
"group": "platform.helpRegistration",
"order": 1006,
"command": "paratextRegistration.showParatextRegistration"
}
]
},
"defaultWebViewTopMenu": {
"columns": {},
Expand Down
14 changes: 13 additions & 1 deletion extensions/src/paratext-registration/contributions/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
[]
[
{
"label": "%settings_paratextRegistration_registration_internet_group_label%",
"description": "%settings_paratextRegistration_registration_internet_group_description%",
"properties": {
"paratextRegistration.shouldShowOnStartup": {
"label": "%settings_paratextRegistration_shouldShowOnStartup_label%",
"description": "%settings_paratextRegistration_shouldShowOnStartup_description%",
"default": false
}
}
}
]
4 changes: 2 additions & 2 deletions extensions/src/paratext-registration/manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "paranext-extension-template",
"name": "paratextRegistration",
"version": "0.0.1",
"displayData": "assets/displayData.json",
"author": "Paranext",
"license": "MIT",
"main": "src/main.ts",
"extensionDependencies": {},
"elevatedPrivileges": [],
"types": "src/types/paranext-extension-template.d.ts",
"types": "src/types/paratext-registration.d.ts",
"menus": "contributions/menus.json",
"settings": "contributions/settings.json",
"projectSettings": "contributions/projectSettings.json",
Expand Down
12 changes: 6 additions & 6 deletions extensions/src/paratext-registration/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "paranext-extension-template",
"name": "paratext-registration",
"private": true,
"version": "0.0.1",
"main": "src/main.js",
"types": "src/types/paranext-extension-template.d.ts",
"types": "src/types/paratext-registration.d.ts",
"author": "Paranext",
"license": "MIT",
"scripts": {
Expand All @@ -16,7 +16,7 @@
"zip": "zip-build dist release --template '%NAME%_%VERSION%.%EXT%' --override",
"package": "npm run build:production && npm run zip",
"package:debug": "cross-env DEBUG_PROD=true npm run package",
"start:core": "cd ../paranext-core && npm run start",
"start:core": "cd ../../.. && npm run start",
"start": "cross-env MAIN_ARGS=\"--extensions $INIT_CWD/dist\" concurrently \"npm:watch\" \"npm:start:core\"",
"start:production": "cross-env MAIN_ARGS=\"--extensions $INIT_CWD/dist\" concurrently \"npm:watch:production\" \"npm:start:core\"",
"lint": "npm run lint:scripts && npm run lint:styles",
Expand All @@ -32,7 +32,7 @@
},
"dependencies": {
"@sillsdev/scripture": "^2.0.2",
"platform-bible-utils": "file:../paranext-core/lib/platform-bible-utils"
"platform-bible-utils": "file:../../../lib/platform-bible-utils"
},
"devDependencies": {
"@swc/core": "^1.7.35",
Expand Down Expand Up @@ -64,8 +64,8 @@
"eslint-plugin-react-hooks": "^4.6.2",
"glob": "^10.4.5",
"lucide-react": "^0.452.0",
"papi-dts": "file:../paranext-core/lib/papi-dts",
"platform-bible-react": "file:../paranext-core/lib/platform-bible-react",
"papi-dts": "file:../../../lib/papi-dts",
"platform-bible-react": "file:../../../lib/platform-bible-react",
"postcss": "^8.4.47",
"postcss-loader": "^8.1.1",
"prettier": "^3.3.3",
Expand Down
76 changes: 72 additions & 4 deletions extensions/src/paratext-registration/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,78 @@
import { logger } from '@papi/backend';
import papi, { logger } from '@papi/backend';
import { ExecutionActivationContext } from '@papi/core';
import ParatextRegistrationWebViewProvider, {
paratextRegistrationWebViewType,
} from './paratext-registration.web-view-provider';

export async function activate() {
logger.info('Extension template is activating!');
async function showParatextRegistration(): Promise<string | undefined> {
return papi.webViews.getWebView(
paratextRegistrationWebViewType,
{ type: 'float', position: 'center', floatSize: { width: 540, height: 415 } },
{ existingId: '?' },
);
}

/**
* Shows the registration info pane if there isn't any registration info yet. Used to help people
* get signed in at startup
*
* Handles its own errors. No need to await
*/
async function showParatextRegistrationIfNoRegistrationData(): Promise<string | undefined> {
try {
if (!(await papi.settings.get('paratextRegistration.shouldShowOnStartup'))) return undefined;

const registrationData = await papi.commands.sendCommand(
'paratextRegistration.getParatextRegistrationData',
);

if (
registrationData.name ||
registrationData.code ||
registrationData.email ||
registrationData.supporterName
)
return undefined;

return await showParatextRegistration();
} catch (e) {
logger.warn(
`Error while trying to determine if we need to pull up the Paratext registration info web view on startup: ${e}`,
);
}
return undefined;
}

export async function activate(context: ExecutionActivationContext) {
logger.info('Paratext Registration is activating!');

const paratextRegistrationWebViewProvider = new ParatextRegistrationWebViewProvider();

const shouldShowOnStartupValidatorPromise = papi.settings.registerValidator(
'paratextRegistration.shouldShowOnStartup',
async (newValue) => typeof newValue === 'boolean',
);

const showParatextRegistrationPromise = papi.commands.registerCommand(
'paratextRegistration.showParatextRegistration',
showParatextRegistration,
);
const showParatextRegistrationWebViewProviderPromise = papi.webViewProviders.register(
paratextRegistrationWebViewType,
paratextRegistrationWebViewProvider,
);

// No need to wait for this; it will do its thing and handle its own errors
showParatextRegistrationIfNoRegistrationData();

context.registrations.add(
await shouldShowOnStartupValidatorPromise,
await showParatextRegistrationPromise,
await showParatextRegistrationWebViewProviderPromise,
);
}

export async function deactivate() {
logger.info('Extension template is deactivating!');
logger.info('Paratext Registration is deactivating!');
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import papi from '@papi/backend';
import paratextRegistrationListWebView from './paratext-registration.web-view?inline';
import paratextRegistrationListStyles from './tailwind.css?inline';

export const paratextRegistrationWebViewType = 'platformScripture.paratextRegistration';
export const paratextRegistrationWebViewType = 'paratextRegistration.registrationView';

const titleKey = '%paratextRegistration_webView_title%';
const tooltipKey = '%paratextRegistration_webView_tooltip%';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum SaveState {

const REGISTRATION_CODE_LENGTH_WITH_DASHES = 34;
const REGISTRATION_CODE_REGEX_STRING =
'^(?:[a-zA-Z0-9]{6}-[a-zA-Z0-9]{6}-[a-zA-Z0-9]{6}-[a-zA-Z0-9]{6}-[a-zA-Z0-9]{6}|\\*{6}-\\*{6}-\\*{6}-\\*{6}-\\*{6})$';
'^(?:[a-zA-Z0-9]{6}-[a-zA-Z0-9]{6}-[a-zA-Z0-9]{6}-[a-zA-Z0-9]{6}-[a-zA-Z0-9]{6}|\\*\\*\\*\\*\\*\\*-\\*\\*\\*\\*\\*\\*-\\*\\*\\*\\*\\*\\*-\\*\\*\\*\\*\\*\\*-\\*\\*\\*\\*\\*\\*)$';

/** Just a div with some margins to give some space around parts of the web view */
function Section({ children, className }: GenericComponentProps) {
Expand All @@ -48,7 +48,7 @@ function Grid({ children, className }: GenericComponentProps) {
}

async function getRegistrationData() {
return papi.commands.sendCommand('platformScripture.getParatextRegistrationData');
return papi.commands.sendCommand('paratextRegistration.getParatextRegistrationData');
}

async function saveRegistrationInformation(
Expand All @@ -57,7 +57,7 @@ async function saveRegistrationInformation(
email: string,
supporter: string,
) {
return papi.commands.sendCommand('platformScripture.setParatextRegistrationData', {
return papi.commands.sendCommand('paratextRegistration.setParatextRegistrationData', {
name,
code: registrationCode,
email,
Expand Down Expand Up @@ -87,8 +87,7 @@ globalThis.webViewComponent = function ParatextRegistration({ useWebViewState }:
const [localizedStrings] = useLocalizedStrings(LOCALIZED_STRING_KEYS);

const [name, setName] = useWebViewState('name', '');
// Not using web view state for code to avoid accidental leakages
const [registrationCode, setRegistrationCode] = useState('******-******-******-******-******');
const [registrationCode, setRegistrationCode] = useWebViewState('registrationCode', '');
const [email, setEmail] = useWebViewState('email', '');
const [supporter, setSupporter] = useWebViewState('supporter', '');

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
declare module 'paratext-registration' {
/**
* Paratext registry user information as used in `ParatextData.dll`
*
* Equivalent to C# `RegistrationData`
*/
export type RegistrationData = {
/** Registration name */
name: string;
/** Registration code */
code: string;
/** Email address of the user if any */
email: string;
/** Name of the user's supporter if any */
supporterName: string;
};
}

declare module 'papi-shared-types' {
import type { RegistrationData } from 'paratext-registration';

export interface CommandHandlers {
/**
* Show the Paratext Registration window with which the user can connect to the Paratext
* Registry
*
* @returns Id of the registration web view
*/
'paratextRegistration.showParatextRegistration': () => Promise<string | undefined>;
/**
* Gets information about user's current Paratext Registry user information in
* `ParatextData.dll`
*/
'paratextRegistration.getParatextRegistrationData': () => Promise<RegistrationData>;
/**
* Sets information about user's current Paratext Registry user information in
* `ParatextData.dll` and restarts the application.
*
* @returns If successfully changed registration data
* @throws If did not successfully change registration data
*/
'paratextRegistration.setParatextRegistrationData': (
newRegistrationData: RegistrationData,
) => Promise<void>;
}

export interface SettingTypes {
/**
* Whether to show the form to enter Paratext Registration information when the application
* starts if it has not been entered previously
*/
'paratextRegistration.shouldShowOnStartup': boolean;
}
}
Loading

0 comments on commit d2bec2c

Please sign in to comment.