Skip to content

Commit

Permalink
feat: hook up with activeTab:change
Browse files Browse the repository at this point in the history
Ensure we only update the templates if an active C8 tab is opened.
  • Loading branch information
nikku committed Aug 21, 2024
1 parent 0e71dcf commit ac05871
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
30 changes: 29 additions & 1 deletion app/lib/connector-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,32 @@ function mergeConnectorTemplates(connectorTemplates, latestConnectorTemplates) {
added,
replaced
};
}
}

const ONE_DAY_MS = 1000 * 60 * 60 * 24;

/**
* @param {import('../util/renderer') } renderer
* @param {string} userPath
*/
function registerConnectorTemplateUpdater(renderer, userPath) {

let shouldUpdate = true;

setInterval(() => {
shouldUpdate = true;
}, ONE_DAY_MS);

const handleTabChange = (newActive) => {

if (newActive?.type === 'cloud-bpmn' && shouldUpdate) {
shouldUpdate = false;

updateConnectorTemplates(renderer, userPath);
}
};

renderer.on('activeTab:change', handleTabChange);
}

module.exports.registerConnectorTemplateUpdater = registerConnectorTemplateUpdater;
6 changes: 2 additions & 4 deletions app/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Workspace = require('./workspace');
const ZeebeAPI = require('./zeebe-api');
const {
getConnectorTemplatesPath,
updateConnectorTemplates
registerConnectorTemplateUpdater
} = require('./connector-templates');

const {
Expand Down Expand Up @@ -694,9 +694,7 @@ function bootstrap() {

// (10) connector templates
if (flags.get('enable-connector-templates', false)) {
app.on('app:client-ready', function() {
updateConnectorTemplates(renderer, userPath);
});
registerConnectorTemplateUpdater(renderer, userPath);
}

return {
Expand Down

0 comments on commit ac05871

Please sign in to comment.