Skip to content

Commit

Permalink
simplify init logic
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Nov 2, 2024
1 parent b0a8330 commit 6a1474e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Logger.initializeGlobalLogger(globalLogger);

const logger = Logger.create('YesYouCan: Index');

const noteUpdateQueue = new AsyncActionQueue(200);
const noteUpdateQueue = new AsyncActionQueue(100);

const newNoteBody = `# Backlog
Expand Down Expand Up @@ -47,23 +47,25 @@ joplin.plugins.register({
const makeNoteUpdateAction = () => {
return async () => {
const note = await joplin.workspace.selectedNote();

logger.info('makeNoteUpdateAction: Handling note: ' + note.id);

if (!noteIsBoard(note ? note.body : '')) {
logger.info('Note is not a Kanban board - hiding panel');
logger.info('Note is not a Kanban board - disactivating editor...');
await panels.setActive(view, false);
panelEnabled = false;
panelReady = false;
return;
}

logger.info('Note was updated - notifying panel...');
logger.info('makeNoteUpdateAction: Note is a Kanban board - notifying panel and activating editor...');

panelEnabled = true;
await panels.setActive(view, true);

if (panelReady) {
await panels.postMessage(view, { type: 'setNote', value: { id: note.id, body: note.body }});
} else {
logger.info('Panel is not ready - will retry...');
logger.info('makeNoteUpdateAction: Editor is not ready - will retry...');
noteUpdateQueue.push(makeNoteUpdateAction());
}
};
Expand Down Expand Up @@ -139,10 +141,6 @@ joplin.plugins.register({
throw new Error('Unknown message: ' + JSON.stringify(message));
});

joplin.workspace.onNoteChange(async () => {
noteUpdateQueue.push(makeNoteUpdateAction());
});

joplin.workspace.onNoteSelectionChange(async () => {
noteUpdateQueue.push(makeNoteUpdateAction());
});
Expand Down

0 comments on commit 6a1474e

Please sign in to comment.