diff --git a/src-electron/main/fs.ts b/src-electron/main/fs.ts index e58f4576ea..5c61a6307c 100644 --- a/src-electron/main/fs.ts +++ b/src-electron/main/fs.ts @@ -65,10 +65,14 @@ const watchers = new Set(); const datePattern = /^\d{4}-\d{2}-\d{2}$/; // YYYY-MM-DD export async function unwatchFolders() { - // console.log(_e, path); - watchers.forEach((watcher) => { - watcher.close().then(() => watchers.delete(watcher)); - }); + for (const watcher of watchers) { + try { + if (!watcher?.closed) await watcher?.close(); + watchers.delete(watcher); + } catch (error) { + errorCatcher(error); + } + } } export async function watchFolder(folderPath: string) { @@ -90,7 +94,7 @@ export async function watchFolder(folderPath: string) { ignorePermissionErrors: true, }).on('all', (event, changedPath, stats) => { try { - console.log(event, changedPath); + // console.log(event, changedPath); if (!changedPath || (!stats && !event.includes('unlink'))) return; // Don't do anything if no stats are available or if no path is available const dirPath = toUnix( stats?.isDirectory() || event === 'unlinkDir' diff --git a/src/helpers/jw-media.ts b/src/helpers/jw-media.ts index 0b01e18a96..9319e224a7 100644 --- a/src/helpers/jw-media.ts +++ b/src/helpers/jw-media.ts @@ -820,46 +820,51 @@ const watchedItemMapper: ( parentDate, watchedItemPath, ) => { - if (!parentDate || !watchedItemPath) return undefined; + try { + if (!parentDate || !watchedItemPath) return undefined; - const fileUrl = getFileUrl(watchedItemPath); + const fileUrl = getFileUrl(watchedItemPath); - const video = isVideo(watchedItemPath); - const audio = isAudio(watchedItemPath); - const image = isImage(watchedItemPath); + const video = isVideo(watchedItemPath); + const audio = isAudio(watchedItemPath); + const image = isImage(watchedItemPath); - if (!(video || audio || image)) return undefined; + if (!(video || audio || image)) return undefined; - const duration = - (video || audio) && (await fs.exists(watchedItemPath)) - ? await getDurationFromMediaPath(watchedItemPath) - : 0; + const duration = + (video || audio) && (await fs.exists(watchedItemPath)) + ? await getDurationFromMediaPath(watchedItemPath) + : 0; - const uniqueId = sanitizeId( - formatDate(parentDate, 'YYYYMMDD') + '-' + fileUrl, - ); + const uniqueId = sanitizeId( + formatDate(parentDate, 'YYYYMMDD') + '-' + fileUrl, + ); - const jwStore = useJwStore(); - const currentStateStore = useCurrentStateStore(); - const section = - jwStore.watchedMediaSections?.[currentStateStore.currentCongregation]?.[ - parentDate - ]?.[uniqueId] || 'additional'; - - const thumbnailUrl = await getThumbnailUrl(watchedItemPath); - - return { - duration, - fileUrl, - isAudio: audio, - isImage: image, - isVideo: video, - section, - sectionOriginal: section, // to enable restoring the original section after custom sorting - thumbnailUrl, - title: path.basename(watchedItemPath), - uniqueId, - }; + const jwStore = useJwStore(); + const currentStateStore = useCurrentStateStore(); + const section = + jwStore.watchedMediaSections?.[currentStateStore.currentCongregation]?.[ + parentDate + ]?.[uniqueId] || 'additional'; + + const thumbnailUrl = await getThumbnailUrl(watchedItemPath); + + return { + duration, + fileUrl, + isAudio: audio, + isImage: image, + isVideo: video, + section, + sectionOriginal: section, // to enable restoring the original section after custom sorting + thumbnailUrl, + title: path.basename(watchedItemPath), + uniqueId, + }; + } catch (e) { + errorCatcher(e); + return undefined; + } }; const getWeMedia = async (lookupDate: Date) => {