refactor: application dependency management (#2363)
This commit is contained in:
@@ -31,7 +31,7 @@ const ChangeEmail: FunctionComponent<Props> = ({ onCloseDialog, application }) =
|
||||
|
||||
useBeforeUnload()
|
||||
|
||||
const applicationAlertService = application.alertService
|
||||
const applicationAlertService = application.alerts
|
||||
|
||||
const validateCurrentPassword = useCallback(async () => {
|
||||
if (!currentPassword || currentPassword.length === 0) {
|
||||
|
||||
@@ -35,7 +35,7 @@ const Email: FunctionComponent<Props> = ({ application }: Props) => {
|
||||
await application.settings.updateSetting(settingName, payload, false)
|
||||
return true
|
||||
} catch (e) {
|
||||
application.alertService.alert(STRING_FAILED_TO_UPDATE_USER_SETTING).catch(console.error)
|
||||
application.alerts.alert(STRING_FAILED_TO_UPDATE_USER_SETTING).catch(console.error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ const InvitationsList = ({ subscriptionState, application }: Props) => {
|
||||
|
||||
const handleCancel = async (invitationUuid: string) => {
|
||||
if (lockContinue) {
|
||||
application.alertService.alert('Cancelation already in progress.').catch(console.error)
|
||||
application.alerts.alert('Cancelation already in progress.').catch(console.error)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -36,7 +36,7 @@ const InvitationsList = ({ subscriptionState, application }: Props) => {
|
||||
setLockContinue(false)
|
||||
|
||||
if (!success) {
|
||||
application.alertService
|
||||
application.alerts
|
||||
.alert('Could not cancel invitation. Please try again or contact support if the issue persists.')
|
||||
.catch(console.error)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ const Invite: FunctionComponent<Props> = ({ onCloseDialog, application, subscrip
|
||||
|
||||
const validateInviteeEmail = useCallback(async () => {
|
||||
if (!isEmailValid(inviteeEmail)) {
|
||||
application.alertService
|
||||
application.alerts
|
||||
.alert('The email you entered has an invalid format. Please review your input and try again.')
|
||||
.catch(console.error)
|
||||
|
||||
@@ -42,15 +42,15 @@ const Invite: FunctionComponent<Props> = ({ onCloseDialog, application, subscrip
|
||||
}
|
||||
|
||||
return true
|
||||
}, [application.alertService, inviteeEmail])
|
||||
}, [application.alerts, inviteeEmail])
|
||||
|
||||
const handleDialogClose = useCallback(() => {
|
||||
if (lockContinue) {
|
||||
application.alertService.alert('Cannot close window until pending tasks are complete.').catch(console.error)
|
||||
application.alerts.alert('Cannot close window until pending tasks are complete.').catch(console.error)
|
||||
} else {
|
||||
onCloseDialog()
|
||||
}
|
||||
}, [application.alertService, lockContinue, onCloseDialog])
|
||||
}, [application.alerts, lockContinue, onCloseDialog])
|
||||
|
||||
const resetProgressState = () => {
|
||||
setSubmitButtonTitle(SubmitButtonTitles.Default)
|
||||
@@ -91,7 +91,7 @@ const Invite: FunctionComponent<Props> = ({ onCloseDialog, application, subscrip
|
||||
|
||||
const success = await processInvite()
|
||||
if (!success) {
|
||||
application.alertService
|
||||
application.alerts
|
||||
.alert('An error occurred while sending the invite. Please try again or contact support if the issue persists.')
|
||||
.catch(console.error)
|
||||
|
||||
@@ -104,7 +104,7 @@ const Invite: FunctionComponent<Props> = ({ onCloseDialog, application, subscrip
|
||||
setSubmitButtonTitle(SubmitButtonTitles.Finish)
|
||||
setCurrentStep(Steps.FinishStep)
|
||||
}, [
|
||||
application.alertService,
|
||||
application.alerts,
|
||||
currentStep,
|
||||
handleDialogClose,
|
||||
isContinuing,
|
||||
|
||||
@@ -26,7 +26,7 @@ const Sync: FunctionComponent<Props> = ({ application }: Props) => {
|
||||
})
|
||||
setIsSyncingInProgress(false)
|
||||
if (response && (response as any).error) {
|
||||
application.alertService.alert(STRING_GENERIC_SYNC_ERROR).catch(console.error)
|
||||
application.alerts.alert(STRING_GENERIC_SYNC_ERROR).catch(console.error)
|
||||
} else {
|
||||
setLastSyncDate(formatLastSyncDate(application.sync.getLastSyncDate() as Date))
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ const DataBackups = ({ application, viewControllerManager }: Props) => {
|
||||
|
||||
const readFile = async (file: File): Promise<any> => {
|
||||
if (file.type === 'application/zip') {
|
||||
application.alertService.alert(STRING_IMPORTING_ZIP_FILE).catch(console.error)
|
||||
application.alerts.alert(STRING_IMPORTING_ZIP_FILE).catch(console.error)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ const DataBackups = ({ application, viewControllerManager }: Props) => {
|
||||
const data = JSON.parse(e.target?.result as string)
|
||||
resolve(data)
|
||||
} catch (e) {
|
||||
application.alertService.alert(STRING_INVALID_IMPORT_FILE).catch(console.error)
|
||||
application.alerts.alert(STRING_INVALID_IMPORT_FILE).catch(console.error)
|
||||
}
|
||||
}
|
||||
reader.readAsText(file)
|
||||
@@ -146,7 +146,7 @@ const DataBackups = ({ application, viewControllerManager }: Props) => {
|
||||
return
|
||||
}
|
||||
|
||||
if (application.encryptionService.supportedVersions().includes(version)) {
|
||||
if (application.encryption.supportedVersions().includes(version)) {
|
||||
await performImport(data)
|
||||
} else {
|
||||
setIsImportDataLoading(false)
|
||||
|
||||
@@ -72,7 +72,7 @@ const EmailBackups = ({ application }: Props) => {
|
||||
await application.settings.updateSetting(settingName, payload, false)
|
||||
return true
|
||||
} catch (e) {
|
||||
application.alertService.alert(STRING_FAILED_TO_UPDATE_USER_SETTING).catch(console.error)
|
||||
application.alerts.alert(STRING_FAILED_TO_UPDATE_USER_SETTING).catch(console.error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,14 +50,14 @@ const BackupsDropZone: FunctionComponent<Props> = ({ application }) => {
|
||||
const result = await application.files.readBackupFileAndSaveDecrypted(binaryFile, decryptedFileItem, fileSystem)
|
||||
|
||||
if (result === 'success') {
|
||||
void application.alertService.alert(
|
||||
void application.alerts.alert(
|
||||
`<strong>${decryptedFileItem.name}</strong> has been successfully decrypted and saved to your chosen directory.`,
|
||||
)
|
||||
setBinaryFile(undefined)
|
||||
setDecryptedFileItem(undefined)
|
||||
setDroppedFile(undefined)
|
||||
} else if (result === 'failed') {
|
||||
void application.alertService.alert(
|
||||
void application.alerts.alert(
|
||||
'Unable to save file to local directory. This may be caused by failure to decrypt, or failure to save the file locally.',
|
||||
)
|
||||
}
|
||||
@@ -74,7 +74,7 @@ const BackupsDropZone: FunctionComponent<Props> = ({ application }) => {
|
||||
}
|
||||
|
||||
if (type === 'binary') {
|
||||
void application.alertService.alert('Please drag the metadata file instead of the encrypted data file.')
|
||||
void application.alerts.alert('Please drag the metadata file instead of the encrypted data file.')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ const BackupsDropZone: FunctionComponent<Props> = ({ application }) => {
|
||||
console.error(error)
|
||||
}
|
||||
},
|
||||
[application.alertService, application.files],
|
||||
[application.alerts, application.files],
|
||||
)
|
||||
|
||||
const handleDragOver = useCallback((event: DragEvent) => {
|
||||
|
||||
@@ -41,7 +41,7 @@ const OfflineSubscription: FunctionComponent<Props> = ({ application, onSuccess
|
||||
|
||||
if (homeServerEnabled) {
|
||||
if (!homeServerIsRunning) {
|
||||
await application.alertService.alert('Please start your home server before activating offline features.')
|
||||
await application.alerts.alert('Please start your home server before activating offline features.')
|
||||
|
||||
return
|
||||
}
|
||||
@@ -53,7 +53,7 @@ const OfflineSubscription: FunctionComponent<Props> = ({ application, onSuccess
|
||||
|
||||
const serverActivationResult = await homeServer.activatePremiumFeatures(signedInUser.email)
|
||||
if (serverActivationResult.isFailed()) {
|
||||
await application.alertService.alert(serverActivationResult.getError())
|
||||
await application.alerts.alert(serverActivationResult.getError())
|
||||
|
||||
return
|
||||
}
|
||||
@@ -62,7 +62,7 @@ const OfflineSubscription: FunctionComponent<Props> = ({ application, onSuccess
|
||||
const result = await application.features.setOfflineFeaturesCode(activationCode)
|
||||
|
||||
if (result instanceof ClientDisplayableError) {
|
||||
await application.alertService.alert(result.text)
|
||||
await application.alerts.alert(result.text)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -85,7 +85,7 @@ const OfflineSubscription: FunctionComponent<Props> = ({ application, onSuccess
|
||||
}
|
||||
|
||||
const handleRemoveClick = async () => {
|
||||
application.alertService
|
||||
application.alerts
|
||||
.confirm(
|
||||
STRING_REMOVE_OFFLINE_KEY_CONFIRMATION,
|
||||
'Remove offline key?',
|
||||
@@ -99,7 +99,7 @@ const OfflineSubscription: FunctionComponent<Props> = ({ application, onSuccess
|
||||
}
|
||||
})
|
||||
.catch((err: string) => {
|
||||
application.alertService.alert(err).catch(console.error)
|
||||
application.alerts.alert(err).catch(console.error)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ const PackagesPreferencesSection: FunctionComponent<Props> = ({
|
||||
}, [confirmableExtension, confirmableEnd])
|
||||
|
||||
const uninstallExtension = async (extension: AnyPackageType) => {
|
||||
application.alertService
|
||||
application.alerts
|
||||
.confirm(
|
||||
'Are you sure you want to uninstall this plugin? Note that plugins managed by your subscription will automatically be re-installed on application restart.',
|
||||
'Uninstall Extension?',
|
||||
@@ -58,7 +58,7 @@ const PackagesPreferencesSection: FunctionComponent<Props> = ({
|
||||
}
|
||||
})
|
||||
.catch((err: string) => {
|
||||
application.alertService.alert(err).catch(console.error)
|
||||
application.alerts.alert(err).catch(console.error)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ const Listed = ({ application }: Props) => {
|
||||
const requestAccount = async () => {
|
||||
const account = await application.listed.requestNewListedAccount()
|
||||
if (account) {
|
||||
const openSettings = await application.alertService.confirm(
|
||||
const openSettings = await application.alerts.confirm(
|
||||
'Your new Listed blog has been successfully created!' +
|
||||
' You can publish a new post to your blog from Standard Notes via the' +
|
||||
' <i>Actions</i> menu in the editor pane. Open your blog settings to begin setting it up.',
|
||||
@@ -47,7 +47,7 @@ const Listed = ({ application }: Props) => {
|
||||
if (openSettings) {
|
||||
const info = await application.listed.getListedAccountInfo(account)
|
||||
if (info) {
|
||||
application.deviceInterface.openUrl(info?.settings_url)
|
||||
application.device.openUrl(info?.settings_url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ const BiometricsLock = ({ application }: Props) => {
|
||||
|
||||
const hasBiometricsSupport = async () => {
|
||||
const hasBiometricsAvailable = await (
|
||||
application.deviceInterface as MobileDeviceInterface
|
||||
application.device as MobileDeviceInterface
|
||||
).getDeviceBiometricsAvailability?.()
|
||||
setSupportsBiometrics(hasBiometricsAvailable)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ const ErroredItems: FunctionComponent = () => {
|
||||
}
|
||||
|
||||
const deleteItems = async (items: EncryptedItemInterface[]): Promise<void> => {
|
||||
const confirmed = await application.alertService.confirm(
|
||||
const confirmed = await application.alerts.confirm(
|
||||
`Are you sure you want to permanently delete ${items.length} item(s)?`,
|
||||
undefined,
|
||||
'Delete',
|
||||
@@ -58,7 +58,7 @@ const ErroredItems: FunctionComponent = () => {
|
||||
const errorOrTrue = application.canAttemptDecryptionOfItem(item)
|
||||
|
||||
if (errorOrTrue instanceof ClientDisplayableError) {
|
||||
void application.alertService.showErrorAlert(errorOrTrue)
|
||||
void application.alerts.showErrorAlert(errorOrTrue)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ const MultitaskingPrivacy = ({ application }: Props) => {
|
||||
setHasScreenshotPrivacy(enable)
|
||||
|
||||
application.protections.setMobileScreenshotPrivacyEnabled(enable)
|
||||
;(application.deviceInterface as MobileDeviceInterface).setAndroidScreenshotPrivacy(enable)
|
||||
;(application.device as MobileDeviceInterface).setAndroidScreenshotPrivacy(enable)
|
||||
}
|
||||
|
||||
const screenshotPrivacyFeatureText = isIOS() ? 'Multitasking Privacy' : 'Multitasking/Screenshot Privacy'
|
||||
|
||||
@@ -24,7 +24,7 @@ const Privacy: FunctionComponent<Props> = ({ application }: Props) => {
|
||||
await application.settings.updateSetting(settingName, payload, false)
|
||||
return true
|
||||
} catch (e) {
|
||||
application.alertService.alert(STRING_FAILED_TO_UPDATE_USER_SETTING).catch(console.error)
|
||||
application.alerts.alert(STRING_FAILED_TO_UPDATE_USER_SETTING).catch(console.error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,18 +51,10 @@ const EditContactModal: FunctionComponent<Props> = ({ onCloseDialog, fromInvite,
|
||||
onAddContact?.(contact)
|
||||
handleDialogClose()
|
||||
} else {
|
||||
void application.alertService.alert('Unable to create contact. Please try again.')
|
||||
void application.alerts.alert('Unable to create contact. Please try again.')
|
||||
}
|
||||
}
|
||||
}, [
|
||||
editingContact,
|
||||
application.contacts,
|
||||
application.alertService,
|
||||
name,
|
||||
collaborationID,
|
||||
handleDialogClose,
|
||||
onAddContact,
|
||||
])
|
||||
}, [editingContact, application.contacts, application.alerts, name, collaborationID, handleDialogClose, onAddContact])
|
||||
|
||||
const modalActions = useMemo(
|
||||
(): ModalAction[] => [
|
||||
|
||||
Reference in New Issue
Block a user