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

Require confirmation for desktop reinstall #1835

Merged
merged 4 commits into from
Dec 7, 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
26 changes: 24 additions & 2 deletions src/components/dialog/content/ConfirmationDialogContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@click="onConfirm"
icon="pi pi-save"
/>
<template v-else>
<template v-else-if="type === 'dirtyClose'">
<Button
:label="$t('no')"
severity="secondary"
Expand All @@ -35,17 +35,33 @@
/>
<Button :label="$t('save')" @click="onConfirm" icon="pi pi-save" />
</template>
<Button
v-else-if="type === 'reinstall'"
:label="$t('desktopMenu.reinstall')"
severity="warn"
@click="onConfirm"
icon="pi pi-eraser"
/>
<!-- Invalid - just show a close button. -->
<Button
v-else
:label="$t('close')"
severity="primary"
@click="onCancel"
icon="pi pi-times"
/>
</div>
</section>
</template>

<script setup lang="ts">
import Button from 'primevue/button'
import { useDialogStore } from '@/stores/dialogStore'
import type { ConfirmationDialogType } from '@/services/dialogService'

const props = defineProps<{
message: string
type: 'overwrite' | 'delete' | 'dirtyClose'
type: ConfirmationDialogType
onConfirm: (value?: boolean) => void
itemList?: string[]
}>()
Expand All @@ -62,3 +78,9 @@ const onConfirm = () => {
useDialogStore().closeDialog()
}
</script>

<style lang="css" scoped>
.prompt-dialog-content {
white-space: pre-wrap;
}
</style>
15 changes: 11 additions & 4 deletions src/extensions/core/electronAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { t } from '@/i18n'
import { app } from '@/scripts/app'
import { showConfirmationDialog } from '@/services/dialogService'
import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil'
;(async () => {
if (!isElectron()) return
Expand Down Expand Up @@ -101,11 +103,16 @@ import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil'
},
{
id: 'Comfy-Desktop.Reinstall',
label: 'Reinstall',
label: t('desktopMenu.reinstall'),
icon: 'pi pi-refresh',
function() {
// TODO(huchenlei): Add a confirmation dialog.
electronAPI.reinstall()
async function() {
const proceed = await showConfirmationDialog({
message: t('desktopMenu.confirmReinstall'),
title: t('desktopMenu.reinstall'),
type: 'reinstall'
})

if (proceed) electronAPI.reinstall()
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"save": "Save",
"no": "No",
"cancel": "Cancel",
"close": "Close",
"overwrite": "Overwrite",
"customize": "Customize",
"experimental": "BETA",
Expand Down Expand Up @@ -598,7 +599,7 @@
},
"desktopMenu": {
"reinstall": "Reinstall",
"confirmReinstall": "This will clear your extra_models_config.yaml file, and begin installation again. Are you sure?"
"confirmReinstall": "This will clear your extra_models_config.yaml file,\nand begin installation again.\n\nAre you sure?"
},
"settingsCategories": {
"Comfy-Desktop": "Comfy-Desktop",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"box": "ボックス",
"briefcase": "ブリーフケース",
"cancel": "キャンセル",
"close": "閉じる",
"color": "色",
"comingSoon": "近日公開",
"confirm": "確認",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"box": "Ящик",
"briefcase": "Чемодан",
"cancel": "Отмена",
"close": "Закрыть",
"color": "Цвет",
"comingSoon": "Скоро",
"confirm": "Подтвердить",
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"box": "盒子",
"briefcase": "公文包",
"cancel": "取消",
"close": "关闭",
"color": "颜色",
"comingSoon": "敬请期待",
"confirm": "确认",
Expand Down
8 changes: 7 additions & 1 deletion src/services/dialogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export async function showPromptDialog({
})
}

export type ConfirmationDialogType =
| 'overwrite'
| 'delete'
| 'dirtyClose'
| 'reinstall'

/**
*
* @returns `true` if the user confirms the dialog,
Expand All @@ -112,7 +118,7 @@ export async function showConfirmationDialog({
/** Dialog heading */
title: string
/** Pre-configured dialog type */
type: 'overwrite' | 'delete' | 'dirtyClose'
type: ConfirmationDialogType
/** The main message body */
message: string
/** Displayed as an unorderd list immediately below the message body */
Expand Down