From 0cb38788d2da9228f988e381fb001cd0ae2ffcaf Mon Sep 17 00:00:00 2001 From: Marcel Ebert Date: Tue, 15 Sep 2020 16:02:23 +0200 Subject: [PATCH 01/16] Add button for printing to secretkey export dialog --- i18n/locales/en/account-settings.json | 3 +- src/Account/components/AccountHeaderCard.tsx | 21 ++++---- src/Account/components/KeyExportBox.tsx | 16 +++++- .../components/ExportKeyDialog.tsx | 53 ++++++++++++++++++- 4 files changed, 80 insertions(+), 13 deletions(-) diff --git a/i18n/locales/en/account-settings.json b/i18n/locales/en/account-settings.json index d9ebb8074..3f1d9754e 100644 --- a/i18n/locales/en/account-settings.json +++ b/i18n/locales/en/account-settings.json @@ -66,7 +66,8 @@ "reveal": { "long": "Reveal key", "short": "Click to reveal secret key" - } + }, + "print": "Print" }, "info": { "backup": { diff --git a/src/Account/components/AccountHeaderCard.tsx b/src/Account/components/AccountHeaderCard.tsx index f094b6700..2d538d9d0 100644 --- a/src/Account/components/AccountHeaderCard.tsx +++ b/src/Account/components/AccountHeaderCard.tsx @@ -32,6 +32,17 @@ const useAccountHeaderStyles = makeStyles({ marginRight: -12 } }, + card: { + color: "white", + position: "relative", + background: "transparent", + boxShadow: "none", + overflow: "visible", + + "@media print": { + display: "none" + } + }, closeButton: { boxSizing: "content-box", width: 32, @@ -129,15 +140,7 @@ function AccountHeaderCard(props: Props) { ) return ( - + ({ + noPrint: { + "@media print": { + display: "none" + } + } +})) + interface Props { export: string hideTapToCopy?: boolean @@ -12,6 +21,7 @@ interface Props { } function KeyExportBox(props: Props) { + const classes = useStyles() const clipboard = useClipboard() const copyToClipboard = React.useCallback(() => clipboard.copyToClipboard(props.export), [clipboard, props.export]) const { t } = useTranslation() @@ -23,7 +33,11 @@ function KeyExportBox(props: Props) { - + {t("account-settings.export-key.info.tap-to-copy")}: ({ + hiddenAccountName: { + display: "none", + + "@media print": { + display: "block" + } + } +})) + interface ShowSecretKeyProps { + accountName?: string export: string onConfirm?: () => void title: React.ReactNode @@ -87,6 +102,8 @@ interface ShowSecretKeyProps { function ShowSecretKey(props: ShowSecretKeyProps) { const { t } = useTranslation() + const classes = useSecretKeyStyles() + return ( } @@ -108,6 +125,9 @@ function ShowSecretKey(props: ShowSecretKeyProps) { {t("account-settings.export-key.info.secret-key")} ) : null} + + {props.accountName ? `"${props.accountName}"` : undefined} + @@ -115,6 +135,14 @@ function ShowSecretKey(props: ShowSecretKeyProps) { ) } +export const useExportKeyDialogStyles = makeStyles(theme => ({ + noPrint: { + "@media print": { + display: "none" + } + } +})) + interface Props { account: Account | null | undefined onClose?: () => void @@ -123,6 +151,8 @@ interface Props { } function ExportKeyDialog(props: Props) { + const classes = useExportKeyDialogStyles() + const [password, setPassword] = React.useState("") const [passwordError, setPasswordError] = React.useState(null) const [isRevealed, setIsRevealed] = React.useState(false) @@ -159,17 +189,30 @@ function ExportKeyDialog(props: Props) { [] ) + const actions = React.useMemo(() => { + return isRevealed ? ( + + ) : ( + undefined + ) + }, [classes, isRevealed, t]) + const titleContent = React.useMemo( () => props.variant === "initial-backup" ? null : ( ), - [props.variant, onBackButtonClick, t] + [actions, props.variant, onBackButtonClick, t] ) const backupInfoContent = React.useMemo( @@ -204,7 +247,13 @@ function ExportKeyDialog(props: Props) { ) return isRevealed && secretKey ? ( - + ) : ( Date: Tue, 15 Sep 2020 16:34:01 +0200 Subject: [PATCH 02/16] Add ipc for printing --- electron/src/ipc/print.ts | 6 ++++++ shared/ipc.ts | 2 ++ shared/types/cordova.d.ts | 5 +++++ shared/types/ipc.d.ts | 4 ++++ src/AccountSettings/components/ExportKeyDialog.tsx | 3 ++- src/App/cordova/app.cordova.ts | 2 ++ src/App/cordova/print.ts | 13 +++++++++++++ src/Platform/ipc/web.ts | 1 + src/Platform/print.ts | 6 ++++++ 9 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 electron/src/ipc/print.ts create mode 100644 src/App/cordova/print.ts create mode 100644 src/Platform/print.ts diff --git a/electron/src/ipc/print.ts b/electron/src/ipc/print.ts new file mode 100644 index 000000000..d89c5802a --- /dev/null +++ b/electron/src/ipc/print.ts @@ -0,0 +1,6 @@ +import { Messages } from "../shared/ipc" +import { expose } from "./_ipc" + +expose(Messages.Print, () => { + window.print() +}) diff --git a/shared/ipc.ts b/shared/ipc.ts index a46a7db03..d9d1033cc 100644 --- a/shared/ipc.ts +++ b/shared/ipc.ts @@ -15,6 +15,8 @@ export const Messages: IPC.MessageType = { OpenLink: "OpenLink", + Print: "Print", + DeepLinkURL: "DeepLinkURL", CheckUpdateAvailability: "CheckUpdateAvailability", diff --git a/shared/types/cordova.d.ts b/shared/types/cordova.d.ts index 2a09ddd51..192180e28 100644 --- a/shared/types/cordova.d.ts +++ b/shared/types/cordova.d.ts @@ -114,6 +114,10 @@ interface NotificationPlugin { } } +interface Printer { + print(content?: string, options?: Object, callback?: Function, scope?: Object): void +} + declare var Fingerprint: Fingerprint interface CordovaPlugins { @@ -121,6 +125,7 @@ interface CordovaPlugins { clipboard: CordovaClipboard notification: NotificationPlugin SecureStorage: CordovaSecureStorage + printer: Printer } interface Navigator { diff --git a/shared/types/ipc.d.ts b/shared/types/ipc.d.ts index 1e864ae94..cc31861f2 100644 --- a/shared/types/ipc.d.ts +++ b/shared/types/ipc.d.ts @@ -23,6 +23,8 @@ declare namespace IPC { OpenLink: "OpenLink" + Print: "Print" + DeepLinkURL: "DeepLinkURL" CheckUpdateAvailability: "CheckUpdateAvailability" @@ -61,6 +63,8 @@ declare namespace IPC { [Messages.OpenLink]: (href: string) => void + [Messages.Print]: () => void + [Messages.DeepLinkURL]: () => string [Messages.CheckUpdateAvailability]: () => boolean diff --git a/src/AccountSettings/components/ExportKeyDialog.tsx b/src/AccountSettings/components/ExportKeyDialog.tsx index d73dbbe58..05a1b132d 100644 --- a/src/AccountSettings/components/ExportKeyDialog.tsx +++ b/src/AccountSettings/components/ExportKeyDialog.tsx @@ -20,6 +20,7 @@ import { isWrongPasswordError, getErrorTranslation } from "~Generic/lib/errors" import { ActionButton, DialogActionsBox } from "~Generic/components/DialogActions" import { Box } from "~Layout/components/Box" import DialogBody from "~Layout/components/DialogBody" +import { print } from "~Platform/print" interface PromptToRevealProps { children: React.ReactNode @@ -191,7 +192,7 @@ function ExportKeyDialog(props: Props) { const actions = React.useMemo(() => { return isRevealed ? ( -