Skip to content

Commit

Permalink
fix: make document hooks breakable and improve file watching on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
purocean committed Feb 5, 2025
1 parent 24448c3 commit b42b163
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/renderer/services/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export async function deleteDoc (doc: PathItem, skipConfirm = false) {
}

try {
triggerHook('DOC_BEFORE_DELETE', { doc, force: false })
await triggerHook('DOC_BEFORE_DELETE', { doc, force: false }, { breakable: true })
await api.deleteFile(doc, true)
} catch (error: any) {
const force = await useModal().confirm({
Expand All @@ -506,7 +506,7 @@ export async function deleteDoc (doc: PathItem, skipConfirm = false) {

if (force) {
try {
triggerHook('DOC_BEFORE_DELETE', { doc, force: true })
await triggerHook('DOC_BEFORE_DELETE', { doc, force: true }, { breakable: true })
await api.deleteFile(doc, false)
} catch (err: any) {
useToast().show('warning', err.message)
Expand Down Expand Up @@ -573,7 +573,7 @@ export async function moveDoc (doc: Doc, newPath?: string) {
}

try {
triggerHook('DOC_BEFORE_MOVE', { doc, newDoc })
await triggerHook('DOC_BEFORE_MOVE', { doc, newDoc }, { breakable: true })
await api.moveFile(doc, newPath)
triggerHook('DOC_MOVED', { oldDoc: doc, newDoc })
} catch (error: any) {
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import plugins from '@fe/plugins'
import ctx from '@fe/context'
import ga from '@fe/support/ga'
import * as jsonrpc from '@fe/support/jsonrpc'
import { getLogger } from '@fe/utils'
import { getLogger, sleep } from '@fe/utils'
import { removeOldDatabases } from './others/db'

const logger = getLogger('startup')
Expand Down Expand Up @@ -55,10 +55,11 @@ function switchDefaultPreviewer () {
}
}

function reWatchFsOnWindows ({ doc }: { doc: PathItem & { type?: Doc['type'] }}) {
async function reWatchFsOnWindows ({ doc }: { doc: PathItem & { type?: Doc['type'] }}) {
// fix parent folder rename / delete on Windows https://github.com/paulmillr/chokidar/issues/664
if (isWindows && doc.type === 'dir') {
indexer.stopWatch()
await sleep(50)
setTimeout(() => {
indexer.triggerWatchCurrentRepo()
}, 500)
Expand Down

0 comments on commit b42b163

Please sign in to comment.