From 14516d53c3812d074ecdb6466a4857cba31d1056 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 13 Apr 2025 23:09:14 +0300 Subject: [PATCH] chore(touchbar): disable widget on non-mac --- src/public/app/layouts/desktop_layout.ts | 4 ++-- src/public/app/services/utils.ts | 2 ++ .../app/widgets/type_widgets/editable_code.ts | 3 ++- .../app/widgets/type_widgets/editable_text.ts | 8 +++++--- .../app/widgets/type_widgets/geo_map.ts | 20 ++++++++++++------- .../app/widgets/view_widgets/calendar_view.ts | 6 ++++-- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/public/app/layouts/desktop_layout.ts b/src/public/app/layouts/desktop_layout.ts index 9ecbf7e8d..0750bba36 100644 --- a/src/public/app/layouts/desktop_layout.ts +++ b/src/public/app/layouts/desktop_layout.ts @@ -83,7 +83,7 @@ import CopyImageReferenceButton from "../widgets/floating_buttons/copy_image_ref import ScrollPaddingWidget from "../widgets/scroll_padding.js"; import ClassicEditorToolbar from "../widgets/ribbon_widgets/classic_editor_toolbar.js"; import options from "../services/options.js"; -import utils from "../services/utils.js"; +import utils, { hasTouchBar } from "../services/utils.js"; import GeoMapButtons from "../widgets/floating_buttons/geo_map_button.js"; import ContextualHelpButton from "../widgets/floating_buttons/help_button.js"; import CloseZenButton from "../widgets/close_zen_button.js"; @@ -162,7 +162,7 @@ export default class DesktopLayout { .filling() .collapsible() .id("center-pane") - .child(new TouchBarWidget()) + .optChild(hasTouchBar, new TouchBarWidget()) .child( new SplitNoteContainer(() => new NoteWrapperWidget() diff --git a/src/public/app/services/utils.ts b/src/public/app/services/utils.ts index efbb82cf8..6ba2793dd 100644 --- a/src/public/app/services/utils.ts +++ b/src/public/app/services/utils.ts @@ -147,6 +147,8 @@ function isMac() { return navigator.platform.indexOf("Mac") > -1; } +export const hasTouchBar = isMac(); + function isCtrlKey(evt: KeyboardEvent | MouseEvent | JQuery.ClickEvent | JQuery.ContextMenuEvent | JQuery.TriggeredEvent | React.PointerEvent) { return (!isMac() && evt.ctrlKey) || (isMac() && evt.metaKey); } diff --git a/src/public/app/widgets/type_widgets/editable_code.ts b/src/public/app/widgets/type_widgets/editable_code.ts index 49bcde3f1..371cb7f0a 100644 --- a/src/public/app/widgets/type_widgets/editable_code.ts +++ b/src/public/app/widgets/type_widgets/editable_code.ts @@ -6,6 +6,7 @@ import options from "../../services/options.js"; import AbstractCodeTypeWidget from "./abstract_code_type_widget.js"; import appContext from "../../components/app_context.js"; import type { TouchBarItem } from "../touch_bar.js"; +import { hasTouchBar } from "../../services/utils.js"; const TPL = /*html*/`
@@ -64,7 +65,7 @@ export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget { this.show(); - if (this.parent) { + if (this.parent && hasTouchBar) { this.triggerCommand("refreshTouchBar"); } } diff --git a/src/public/app/widgets/type_widgets/editable_text.ts b/src/public/app/widgets/type_widgets/editable_text.ts index 2e2ba64c5..65166f2dc 100644 --- a/src/public/app/widgets/type_widgets/editable_text.ts +++ b/src/public/app/widgets/type_widgets/editable_text.ts @@ -2,7 +2,7 @@ import { t } from "../../services/i18n.js"; import libraryLoader from "../../services/library_loader.js"; import noteAutocompleteService from "../../services/note_autocomplete.js"; import mimeTypesService from "../../services/mime_types.js"; -import utils from "../../services/utils.js"; +import utils, { hasTouchBar } from "../../services/utils.js"; import keyboardActionService from "../../services/keyboard_actions.js"; import froca from "../../services/froca.js"; import noteCreateService from "../../services/note_create.js"; @@ -282,8 +282,10 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { } // Touch bar integration - for (const event of [ "bold", "italic", "underline", "paragraph", "heading" ]) { - editor.commands.get(event).on("change", () => this.triggerCommand("refreshTouchBar")); + if (hasTouchBar) { + for (const event of [ "bold", "italic", "underline", "paragraph", "heading" ]) { + editor.commands.get(event).on("change", () => this.triggerCommand("refreshTouchBar")); + } } return editor; diff --git a/src/public/app/widgets/type_widgets/geo_map.ts b/src/public/app/widgets/type_widgets/geo_map.ts index 82a01fc41..320fb7c9a 100644 --- a/src/public/app/widgets/type_widgets/geo_map.ts +++ b/src/public/app/widgets/type_widgets/geo_map.ts @@ -15,6 +15,7 @@ import appContext from "../../components/app_context.js"; import markerIcon from "leaflet/dist/images/marker-icon.png"; import markerIconShadow from "leaflet/dist/images/marker-shadow.png"; +import { hasTouchBar } from "../../services/utils.js"; const TPL = /*html*/`\
@@ -152,13 +153,16 @@ export default class GeoMapTypeWidget extends TypeWidget { map.on("moveend", updateFn); map.on("zoomend", updateFn); map.on("click", (e) => this.#onMapClicked(e)); - map.on("zoom", () => { - if (!this.ignoreNextZoomEvent) { - this.triggerCommand("refreshTouchBar"); - } - this.ignoreNextZoomEvent = false; - }); + if (hasTouchBar) { + map.on("zoom", () => { + if (!this.ignoreNextZoomEvent) { + this.triggerCommand("refreshTouchBar"); + } + + this.ignoreNextZoomEvent = false; + }); + } } async #restoreViewportAndZoom() { @@ -287,7 +291,9 @@ export default class GeoMapTypeWidget extends TypeWidget { #changeState(newState: State) { this._state = newState; this.geoMapWidget.$container.toggleClass("placing-note", newState === State.NewNote); - this.triggerCommand("refreshTouchBar"); + if (hasTouchBar) { + this.triggerCommand("refreshTouchBar"); + } } async #onMapClicked(e: LeafletMouseEvent) { diff --git a/src/public/app/widgets/view_widgets/calendar_view.ts b/src/public/app/widgets/view_widgets/calendar_view.ts index bda4d02d4..a5452de66 100644 --- a/src/public/app/widgets/view_widgets/calendar_view.ts +++ b/src/public/app/widgets/view_widgets/calendar_view.ts @@ -8,7 +8,7 @@ import options from "../../services/options.js"; import dialogService from "../../services/dialog.js"; import attributes from "../../services/attributes.js"; import type { CommandListenerData, EventData } from "../../components/app_context.js"; -import utils from "../../services/utils.js"; +import utils, { hasTouchBar } from "../../services/utils.js"; import date_notes from "../../services/date_notes.js"; import appContext from "../../components/app_context.js"; import type { EventImpl } from "@fullcalendar/core/internal"; @@ -269,7 +269,9 @@ export default class CalendarView extends ViewMode { this.debouncedSaveView(); this.lastView = currentView; - appContext.triggerCommand("refreshTouchBar"); + if (hasTouchBar) { + appContext.triggerCommand("refreshTouchBar"); + } } async #onCalendarSelection(e: DateSelectArg) {