Skip to content

Commit

Permalink
electron: Add buttons to open the video folder as well as the cockpit…
Browse files Browse the repository at this point in the history
… folder
  • Loading branch information
rafaellehmkuhl authored and ArturoManzoli committed Dec 17, 2024
1 parent 5273f8f commit ab5a1f9
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 5 deletions.
2 changes: 2 additions & 0 deletions electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ contextBridge.exposeInMainWorld('electronAPI', {
keys: async (subFolders?: string[]) => {
return await ipcRenderer.invoke('keys', { subFolders })
},
openCockpitFolder: () => ipcRenderer.invoke('open-cockpit-folder'),
openVideoFolder: () => ipcRenderer.invoke('open-video-folder'),
})
13 changes: 11 additions & 2 deletions electron/services/storage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ipcMain } from 'electron'
import { ipcMain, shell } from 'electron'
import { app } from 'electron'
import * as fs from 'fs/promises'
import { dirname, join } from 'path'

// Create a new storage interface for filesystem
const cockpitFolderPath = join(app.getPath('home'), 'Cockpit')
export const cockpitFolderPath = join(app.getPath('home'), 'Cockpit')
fs.mkdir(cockpitFolderPath, { recursive: true })

export const filesystemStorage = {
Expand Down Expand Up @@ -58,4 +58,13 @@ export const setupFilesystemStorage = (): void => {
ipcMain.handle('keys', async (_, data) => {
return await filesystemStorage.keys(data.subFolders)
})
ipcMain.handle('open-cockpit-folder', async () => {
await fs.mkdir(cockpitFolderPath, { recursive: true })
await shell.openPath(cockpitFolderPath)
})
ipcMain.handle('open-video-folder', async () => {
const videoFolderPath = join(cockpitFolderPath, 'videos')
await fs.mkdir(videoFolderPath, { recursive: true })
await shell.openPath(videoFolderPath)
})
}
24 changes: 24 additions & 0 deletions src/components/VideoLibraryModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ import { ref, watch } from 'vue'
import { useInteractionDialog } from '@/composables/interactionDialog'
import { useSnackbar } from '@/composables/snackbar'
import { isElectron } from '@/libs/utils'
import { useAppInterfaceStore } from '@/stores/appInterface'
import { useVideoStore } from '@/stores/video'
import { DialogActions } from '@/types/general'
Expand Down Expand Up @@ -580,8 +581,31 @@ const fileActionButtons = computed(() => [
disabled: showOnScreenProgress.value === true || isPreparingDownload.value === true,
action: () => downloadVideoAndTelemetryFiles(),
},
{
name: 'Open Folder',
icon: 'mdi-folder-outline',
size: 28,
tooltip: 'Open videos folder',
confirmAction: false,
show: isElectron(),
disabled: false,
action: () => openVideoFolder(),
},
])
const openVideoFolder = (): void => {
if (isElectron() && window.electronAPI) {
window.electronAPI?.openVideoFolder()
} else {
showSnackbar({
message: 'This feature is only available in the desktop version of Cockpit.',
duration: 3000,
variant: 'error',
closeButton: true,
})
}
}
const closeModal = (): void => {
isVisible.value = false
emits('update:openModal', false)
Expand Down
8 changes: 8 additions & 0 deletions src/libs/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ declare global {
* Register callback for download progress event
*/
onDownloadProgress: (callback: (info: any) => void) => void
/**
* Open cockpit folder
*/
openCockpitFolder: () => void
/**
* Open video folder
*/
openVideoFolder: () => void
}
}
}
Expand Down
32 changes: 29 additions & 3 deletions src/views/ConfigurationGeneralView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,20 @@
@click="missionStore.changeUsername"
/>
</div>
<v-btn size="x-small" class="bg-[#FFFFFF22] -mt-3 mb-4 shadow-2" variant="flat" @click="openTutorial">
Show tutorial
</v-btn>
<div class="flex flex-row">
<v-btn size="x-small" class="bg-[#FFFFFF22] -mt-3 mb-4 shadow-2" variant="flat" @click="openTutorial">
Show tutorial
</v-btn>
<v-btn
v-if="isElectron()"
size="x-small"
class="bg-[#FFFFFF22] -mt-3 mb-4 ml-2 shadow-2"
variant="flat"
@click="openCockpitFolder"
>
Open Cockpit folder
</v-btn>
</div>
</div>
</template>
</ExpansiblePanel>
Expand Down Expand Up @@ -292,6 +303,7 @@ import { onMounted, ref, watch } from 'vue'
import { defaultGlobalAddress } from '@/assets/defaults'
import ExpansiblePanel from '@/components/ExpansiblePanel.vue'
import VehicleDiscoveryDialog from '@/components/VehicleDiscoveryDialog.vue'
import { useSnackbar } from '@/composables/snackbar'
import * as Connection from '@/libs/connection/connection'
import { ConnectionManager } from '@/libs/connection/connection-manager'
import { isValidNetworkAddress, reloadCockpit } from '@/libs/utils'
Expand All @@ -306,6 +318,7 @@ import BaseConfigurationView from './BaseConfigurationView.vue'
const mainVehicleStore = useMainVehicleStore()
const interfaceStore = useAppInterfaceStore()
const missionStore = useMissionStore()
const { showSnackbar } = useSnackbar()
const globalAddressForm = ref()
const globalAddressFormValid = ref(false)
Expand Down Expand Up @@ -517,6 +530,19 @@ onMounted(() => {
})
const showDiscoveryDialog = ref(false)
const openCockpitFolder = (): void => {
if (isElectron() && window.electronAPI) {
window.electronAPI?.openCockpitFolder()
} else {
showSnackbar({
message: 'This feature is only available in the desktop version of Cockpit.',
duration: 3000,
variant: 'error',
closeButton: true,
})
}
}
</script>
<style scoped>
.uri-input {
Expand Down

0 comments on commit ab5a1f9

Please sign in to comment.