Skip to content

Commit

Permalink
Ignore folders in the folio dir
Browse files Browse the repository at this point in the history
  • Loading branch information
joerick committed Aug 29, 2023
1 parent 1d50c68 commit 9cdde65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions packages/main/src/DirWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class DirWatcher {
lastEventTimes: Record<string, number> = {};

constructor() {
console.log(MY_APP_FOLIO_DIR);
console.log("Folio dir: ", MY_APP_FOLIO_DIR);
// ensure the directory exists
fs.mkdir(MY_APP_FOLIO_DIR, {recursive: true});

Expand Down Expand Up @@ -72,20 +72,25 @@ export default class DirWatcher {
}

async update() {
let filenames = await fs.readdir(MY_APP_FOLIO_DIR);

// filter out ignored files
filenames = filenames.filter(name => !IGNORE_LIST.includes(name));
const filenames = await fs.readdir(MY_APP_FOLIO_DIR);

// populate the files array
const files: FolioFile[] = await Promise.all(filenames.map(async (name) => {
let files = await Promise.all(filenames.map(async (name) => {
const stat = await fs.stat(path.join(MY_APP_FOLIO_DIR, name));
return {
name,
mtime: stat.mtimeMs,
lastEventTime: this.lastEventTimes[name] ?? stat.mtimeMs,
isDir: stat.isDirectory(),
};
}));

// filter out ignored files
files = files.filter(file => !IGNORE_LIST.includes(file.name));

// filter out files that are dirs
files = files.filter(file => !file.isDir);

// sort by lastEventTime, latest first
files.sort((a, b) => b.lastEventTime - a.lastEventTime);
this.files = files;
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/folioProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function registerFolioProtocol() {
app.on('ready', () => {
protocol.registerFileProtocol('folio', (request, callback) => {
const filename = decodeURIComponent(new URL(request.url).pathname)
console.log('folio request filename', filename)
console.log('Served file:', filename)
const filepath = path.join(MY_APP_FOLIO_DIR, filename);
return callback(filepath)
})
Expand Down

0 comments on commit 9cdde65

Please sign in to comment.