Skip to content

Commit ec348f8

Browse files
committed
fix: disable markdown print in tauri desktop app and safari
1 parent 27dc990 commit ec348f8

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src-mdviewer/src/components/embedded-toolbar.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ const THRESHOLD_BLOCKS = 640; // collapse block elements + image first
5050
const THRESHOLD_LISTS = 590; // then lists
5151
const THRESHOLD_TEXT = 590; // finally text formatting (all dropdowns collapsed)
5252

53+
// window.print() from inside an iframe is a no-op in WKWebView (Safari on macOS),
54+
// which is what Tauri uses for the Mac desktop build. Hide the button there.
55+
const _isMacWebKit = /Mac/.test(navigator.platform)
56+
&& /AppleWebKit/.test(navigator.userAgent)
57+
&& !/Chrome|CriOS|Edg|Firefox|FxiOS/.test(navigator.userAgent);
58+
5359
const allIcons = { Bold, Italic, Strikethrough, Underline, Code, Link, List, ListOrdered,
5460
ListChecks, Quote, Minus, Table, FileCode, ChevronDown, Type, MoreHorizontal, Pencil, BookOpen, Link2, Link2Off, Printer, Image: ImageIcon, Upload, Sun, Moon };
5561

@@ -89,9 +95,9 @@ function renderReadMode() {
8995
<button class="toolbar-btn theme-toggle-btn" id="emb-theme-toggle" data-tooltip="${t("toolbar.theme") || "Toggle theme"}">
9096
<i data-lucide="${isDark ? "sun" : "moon"}"></i>
9197
</button>
92-
<button class="toolbar-btn print-btn" id="emb-print-btn" data-tooltip="${t("toolbar.print") || "Print"}">
98+
${_isMacWebKit ? "" : `<button class="toolbar-btn print-btn" id="emb-print-btn" data-tooltip="${t("toolbar.print") || "Print"}">
9399
<i data-lucide="printer"></i>
94-
</button>
100+
</button>`}
95101
<button class="toolbar-btn cursor-sync-btn${cursorSyncEnabled ? " active" : ""}" id="emb-cursor-sync" data-tooltip="${t("toolbar.cursor_sync") || "Cursor sync"}" aria-pressed="${cursorSyncEnabled}">
96102
<i data-lucide="link-2" class="sync-on-icon"${cursorSyncEnabled ? "" : ' style="display:none"'}></i>
97103
<i data-lucide="link-2-off" class="sync-off-icon"${cursorSyncEnabled ? ' style="display:none"' : ""}></i>
@@ -206,9 +212,9 @@ function renderEditMode(level) {
206212
<button class="toolbar-btn theme-toggle-btn" id="emb-theme-toggle" data-tooltip="${t("toolbar.theme") || "Toggle theme"}">
207213
<i data-lucide="${isDark ? "sun" : "moon"}"></i>
208214
</button>
209-
<button class="toolbar-btn print-btn" id="emb-print-btn" data-tooltip="${t("toolbar.print") || "Print"}">
215+
${_isMacWebKit ? "" : `<button class="toolbar-btn print-btn" id="emb-print-btn" data-tooltip="${t("toolbar.print") || "Print"}">
210216
<i data-lucide="printer"></i>
211-
</button>
217+
</button>`}
212218
<button class="toolbar-btn cursor-sync-btn${cursorSyncEnabled ? " active" : ""}" id="emb-cursor-sync" data-tooltip="${t("toolbar.cursor_sync") || "Cursor sync"}" aria-pressed="${cursorSyncEnabled}">
213219
<i data-lucide="link-2" class="sync-on-icon"${cursorSyncEnabled ? "" : ' style="display:none"'}></i>
214220
<i data-lucide="link-2-off" class="sync-off-icon"${cursorSyncEnabled ? ' style="display:none"' : ""}></i>

0 commit comments

Comments
 (0)