Skip to content

Fix sticky HUD messages #584

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

Merged
merged 2 commits into from
Sep 12, 2024
Merged
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
1 change: 0 additions & 1 deletion src/scripts/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async function createMessageDiv() {
const settings = await getSettings();
switch (settings.message_display) {
case 'hud': {
HornHud.init();
break;
}
case 'toast':
Expand Down
29 changes: 26 additions & 3 deletions src/scripts/util/hornHud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,34 @@
* This class can only be uses from contexts that have access to DOM.
*/
export class HornHud {
private static messageQueue: { message: string, type: 'success' | 'warning' | 'error' }[] = [];
private static isProcessingQueue = false;

public static async showMessage(
message: string,
type: 'success' | 'warning' | 'error' = 'success'
) {
this.messageQueue.push({message, type});

if (!this.isProcessingQueue) {
await this.processQueue();
}
}

private static async processQueue() {
this.isProcessingQueue = true;

while (this.messageQueue.length > 0) {
const {message, type} = this.messageQueue.shift()!;
await this.displayMessage(message, type);
}

this.isProcessingQueue = false;
}

private static async displayMessage(
message: string,
type: 'success' | 'warning' | 'error'
) {
const messageDom = this.getMessageDOM();
if (messageDom === null) {
Expand Down Expand Up @@ -74,9 +98,8 @@ export class HornHud {
messageDom.replaceChildren(messageView);
messageDom.classList.add('huntersHornView__message--active');

setTimeout(() => {
removeMessage();
}, duration);
await new Promise((r) => setTimeout(r, duration));
await removeMessage();
}

/**
Expand Down