Skip to content

TagSpaces is an offline, open source, document manager with tagging support

chore: added a print functionality for the license and thirdparty dialog

Ilian Sapundshiev2d0e02eb62a6
diff --git a/src/renderer/components/dialogs/LicenseDialog.tsx b/src/renderer/components/dialogs/LicenseDialog.tsx
index 459355b5d..f775b3c34 100644
--- a/src/renderer/components/dialogs/LicenseDialog.tsx
+++ b/src/renderer/components/dialogs/LicenseDialog.tsx
@@ -16,7 +16,9 @@
*
*/
+import AppConfig from '-/AppConfig';
import LicenseContent from '-/LICENSE.txt';
+import { printText } from '-/utils/print';
import TsButton from '-/components/TsButton';
import TsDialogActions from '-/components/dialogs/components/TsDialogActions';
import { Pro } from '-/pro';
@@ -49,11 +51,8 @@ interface Props {
function LicenseDialog(props: Props) {
const { open, onClose } = props;
const { t } = useTranslation();
- // let licenseElement;
- // function printLicense() {
- // // printElem(licenseElement);
- // window.print();
- // }
+
+ const licenseText = Pro ? Pro.EULAContent : LicenseContent;
const theme = useTheme();
const smallScreen = useMediaQuery(theme.breakpoints.down('md'));
@@ -76,24 +75,37 @@ function LicenseDialog(props: Props) {
sx={{ overflow: 'auto' }}
>
<pre style={{ whiteSpace: 'pre-wrap', userSelect: 'text' }}>
- {Pro ? Pro.EULAContent : LicenseContent}
+ {licenseText}
</pre>
</DialogContent>
<TsDialogActions>
- {/* <TsButton
- onClick={printLicense}
- >
- {t('core:print')}
- </TsButton> */}
- <TsButton data-tid="confirmLicenseDialog" onClick={quitApp}>
- {t('core:quit')}
- </TsButton>
+ {/* Print sits on the left (marginRight:auto pushes the rest right) so
+ the user can save the license as a PDF via the OS print dialog.
+ Desktop/web only — WebView printing is unreliable on mobile. */}
+ {!AppConfig.isNativeMobile && (
+ <TsButton
+ data-tid="printLicenseDialog"
+ onClick={() => printText(licenseText, t('core:license'))}
+ sx={{ marginRight: 'auto' }}
+ >
+ {t('core:print')}
+ </TsButton>
+ )}
+ {/* Native mobile: the license is shown for information only (the store
+ handles the EULA and the AGPL doesn't gate running the app), so no
+ accept/decline. A self-terminating "Quit" also violates store
+ review guidelines, so it's desktop-only. */}
+ {!AppConfig.isNativeMobile && (
+ <TsButton data-tid="confirmLicenseDialog" onClick={quitApp}>
+ {t('core:quit')}
+ </TsButton>
+ )}
<TsButton
data-tid="agreeLicenseDialog"
onClick={props.onClose}
variant="contained"
>
- {t('core:agreeLicense')}
+ {AppConfig.isNativeMobile ? t('core:ok') : t('core:agreeLicense')}
</TsButton>
</TsDialogActions>
</Dialog>
diff --git a/src/renderer/components/dialogs/ThirdPartyLibsDialog.tsx b/src/renderer/components/dialogs/ThirdPartyLibsDialog.tsx
index 9ce3831e2..af7338f42 100644
--- a/src/renderer/components/dialogs/ThirdPartyLibsDialog.tsx
+++ b/src/renderer/components/dialogs/ThirdPartyLibsDialog.tsx
@@ -21,6 +21,7 @@ import TsButton from '-/components/TsButton';
import TsDialogActions from '-/components/dialogs/components/TsDialogActions';
import TsDialogTitle from '-/components/dialogs/components/TsDialogTitle';
import ThirdPartyLibs from '-/third-party.txt';
+import { printText } from '-/utils/print';
import Dialog from '@mui/material/Dialog';
import DialogContent from '@mui/material/DialogContent';
import Paper from '@mui/material/Paper';
@@ -72,7 +73,22 @@ function ThirdPartyLibsDialog(props: Props) {
{ThirdPartyLibs}
</pre>
</DialogContent>
- {!smallScreen && <TsDialogActions>{okButton}</TsDialogActions>}
+ {!smallScreen && (
+ <TsDialogActions>
+ {/* Left-aligned (marginRight:auto) so the user can save the notices
+ as a PDF via the OS print dialog. Desktop only — this actions row
+ is hidden on small screens, where WebView printing is unreliable
+ anyway. */}
+ <TsButton
+ data-tid="printThirdPartyLibsDialog"
+ onClick={() => printText(ThirdPartyLibs, t('core:thirdPartyLibs'))}
+ sx={{ marginRight: 'auto' }}
+ >
+ {t('core:print')}
+ </TsButton>
+ {okButton}
+ </TsDialogActions>
+ )}
</Dialog>
);
}
diff --git a/src/renderer/components/dialogs/hooks/LicenseDialogContextProvider.tsx b/src/renderer/components/dialogs/hooks/LicenseDialogContextProvider.tsx
index 45a85f10b..615590dd5 100644
--- a/src/renderer/components/dialogs/hooks/LicenseDialogContextProvider.tsx
+++ b/src/renderer/components/dialogs/hooks/LicenseDialogContextProvider.tsx
@@ -65,8 +65,24 @@ export const LicenseDialogContextProvider = ({
// (defaults to true) and manual resets (Settings → Restore Defaults clears
// localStorage, reload re-applies defaults). Reactive — works regardless
// of redux-persist rehydration timing.
+ //
+ // Native mobile (App Store / Play Store) is the exception: the store handles
+ // the EULA, the AGPL doesn't require end-user acceptance to run a copy
+ // (AGPLv3 §9), and a first-run accept/quit gate (with a self-terminating
+ // "Quit") is discouraged by — and risks rejection under — store review
+ // guidelines. So we skip the gate there: clear firstRun and hand off to
+ // onboarding directly. The license stays available via About → License.
useEffect(() => {
- if (firstRun) setOpen(true);
+ if (!firstRun) return;
+ if (AppConfig.isNativeMobile) {
+ dispatch(SettingsActions.setFirstRun(false));
+ if (!onboardingCompleted && openOnboardingDialog) {
+ openOnboardingDialog();
+ }
+ } else {
+ setOpen(true);
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [firstRun]);
useEffect(() => {
diff --git a/src/renderer/utils/print.ts b/src/renderer/utils/print.ts
new file mode 100644
index 000000000..a3372f627
--- /dev/null
+++ b/src/renderer/utils/print.ts
@@ -0,0 +1,69 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2026-present TagSpaces GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+function escapeHtml(value: string): string {
+ return String(value)
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;');
+}
+
+/**
+ * Print a block of plain text via the OS print dialog (so the user can save it
+ * as a PDF, for example), without printing the whole app window.
+ *
+ * The text is rendered into an off-screen iframe and that iframe is printed —
+ * this avoids popup blockers and works in both the web build and Electron.
+ * WKWebView / Android WebView printing is unreliable, so callers typically gate
+ * this to desktop/web (e.g. `!AppConfig.isNativeMobile`).
+ */
+export function printText(text: string, title = ''): void {
+ const iframe = document.createElement('iframe');
+ iframe.setAttribute('aria-hidden', 'true');
+ iframe.style.cssText =
+ 'position:fixed;right:0;bottom:0;width:0;height:0;border:0;';
+ document.body.appendChild(iframe);
+
+ const cleanup = () => {
+ if (iframe.parentNode) {
+ iframe.parentNode.removeChild(iframe);
+ }
+ };
+
+ const win = iframe.contentWindow;
+ if (!win) {
+ cleanup();
+ return;
+ }
+
+ win.document.open();
+ win.document.write(
+ '<html><head><title>' +
+ escapeHtml(title) +
+ '</title></head><body>' +
+ '<pre style="white-space:pre-wrap;word-wrap:break-word;' +
+ 'font-family:monospace;font-size:12px;">' +
+ escapeHtml(text) +
+ '</pre></body></html>',
+ );
+ win.document.close();
+ win.focus();
+ win.print();
+ // Give the print dialog time to grab the document before removing the iframe.
+ setTimeout(cleanup, 1000);
+}