From c655cfffd603d3bd29ba5efcfbf5326e99396b8d Mon Sep 17 00:00:00 2001 From: phibr0 Date: Tue, 5 Jul 2022 10:26:42 +0200 Subject: [PATCH] Hide commands of other devices, fix support button not working on mobile because of electron dependency --- src/ui/components/commandComponent.tsx | 2 +- src/ui/components/commandViewerComponent.tsx | 66 ++++++++++---------- src/ui/components/settingTabComponent.tsx | 3 +- src/util.tsx | 1 - 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/ui/components/commandComponent.tsx b/src/ui/components/commandComponent.tsx index fc043ea..5376f9a 100644 --- a/src/ui/components/commandComponent.tsx +++ b/src/ui/components/commandComponent.tsx @@ -28,7 +28,7 @@ export default function CommandComponent({ pair, handleRemove, handleDown, handl const isChecked = cmd.hasOwnProperty("checkCallback") || cmd.hasOwnProperty("editorCheckCallback"); const modeIcon = getModeIcon(pair.mode); - const modeName = pair.mode.match(/desktop|mobile|any/) ? pair.mode[0].toUpperCase() + pair.mode.substring(1) : `Device ${pair.mode}`; + const modeName = pair.mode.match(/desktop|mobile|any/) ? pair.mode[0].toUpperCase() + pair.mode.substring(1) : `This device`; return ( diff --git a/src/ui/components/commandViewerComponent.tsx b/src/ui/components/commandViewerComponent.tsx index 2e414bc..ba9f4e6 100644 --- a/src/ui/components/commandViewerComponent.tsx +++ b/src/ui/components/commandViewerComponent.tsx @@ -3,10 +3,11 @@ import CommanderPlugin from "src/main"; import CommandComponent from "./commandComponent"; import logo from "src/assets/commander-logo.svg"; import CommandManager from "src/manager/_commandManager"; -import { chooseNewCommand } from "src/util"; +import { chooseNewCommand, isModeActive } from "src/util"; import { arrayMoveMutable } from "array-move"; import ChooseIconModal from "../chooseIconModal"; import ConfirmDeleteModal from "../confirmDeleteModal"; +import { CommandIconPair } from "src/types"; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion export const ManagerContext = createContext(null!); @@ -20,41 +21,42 @@ export default function CommandViewer({ manager, plugin }: CommandViewerProps): {manager.pairs.map((cmd, idx) => { - return => { - if (!plugin.settings.confirmDeletion || await new ConfirmDeleteModal(plugin).didChooseRemove()) { - await manager.removeCommand(cmd); this.forceUpdate(); - } - }} - handleUp={(): void => { arrayMoveMutable(manager.pairs, idx, idx - 1); manager.reorder(); this.forceUpdate(); }} - handleDown={(): void => { arrayMoveMutable(manager.pairs, idx, idx + 1); manager.reorder(); this.forceUpdate(); }} - handleRename={async (name): Promise => { cmd.name = name; await plugin.saveSettings(); manager.reorder(); this.forceUpdate(); }} - handleNewIcon={async (): Promise => { - const newIcon = await (new ChooseIconModal(plugin)).awaitSelection(); - if (newIcon && newIcon !== cmd.icon) { - cmd.icon = newIcon; + if (cmd.mode.match(/desktop|mobile|any/) || cmd.mode === app.appId) { + return => { + if (!plugin.settings.confirmDeletion || await new ConfirmDeleteModal(plugin).didChooseRemove()) { + await manager.removeCommand(cmd); this.forceUpdate(); + } + }} + handleUp={(): void => { arrayMoveMutable(manager.pairs, idx, idx - 1); manager.reorder(); this.forceUpdate(); }} + handleDown={(): void => { arrayMoveMutable(manager.pairs, idx, idx + 1); manager.reorder(); this.forceUpdate(); }} + handleRename={async (name): Promise => { cmd.name = name; await plugin.saveSettings(); manager.reorder(); this.forceUpdate(); }} + handleNewIcon={async (): Promise => { + const newIcon = await (new ChooseIconModal(plugin)).awaitSelection(); + if (newIcon && newIcon !== cmd.icon) { + cmd.icon = newIcon; + await plugin.saveSettings(); + manager.reorder(); + this.forceUpdate(); + } + }} + handleModeChange={async (): Promise => { + // This is the rotation + const modes = ["any", "desktop", "mobile", app.appId]; + let currentIdx = modes.indexOf(cmd.mode); + if (currentIdx === 3) currentIdx = -1; + + cmd.mode = modes[currentIdx + 1]; await plugin.saveSettings(); manager.reorder(); this.forceUpdate(); - } - }} - handleModeChange={async (): Promise => { - // This is the rotation - const modes = ["any", "desktop", "mobile", app.appId]; - let currentIdx = modes.indexOf(cmd.mode); - if (currentIdx === 3) currentIdx = -1; - - cmd.mode = modes[currentIdx + 1]; - await plugin.saveSettings(); - manager.reorder(); - this.forceUpdate(); - }} - />; + }} + />; + } })} - - {manager.pairs.length === 0 &&
+ {!manager.pairs.some((pre) => isModeActive(pre.mode)) &&
{/* This isn't really dangerous, as the svg is inserted at build time and no other data can be passed to it */}
diff --git a/src/ui/components/settingTabComponent.tsx b/src/ui/components/settingTabComponent.tsx index 770c492..f01f525 100644 --- a/src/ui/components/settingTabComponent.tsx +++ b/src/ui/components/settingTabComponent.tsx @@ -123,8 +123,7 @@ export default function settingTabComponent({ plugin, mobileMode }: { plugin: Co // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const pos = coffeeIcon.current!.getBoundingClientRect(); - // eslint-disable-next-line @typescript-eslint/no-var-requires - setTimeout(() => require('electron').shell.openExternal("https://buymeacoffee.com/phibr0"), 800); + setTimeout(() => location.replace("https://buymeacoffee.com/phibr0"), 800); await myConfetti({ particleCount: 150, diff --git a/src/util.tsx b/src/util.tsx index b71c5d2..f56c81f 100644 --- a/src/util.tsx +++ b/src/util.tsx @@ -6,7 +6,6 @@ import { Command, setIcon } from 'obsidian'; import ChooseCustomNameModal from './ui/chooseCustomNameModal'; import { ComponentProps, h } from 'preact'; import { useRef, useEffect } from 'preact/hooks'; -import { HTMLAttributes } from 'react'; /** * It creates a modal, waits for the user to select a command, and then creates another modal to wait