Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native context menu when using desktop #1875

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
},
"dependencies": {
"@atlaskit/pragmatic-drag-and-drop": "^1.3.1",
"@comfyorg/comfyui-electron-types": "^0.3.25",
"@comfyorg/comfyui-electron-types": "^0.3.32",
"@comfyorg/litegraph": "^0.8.44",
"@primevue/themes": "^4.0.5",
"@vueuse/core": "^11.0.0",
Expand Down
16 changes: 16 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import BlockUI from 'primevue/blockui'
import ProgressSpinner from 'primevue/progressspinner'
import GlobalDialog from '@/components/dialog/GlobalDialog.vue'
import { useEventListener } from '@vueuse/core'
import { isElectron, showNativeMenu } from './utils/envUtil'

const workspaceStore = useWorkspaceStore()
const isLoading = computed<boolean>(() => workspaceStore.spinner)
Expand All @@ -25,8 +26,23 @@ const handleKey = (e: KeyboardEvent) => {
useEventListener(window, 'keydown', handleKey)
useEventListener(window, 'keyup', handleKey)

const showContextMenu = (event: PointerEvent) => {
const { target } = event
switch (true) {
case target instanceof HTMLTextAreaElement:
case target instanceof HTMLInputElement && target.type === 'text':
// TODO: Context input menu explicitly for text input
showNativeMenu({ type: 'text' })
return
}
}

onMounted(() => {
window['__COMFYUI_FRONTEND_VERSION__'] = config.app_version
console.log('ComfyUI Front-end version:', config.app_version)

if (isElectron()) {
document.addEventListener('contextmenu', showContextMenu)
}
})
</script>
2 changes: 2 additions & 0 deletions src/components/MenuHamburger.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
size="large"
v-tooltip="{ value: $t('menu.showMenu'), showDelay: 300 }"
@click="exitFocusMode"
@contextmenu="showNativeMenu"
/>
</template>

Expand All @@ -18,6 +19,7 @@ import { useWorkspaceStore } from '@/stores/workspaceStore'
import { computed, CSSProperties, watchEffect } from 'vue'
import { app } from '@/scripts/app'
import { useSettingStore } from '@/stores/settingStore'
import { showNativeMenu } from '@/utils/envUtil'
huchenlei marked this conversation as resolved.
Show resolved Hide resolved

const workspaceState = useWorkspaceStore()
const settingStore = useSettingStore()
Expand Down
2 changes: 2 additions & 0 deletions src/components/topbar/TopMenubar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
text
v-tooltip="{ value: $t('menu.hideMenu'), showDelay: 300 }"
@click="workspaceState.focusMode = true"
@contextmenu="showNativeMenu"
/>
</div>
</teleport>
Expand All @@ -38,6 +39,7 @@ import { useSettingStore } from '@/stores/settingStore'
import { app } from '@/scripts/app'
import { useEventBus } from '@vueuse/core'
import { useWorkspaceStore } from '@/stores/workspaceStore'
import { showNativeMenu } from '@/utils/envUtil'

const workspaceState = useWorkspaceStore()
const settingStore = useSettingStore()
Expand Down
5 changes: 5 additions & 0 deletions src/utils/envUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ export function isElectron() {
export function electronAPI() {
return (window as any)['electronAPI'] as ElectronAPI
}

type NativeContextOptions = Parameters<ElectronAPI['showContextMenu']>[0]
export function showNativeMenu(options?: NativeContextOptions) {
electronAPI()?.showContextMenu(options)
}
Loading