Skip to content

Commit f84c5d9

Browse files
refactor usage of isElectron to use isDesktop
1 parent d1639c4 commit f84c5d9

File tree

27 files changed

+105
-99
lines changed

27 files changed

+105
-99
lines changed

apps/desktop-ui/src/components/bottomPanel/tabs/terminal/BaseTerminal.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
22
<div
33
ref="rootEl"
4-
class="relative overflow-hidden h-full w-full bg-neutral-900"
4+
class="relative h-full w-full overflow-hidden bg-neutral-900"
55
>
6-
<div class="p-terminal rounded-none h-full w-full p-2">
7-
<div ref="terminalEl" class="h-full terminal-host" />
6+
<div class="p-terminal h-full w-full rounded-none p-2">
7+
<div ref="terminalEl" class="terminal-host h-full" />
88
</div>
99
<Button
1010
v-tooltip.left="{
@@ -26,6 +26,7 @@
2626
</template>
2727

2828
<script setup lang="ts">
29+
import { isDesktop } from '@frontend/platform/distribution/types'
2930
import { useElementHover, useEventListener } from '@vueuse/core'
3031
import type { IDisposable } from '@xterm/xterm'
3132
import Button from 'primevue/button'
@@ -34,7 +35,7 @@ import { computed, onMounted, onUnmounted, ref } from 'vue'
3435
import { useI18n } from 'vue-i18n'
3536
3637
import { useTerminal } from '@/composables/bottomPanelTabs/useTerminal'
37-
import { electronAPI, isElectron } from '@/utils/envUtil'
38+
import { electronAPI } from '@/utils/envUtil'
3839
import { cn } from '@/utils/tailwindUtil'
3940
4041
const { t } = useI18n()
@@ -84,7 +85,7 @@ const showContextMenu = (event: MouseEvent) => {
8485
electronAPI()?.showContextMenu({ type: 'text' })
8586
}
8687
87-
if (isElectron()) {
88+
if (isDesktop) {
8889
useEventListener(terminalEl, 'contextmenu', showContextMenu)
8990
}
9091

apps/desktop-ui/src/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import { isDesktop } from '@frontend/platform/distribution/types'
12
import {
23
createRouter,
34
createWebHashHistory,
45
createWebHistory
56
} from 'vue-router'
67

7-
import { isElectron } from '@/utils/envUtil'
88
import LayoutDefault from '@/views/layouts/LayoutDefault.vue'
99

1010
const isFileProtocol = window.location.protocol === 'file:'
11-
const basePath = isElectron() ? '/' : window.location.pathname
11+
const basePath = isDesktop ? '/' : window.location.pathname
1212

1313
const router = createRouter({
1414
history: isFileProtocol ? createWebHashHistory() : createWebHistory(basePath),
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
1-
import type { ElectronAPI } from '@comfyorg/comfyui-electron-types'
2-
3-
export function isElectron() {
4-
return 'electronAPI' in window && window.electronAPI !== undefined
5-
}
6-
7-
export function electronAPI() {
8-
return (window as any).electronAPI as ElectronAPI
9-
}
10-
11-
export function isNativeWindow() {
12-
return isElectron() && !!window.navigator.windowControlsOverlay?.visible
13-
}
1+
export { electronAPI, isNativeWindow } from '@frontend/utils/envUtil'

apps/desktop-ui/src/views/templates/BaseViewTemplate.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
<template>
22
<div
3-
class="font-sans w-screen h-screen flex flex-col"
3+
class="flex h-screen w-screen flex-col font-sans"
44
:class="[
55
dark
6-
? 'text-neutral-300 bg-neutral-900 dark-theme'
7-
: 'text-neutral-900 bg-neutral-300'
6+
? 'dark-theme bg-neutral-900 text-neutral-300'
7+
: 'bg-neutral-300 text-neutral-900'
88
]"
99
>
1010
<!-- Virtual top menu for native window (drag handle) -->
1111
<div
1212
v-show="isNativeWindow()"
1313
ref="topMenuRef"
14-
class="app-drag w-full h-(--comfy-topbar-height)"
14+
class="app-drag h-(--comfy-topbar-height) w-full"
1515
/>
16-
<div class="grow w-full flex items-center justify-center overflow-auto">
16+
<div class="flex w-full grow items-center justify-center overflow-auto">
1717
<slot />
1818
</div>
1919
</div>
2020
</template>
2121

2222
<script setup lang="ts">
23+
import { isDesktop } from '@frontend/platform/distribution/types'
2324
import { nextTick, onMounted, ref } from 'vue'
2425
25-
import { electronAPI, isElectron, isNativeWindow } from '../../utils/envUtil'
26+
import { electronAPI, isNativeWindow } from '../../utils/envUtil'
2627
2728
const { dark = false } = defineProps<{
2829
dark?: boolean
@@ -40,7 +41,7 @@ const lightTheme = {
4041
4142
const topMenuRef = ref<HTMLDivElement | null>(null)
4243
onMounted(async () => {
43-
if (isElectron()) {
44+
if (isDesktop) {
4445
await nextTick()
4546
4647
electronAPI().changeTheme({

apps/desktop-ui/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"baseUrl": ".",
77
"paths": {
88
"@/*": ["src/*"],
9+
"@frontend/*": ["../../src/*"],
910
"@frontend-locales/*": ["../../src/locales/*"]
1011
}
1112
},

apps/desktop-ui/vite.config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default defineConfig(() => {
3131
resolve: {
3232
alias: {
3333
'@': path.resolve(projectRoot, 'src'),
34+
'@frontend': path.resolve(projectRoot, '../../src'),
3435
'@frontend-locales': path.resolve(projectRoot, '../../src/locales')
3536
}
3637
},

src/App.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import { computed, onMounted } from 'vue'
1616
1717
import GlobalDialog from '@/components/dialog/GlobalDialog.vue'
1818
import config from '@/config'
19+
import { isDesktop } from '@/platform/distribution/types'
1920
import { useWorkspaceStore } from '@/stores/workspaceStore'
2021
import { useConflictDetection } from '@/workbench/extensions/manager/composables/useConflictDetection'
2122
22-
import { electronAPI, isElectron } from './utils/envUtil'
23+
import { electronAPI } from './utils/envUtil'
2324
2425
const workspaceStore = useWorkspaceStore()
2526
const conflictDetection = useConflictDetection()
@@ -45,7 +46,7 @@ onMounted(() => {
4546
// @ts-expect-error fixme ts strict error
4647
window['__COMFYUI_FRONTEND_VERSION__'] = config.app_version
4748
48-
if (isElectron()) {
49+
if (isDesktop) {
4950
document.addEventListener('contextmenu', showContextMenu)
5051
}
5152

src/components/bottomPanel/tabs/terminal/BaseTerminal.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import { computed, onMounted, onUnmounted, ref } from 'vue'
3434
import { useI18n } from 'vue-i18n'
3535
3636
import { useTerminal } from '@/composables/bottomPanelTabs/useTerminal'
37-
import { electronAPI, isElectron } from '@/utils/envUtil'
37+
import { isDesktop } from '@/platform/distribution/types'
38+
import { electronAPI } from '@/utils/envUtil'
3839
import { cn } from '@/utils/tailwindUtil'
3940
4041
const { t } = useI18n()
@@ -84,7 +85,7 @@ const showContextMenu = (event: MouseEvent) => {
8485
electronAPI()?.showContextMenu({ type: 'text' })
8586
}
8687
87-
if (isElectron()) {
88+
if (isDesktop) {
8889
useEventListener(terminalEl, 'contextmenu', showContextMenu)
8990
}
9091

src/components/dialog/content/MissingModelsWarning.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</div>
1414
<ListBox :options="missingModels" class="comfy-missing-models">
1515
<template #option="{ option }">
16-
<Suspense v-if="isElectron()">
16+
<Suspense v-if="isDesktop">
1717
<ElectronFileDownload
1818
:url="option.url"
1919
:label="option.label"
@@ -39,8 +39,8 @@ import { useI18n } from 'vue-i18n'
3939
import ElectronFileDownload from '@/components/common/ElectronFileDownload.vue'
4040
import FileDownload from '@/components/common/FileDownload.vue'
4141
import NoResultsPlaceholder from '@/components/common/NoResultsPlaceholder.vue'
42+
import { isDesktop } from '@/platform/distribution/types'
4243
import { useSettingStore } from '@/platform/settings/settingStore'
43-
import { isElectron } from '@/utils/envUtil'
4444
4545
// TODO: Read this from server internal API rather than hardcoding here
4646
// as some installations may wish to use custom sources

src/components/helpcenter/HelpCenterMenuContent.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ import type { CSSProperties, Component } from 'vue'
135135
import { useI18n } from 'vue-i18n'
136136
137137
import PuzzleIcon from '@/components/icons/PuzzleIcon.vue'
138-
import { isCloud } from '@/platform/distribution/types'
138+
import { isCloud, isDesktop } from '@/platform/distribution/types'
139139
import { useSettingStore } from '@/platform/settings/settingStore'
140140
import type { ReleaseNote } from '@/platform/updates/common/releaseService'
141141
import { useReleaseStore } from '@/platform/updates/common/releaseStore'
142142
import { useCommandStore } from '@/stores/commandStore'
143-
import { electronAPI, isElectron } from '@/utils/envUtil'
143+
import { electronAPI } from '@/utils/envUtil'
144144
import { formatVersionAnchor } from '@/utils/formatUtil'
145145
import { useConflictAcknowledgment } from '@/workbench/extensions/manager/composables/useConflictAcknowledgment'
146146
import { useManagerState } from '@/workbench/extensions/manager/composables/useManagerState'
@@ -216,7 +216,7 @@ const moreItems = computed<MenuItem[]>(() => {
216216
key: 'desktop-guide',
217217
type: 'item',
218218
label: t('helpCenter.desktopUserGuide'),
219-
visible: isElectron(),
219+
visible: isDesktop,
220220
action: () => {
221221
const docsUrl =
222222
electronAPI().getPlatform() === 'darwin'
@@ -230,7 +230,7 @@ const moreItems = computed<MenuItem[]>(() => {
230230
key: 'dev-tools',
231231
type: 'item',
232232
label: t('helpCenter.openDevTools'),
233-
visible: isElectron(),
233+
visible: isDesktop,
234234
action: () => {
235235
openDevTools()
236236
emit('close')
@@ -239,13 +239,13 @@ const moreItems = computed<MenuItem[]>(() => {
239239
{
240240
key: 'divider-1',
241241
type: 'divider',
242-
visible: isElectron()
242+
visible: isDesktop
243243
},
244244
{
245245
key: 'reinstall',
246246
type: 'item',
247247
label: t('helpCenter.reinstall'),
248-
visible: isElectron(),
248+
visible: isDesktop,
249249
action: () => {
250250
onReinstall()
251251
emit('close')
@@ -484,13 +484,13 @@ const onSubmenuLeave = (): void => {
484484
}
485485
486486
const openDevTools = (): void => {
487-
if (isElectron()) {
487+
if (isDesktop) {
488488
electronAPI().openDevTools()
489489
}
490490
}
491491
492492
const onReinstall = (): void => {
493-
if (isElectron()) {
493+
if (isDesktop) {
494494
void electronAPI().reinstall()
495495
}
496496
}

0 commit comments

Comments
 (0)