Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process applications #4762

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading