Skip to content

Commit

Permalink
fix: enhance document deletion hooks and improve file watching on Win…
Browse files Browse the repository at this point in the history
…dows
  • Loading branch information
purocean committed Feb 5, 2025
1 parent a21175b commit 24448c3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion 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 })
triggerHook('DOC_BEFORE_DELETE', { doc, force: false })
await api.deleteFile(doc, true)
} catch (error: any) {
const force = await useModal().confirm({
Expand All @@ -506,6 +506,7 @@ export async function deleteDoc (doc: PathItem, skipConfirm = false) {

if (force) {
try {
triggerHook('DOC_BEFORE_DELETE', { doc, force: true })
await api.deleteFile(doc, false)
} catch (err: any) {
useToast().show('warning', err.message)
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ function switchDefaultPreviewer () {
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.triggerWatchCurrentRepo()
indexer.stopWatch()
setTimeout(() => {
indexer.triggerWatchCurrentRepo()
}, 500)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ export type BuildInHookTypes = {
EDITOR_CURRENT_EDITOR_CHANGE: { current?: CustomEditor | null },
EDITOR_CONTENT_CHANGE: { uri: string, value: string },
DOC_CREATED: { doc: Doc },
DOC_BEFORE_DELETE: { doc: PathItem },
DOC_BEFORE_DELETE: { doc: PathItem, force: boolean },
DOC_DELETED: { doc: PathItem },
DOC_BEFORE_MOVE: { doc: Doc, newDoc: Doc },
DOC_MOVED: { oldDoc: Doc, newDoc: Doc },
Expand Down

0 comments on commit 24448c3

Please sign in to comment.