-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved paratext registration to its own extension
- Loading branch information
1 parent
8b6bda9
commit d2bec2c
Showing
23 changed files
with
335 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
extensions/src/paratext-registration/assets/descriptions/description-en.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 26 additions & 2 deletions
28
extensions/src/paratext-registration/contributions/localizedStrings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
{ | ||
"metadata": {}, | ||
"metadata": { | ||
"%paratextRegistration_commit_comment_changing_user%": { | ||
"fallbackKey": "%Paratext."Before changing registered user"%" | ||
}, | ||
"%paratextRegistration_warning_invalid_email%": { | ||
"fallbackKey": "%Paratext.RegistrationForm.cmdOK_Click."Enter valid email address"%" | ||
} | ||
}, | ||
"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." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 13 additions & 1 deletion
14
extensions/src/paratext-registration/contributions/settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
extensions/src/paratext-registration/src/types/paranext-extension-template.d.ts
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
extensions/src/paratext-registration/src/types/paratext-registration.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.