All files / src/views update-available-modal.ts

100% Statements 24/24
100% Branches 0/0
100% Functions 6/6
100% Lines 23/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50                            5x 5x 5x   5x 5x       5x 5x 5x 5x 5x 5x   5x 5x 5x 1x 1x   5x 5x 5x 5x 1x 1x         3x      
import { App, Modal } from "obsidian";
import type { ReleaseInfo } from "../server-binary";
import { MESSAGES } from "../locales/en";
import { bindEscapeToClose } from "../utils";
 
export interface UpdateReminderActions {
    openSettings: () => void;
    stopReminding: () => void;
}
 
/** Launch-time reminder that a newer server exists while automatic updates are off. */
export class UpdateAvailableModal extends Modal {
    constructor(
        app: App,
        private release: ReleaseInfo,
        private build: string | null,
        private actions: UpdateReminderActions,
    ) {
        super(app);
        bindEscapeToClose(this);
    }
 
    onOpen(): void {
        const { contentEl } = this;
        contentEl.empty();
        contentEl.addClass("lilbee-update-modal");
        contentEl.createEl("h3", { text: MESSAGES.UPDATE_MODAL_TITLE });
        contentEl.createEl("p", { text: MESSAGES.UPDATE_MODAL_BODY(this.release.tag, this.build) });
        contentEl.createEl("p", { text: MESSAGES.UPDATE_MODAL_HOW_TO_DISABLE, cls: "lilbee-update-modal-hint" });
 
        const actions = contentEl.createDiv({ cls: "modal-button-container" });
        const open = actions.createEl("button", { text: MESSAGES.BUTTON_OPEN_UPDATE_SETTINGS, cls: "mod-cta" });
        open.addEventListener("click", () => {
            this.close();
            this.actions.openSettings();
        });
        const later = actions.createEl("button", { text: MESSAGES.BUTTON_NOT_NOW });
        later.addEventListener("click", () => this.close());
        const stop = actions.createEl("button", { text: MESSAGES.BUTTON_STOP_REMINDING });
        stop.addEventListener("click", () => {
            this.actions.stopReminding();
            this.close();
        });
    }
 
    onClose(): void {
        this.contentEl.empty();
    }
}