chore(touchbar): disable widget on non-mac

This commit is contained in:
Elian Doran 2025-04-13 23:09:14 +03:00
parent 83e7e82252
commit 14516d53c3
No known key found for this signature in database
6 changed files with 28 additions and 15 deletions

View File

@ -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()

View File

@ -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<HTMLCanvasElement>) {
return (!isMac() && evt.ctrlKey) || (isMac() && evt.metaKey);
}

View File

@ -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*/`
<div class="note-detail-code note-detail-printable">
@ -64,7 +65,7 @@ export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget {
this.show();
if (this.parent) {
if (this.parent && hasTouchBar) {
this.triggerCommand("refreshTouchBar");
}
}

View File

@ -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;

View File

@ -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*/`\
<div class="note-detail-geo-map note-detail-printable">
@ -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) {

View File

@ -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) {