Skip to content

Commit

Permalink
feat: process applications
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Dec 13, 2024
1 parent a9e53f8 commit 761c6ab
Show file tree
Hide file tree
Showing 31 changed files with 3,640 additions and 28,169 deletions.
3 changes: 2 additions & 1 deletion app/lib/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Dialog {
showOpenDialog(options) {
const {
filters,
properties,
title
} = options;

Expand All @@ -117,7 +118,7 @@ class Dialog {
return this.electronDialog.showOpenDialog(this.browserWindow, {
defaultPath,
filters,
properties: [ 'openFile', 'multiSelections' ],
properties: properties || [ 'openFile', 'multiSelections' ],
title: title || 'Open File'
}).then(response => {

Expand Down
163 changes: 163 additions & 0 deletions app/lib/file-context/file-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/

const { EventEmitter } = require('node:events');

const {
toFileUrl
} = require('./util');

const Indexer = require('./indexer.js');
const Processor = require('./processor.js');
const Watcher = require('./watcher.js');
const Workqueue = require('./workqueue.js');

/**
* @typedef { import('./types').Processor } Processor
* @typedef { {
* watch: boolean;
* processors: Processor[];
* } } FileContextOptions
*/

const DEFAULT_PROCESSORS = require('./processors');

const DEFAULT_OPTIONS = {
watch: true,
processors: DEFAULT_PROCESSORS
};

/**
* File context that indexes and processes files.
*/
module.exports = class FileContext extends EventEmitter {

/**
* @param {import('./types.js').Logger} logger
* @param {FileContextOptions} [options]
*/
constructor(logger, options = DEFAULT_OPTIONS) {
super();

const { processors } = options;

this._logger = logger;

this._workqueue = new Workqueue(this);
this._processor = new Processor(logger, processors);
this._indexer = new Indexer(logger, this, this._processor, this._workqueue);

this._init(options);
}

/**
* Add root
*
* @param {string} uri
*/
addRoot(uri) {
return this._indexer.addRoot(toFileUrl(uri));
}

/**
* Remove root
*
* @param {string} uri
*/
removeRoot(uri) {
return this._indexer.removeRoot(toFileUrl(uri));
}

/**
* Add file
*
* @param {string} uri
*/
addFile(uri) {
return this._indexer.add(toFileUrl(uri));
}

/**
* Notify file changed
*
* @param {string} uri
*/
updateFile(uri) {
return this.addFile(toFileUrl(uri));
}

/**
* Remove file
*
* @param {string} uri
*/
removeFile(uri) {
return this._indexer.remove(toFileUrl(uri));
}

/**
* Notify file opened
*
* @param { { uri: string, value: string } } fileProps
*/
fileOpened(fileProps) {
return this._indexer.fileOpened(fileProps);
}

/**
* Notify file content changed
*
* @param { { uri: string, value: string } } fileProps
*/
fileContentChanged(fileProps) {
return this._indexer.fileContentChanged(fileProps);
}

/**
* Notify file closed
*
* @param {string} uri
*/
fileClosed(uri) {
return this._indexer.fileClosed(toFileUrl(uri));
}

/**
* @return { Promise<Void> }
*/
close() {
if (this._watcher) {
return this._watcher.close();
}

return Promise.resolve();
}

/**
* @param {FileContextOptions} options
*/
_init(options = {}) {
const {
processors,
watch = true
} = options;

if (watch) {
this._watcher = new Watcher(this._logger, this, processors);

this.once('watcher:ready', () => {
this.once('workqueue:empty', () => this.emit('ready'));
});
} else {
this.once('workqueue:empty', () => this.emit('ready'));
}
}

};
Loading

0 comments on commit 761c6ab

Please sign in to comment.