Skip to content

Commit

Permalink
SDA-4675 - Revert delay
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranNiranjan committed Oct 1, 2024
1 parent fe7fd98 commit 0a67bed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 74 deletions.
48 changes: 0 additions & 48 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,51 +349,3 @@ export class DelayedFunctionQueue {
}
}
}
export interface IFunctionQueue {
enqueue: (fn: () => void) => void;
}

/**
* Creates a function queue that executes functions sequentially with a specified interval.
*
* @param {number} interval - The interval (in milliseconds) between function executions.
* @returns {IFunctionQueue} - An object representing the function queue.
*/
export const createSequentialFunctionQueue = (
interval: number,
): IFunctionQueue => {
const queue: Array<() => void> = [];
let isProcessing: boolean = false;

// Enqueue a function call
const enqueue = (fn: () => void): void => {
queue.push(fn);
processQueue();
};

// Process the queue
const processQueue = (): void => {
if (isProcessing) {
return;
}
isProcessing = true;

const processNext = (): void => {
if (queue.length === 0) {
isProcessing = false;
return;
}
const fn = queue.shift();
if (fn) {
fn();
}
// Schedule the next function execution after the interval
setTimeout(() => {
processNext();
}, interval);
};
processNext();
};

return { enqueue };
};
43 changes: 17 additions & 26 deletions src/renderer/ssf-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ import {
PhoneNumberProtocol,
} from '../common/api-interface';
import { i18n, LocaleType } from '../common/i18n-preload';
import {
createSequentialFunctionQueue,
DelayedFunctionQueue,
throttle,
} from '../common/utils';
import { DelayedFunctionQueue, throttle } from '../common/utils';
import { getSource } from './desktop-capturer';
import SSFNotificationHandler from './notification-ssf-handler';
import { ScreenSnippetBcHandler } from './screen-snippet-bc-handler';
Expand Down Expand Up @@ -90,9 +86,6 @@ const callNotificationActionCallbacks = new Map<
>();

const DEFAULT_THROTTLE = 1000;
const NOTIFICATION_DELAY = 500;

const notificationQueue = createSequentialFunctionQueue(NOTIFICATION_DELAY);

// Throttle func
const throttledSetBadgeCount = throttle((count) => {
Expand Down Expand Up @@ -719,24 +712,22 @@ export class SSFApi {
notificationOpts: INotificationData,
notificationCallback: NotificationActionCallback,
): void {
notificationQueue.enqueue(() => {
// Store callbacks based on notification id so,
// we can use this to trigger on notification action
if (typeof notificationOpts.id === 'number') {
notificationActionCallbacks.set(
notificationOpts.id,
notificationCallback,
);
}
// ipc does not support sending Functions, Promises, Symbols, WeakMaps,
// or WeakSets will throw an exception
if (notificationOpts.callback) {
delete notificationOpts.callback;
}
ipcRenderer.send(apiName.symphonyApi, {
cmd: apiCmds.showNotification,
notificationOpts,
});
// Store callbacks based on notification id so,
// we can use this to trigger on notification action
if (typeof notificationOpts.id === 'number') {
notificationActionCallbacks.set(
notificationOpts.id,
notificationCallback,
);
}
// ipc does not support sending Functions, Promises, Symbols, WeakMaps,
// or WeakSets will throw an exception
if (notificationOpts.callback) {
delete notificationOpts.callback;
}
ipcRenderer.send(apiName.symphonyApi, {
cmd: apiCmds.showNotification,
notificationOpts,
});
}

Expand Down

0 comments on commit 0a67bed

Please sign in to comment.