feat(desktop): open task in main window with Ctrl/Cmd+Enter
When creating a task via quick entry, pressing Ctrl+Enter (or Cmd+Enter on macOS) creates the task and opens it in the main Vikunja window. Adds show-main-window IPC to bring the main window to focus.
This commit is contained in:
parent
37389d6bdb
commit
c8349df8b6
|
|
@ -4,4 +4,5 @@ const { contextBridge, ipcRenderer } = require('electron')
|
||||||
contextBridge.exposeInMainWorld('quickEntry', {
|
contextBridge.exposeInMainWorld('quickEntry', {
|
||||||
close: () => ipcRenderer.send('quick-entry:close'),
|
close: () => ipcRenderer.send('quick-entry:close'),
|
||||||
resize: (width, height) => ipcRenderer.send('quick-entry:resize', width, height),
|
resize: (width, height) => ipcRenderer.send('quick-entry:resize', width, height),
|
||||||
|
showMainWindow: () => ipcRenderer.send('quick-entry:show-main-window'),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import {watch, computed, onBeforeUnmount} from 'vue'
|
import {watch, computed, onBeforeUnmount} from 'vue'
|
||||||
import {useRoute} from 'vue-router'
|
import {useRoute, useRouter} from 'vue-router'
|
||||||
|
|
||||||
import Navigation from '@/components/home/Navigation.vue'
|
import Navigation from '@/components/home/Navigation.vue'
|
||||||
import QuickActions from '@/components/quick-actions/QuickActions.vue'
|
import QuickActions from '@/components/quick-actions/QuickActions.vue'
|
||||||
|
|
@ -107,6 +107,7 @@ function showKeyboardShortcuts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
// FIXME: this is really error prone
|
// FIXME: this is really error prone
|
||||||
// Reset the current project highlight in menu if the current route is not project related.
|
// Reset the current project highlight in menu if the current route is not project related.
|
||||||
|
|
@ -143,8 +144,10 @@ projectStore.loadAllProjects()
|
||||||
|
|
||||||
// Listen for task creation from the quick-entry window
|
// Listen for task creation from the quick-entry window
|
||||||
const taskUpdateChannel = new BroadcastChannel('vikunja-task-updates')
|
const taskUpdateChannel = new BroadcastChannel('vikunja-task-updates')
|
||||||
taskUpdateChannel.onmessage = () => {
|
taskUpdateChannel.onmessage = (event) => {
|
||||||
// Handled by later commits (e.g. open task in main window)
|
if (event.data?.type === 'task-created-open' && event.data?.taskId) {
|
||||||
|
router.push({name: 'task.detail', params: {id: event.data.taskId}})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
@keyup="search"
|
@keyup="search"
|
||||||
@keydown.down.prevent="select(0, 0)"
|
@keydown.down.prevent="select(0, 0)"
|
||||||
@keyup.prevent.delete="unselectCmd"
|
@keyup.prevent.delete="unselectCmd"
|
||||||
@keyup.prevent.enter="doCmd"
|
@keydown.prevent.enter="onEnter"
|
||||||
@keyup.prevent.esc="closeQuickActions"
|
@keyup.prevent.esc="closeQuickActions"
|
||||||
>
|
>
|
||||||
<QuickAddMagic
|
<QuickAddMagic
|
||||||
|
|
@ -572,14 +572,23 @@ async function doAction(type: ACTION_TYPE, item: DoAction) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let openTaskAfterCreate = false
|
||||||
|
|
||||||
|
function onEnter(event: KeyboardEvent) {
|
||||||
|
openTaskAfterCreate = event.ctrlKey || event.metaKey
|
||||||
|
doCmd()
|
||||||
|
}
|
||||||
|
|
||||||
async function doCmd() {
|
async function doCmd() {
|
||||||
if (results.value.length === 1 && results.value[0].items.length === 1) {
|
if (results.value.length === 1 && results.value[0].items.length === 1) {
|
||||||
const result = results.value[0]
|
const result = results.value[0]
|
||||||
doAction(result.type, result.items[0])
|
doAction(result.type, result.items[0])
|
||||||
|
openTaskAfterCreate = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedCmd.value === null || query.value === '') {
|
if (selectedCmd.value === null || query.value === '') {
|
||||||
|
openTaskAfterCreate = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -602,9 +611,16 @@ async function newTask() {
|
||||||
|
|
||||||
if (isQuickAddMode) {
|
if (isQuickAddMode) {
|
||||||
const channel = new BroadcastChannel('vikunja-task-updates')
|
const channel = new BroadcastChannel('vikunja-task-updates')
|
||||||
channel.postMessage({type: 'task-created', taskId: task.id})
|
const type = openTaskAfterCreate ? 'task-created-open' : 'task-created'
|
||||||
|
channel.postMessage({type, taskId: task.id})
|
||||||
channel.close()
|
channel.close()
|
||||||
|
|
||||||
|
if (openTaskAfterCreate) {
|
||||||
|
window.quickEntry?.showMainWindow()
|
||||||
|
}
|
||||||
|
|
||||||
closeQuickActions()
|
closeQuickActions()
|
||||||
|
openTaskAfterCreate = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,6 @@ interface Window {
|
||||||
quickEntry?: {
|
quickEntry?: {
|
||||||
close: () => void
|
close: () => void
|
||||||
resize: (width: number, height: number) => void
|
resize: (width: number, height: number) => void
|
||||||
|
showMainWindow: () => void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue