Skip to content

Commit

Permalink
App: Startup dialogs: Implement changes to run under dialog queue
Browse files Browse the repository at this point in the history
Signed-off-by: Arturo Manzoli <arturomanzoli@gmail.com>
  • Loading branch information
ArturoManzoli committed Feb 17, 2025
1 parent 0e273d9 commit e352580
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 13 deletions.
16 changes: 14 additions & 2 deletions src/components/Tutorial.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,18 @@ const { openSnackbar } = useSnackbar()
const interfaceStore = useAppInterfaceStore()
const vehicleStore = useMainVehicleStore()
const showTutorial = ref(true)
const props = defineProps<{
/**
*
*/
modelValue: boolean
}>()
const emit = defineEmits<{
(e: 'update:modelValue', value: boolean): void
}>()
const showTutorial = ref(false || props.modelValue)
const currentTutorialStep = useStorage('cockpit-last-tutorial-step', 1)
const isVehicleConnectedVisible = ref(false)
const tallContent = ref(false)
Expand Down Expand Up @@ -316,6 +327,7 @@ const handleStepChange = (newStep: number): void => {
const dontShowTutorialAgain = (): void => {
interfaceStore.userHasSeenTutorial = true
showTutorial.value = false
emit('update:modelValue', false)
currentTutorialStep.value = 1
openSnackbar({
message: 'This guide can be reopened via the Settings > General menu',
Expand Down Expand Up @@ -348,8 +360,8 @@ const backTutorialStep = (): void => {
const closeTutorial = (): void => {
showTutorial.value = false
interfaceStore.componentToHighlight = 'none'
interfaceStore.userHasSeenTutorial = true
interfaceStore.isTutorialVisible = false
emit('update:modelValue', false)
}
const setVehicleConnectedVisible = (): void => {
Expand Down
57 changes: 46 additions & 11 deletions src/components/UpdateNotification.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<InteractionDialog
v-model="showUpdateDialog"
:show-dialog="showUpdateDialog"
:title="dialogTitle"
:message="dialogMessage"
:variant="dialogVariant"
Expand All @@ -27,17 +27,33 @@
</template>
</v-progress-linear>
</template>
<template #actions>
<v-btn variant="text" size="small" @click="handleCloseDialog">Close</v-btn>
</template>
</InteractionDialog>
</template>

<script setup lang="ts">
import { useStorage } from '@vueuse/core'
import { onBeforeMount, ref } from 'vue'
import { onBeforeMount, onMounted, ref } from 'vue'
import InteractionDialog, { type Action } from '@/components/InteractionDialog.vue'
import { openSnackbar } from '@/composables/snackbar'
import { app_version } from '@/libs/cosmos'
import { isElectron } from '@/libs/utils'
const props = defineProps<{
/**
*
*/
modelValue: boolean
}>()
const emit = defineEmits<{
(e: 'update:modelValue', value: boolean): void
}>()
const updateAvailable = ref(false)
const showUpdateDialog = ref(false)
const dialogTitle = ref('')
const dialogMessage = ref('')
Expand All @@ -52,6 +68,23 @@ const updateInfo = ref({
})
const ignoredUpdateVersions = useStorage<string[]>('cockpit-ignored-update-versions', [])
// Wait for 2 seconds for updates. If no updates are available, show a message and emit close.
onMounted(() => {
setTimeout(() => {
if (props.modelValue && updateAvailable.value) {
showUpdateDialog.value = true
} else {
openSnackbar({ message: 'No updates available.', variant: 'success' })
emit('update:modelValue', false)
}
}, 2000)
})
const handleCloseDialog = (): void => {
emit('update:modelValue', false)
showUpdateDialog.value = false
}
const formatDate = (date: string): string => {
return new Date(date).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })
}
Expand All @@ -75,7 +108,7 @@ onBeforeMount(() => {
dialogVariant.value = 'info'
dialogActions.value = []
showProgress.value = false
showUpdateDialog.value = true
updateAvailable.value = true
})
window.electronAPI.onUpdateNotAvailable(() => {
Expand All @@ -87,11 +120,12 @@ onBeforeMount(() => {
{
text: 'OK',
action: () => {
showUpdateDialog.value = false
handleCloseDialog()
},
},
]
showProgress.value = false
updateAvailable.value = false
})
window.electronAPI.onUpdateAvailable((info) => {
Expand All @@ -107,7 +141,7 @@ onBeforeMount(() => {
console.log(`User chose to ignore version ${updateInfo.value.version}`)
ignoredUpdateVersions.value.push(updateInfo.value.version)
window.electronAPI!.cancelUpdate()
showUpdateDialog.value = false
handleCloseDialog()
},
},
{
Expand All @@ -121,7 +155,7 @@ onBeforeMount(() => {
action: () => {
console.log('User chose to cancel the update for the Electron app.')
window.electronAPI!.cancelUpdate()
showUpdateDialog.value = false
handleCloseDialog()
dialogMessage.value = 'Downloading update...'
},
},
Expand All @@ -132,19 +166,20 @@ onBeforeMount(() => {
text: 'Not Now',
action: () => {
window.electronAPI!.cancelUpdate()
showUpdateDialog.value = false
handleCloseDialog()
},
},
]
// Check if this version is in the ignored list
if (ignoredUpdateVersions.value.includes(info.version)) {
console.log(`Skipping ignored version ${info.version}.`)
showUpdateDialog.value = false
handleCloseDialog()
return
}
showUpdateDialog.value = true
updateAvailable.value = true
})
window.electronAPI.onDownloadProgress((progressInfo) => {
Expand All @@ -171,11 +206,11 @@ onBeforeMount(() => {
text: 'Later',
action: () => {
console.log('User chose to install the update for the Electron app later.')
showUpdateDialog.value = false
handleCloseDialog()
},
},
]
showUpdateDialog.value = true
updateAvailable.value = true
})
})
</script>

0 comments on commit e352580

Please sign in to comment.