mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
Show a one-time pause notice with Run Anyway
This commit is contained in:
1 parent
c223a4ccae
commit
a2b604a87a
4 files changed
+79
-6
No files matched your search
@@ -1,15 +1,27 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getRemoteStatus } from "@/seqta/utils/remoteStatus";
|
import { choosePause, getRemoteStatus, isPaused, pauseMessage } from "@/seqta/utils/remoteStatus";
|
||||||
|
|
||||||
const status = getRemoteStatus();
|
const status = getRemoteStatus();
|
||||||
const message = status.message ?? (status.off ? "BetterSEQTA+ is temporarily disabled." : null);
|
const message = status.off ? pauseMessage() : status.message;
|
||||||
|
|
||||||
|
async function runAnyway() {
|
||||||
|
await choosePause(true);
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if message}
|
{#if message}
|
||||||
<div
|
<div
|
||||||
class="shrink-0 border-b border-amber-200/80 bg-amber-50 px-4 py-3 text-sm text-amber-950 dark:border-amber-900/60 dark:bg-amber-950/40 dark:text-amber-50"
|
class="flex shrink-0 items-center gap-3 border-b border-amber-200/80 bg-amber-50 px-4 py-3 text-sm text-amber-950 dark:border-amber-900/60 dark:bg-amber-950/40 dark:text-amber-50"
|
||||||
role="status"
|
role="status"
|
||||||
>
|
>
|
||||||
<p class="leading-relaxed">{message}</p>
|
<p class="flex-1 leading-relaxed">{message}</p>
|
||||||
|
{#if isPaused()}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-lg px-3 py-1.5 font-semibold ring-1 ring-current"
|
||||||
|
onclick={runAnyway}>Run Anyway</button
|
||||||
|
>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
+9
-2
@@ -9,7 +9,13 @@ import { initializeHideSensitiveToggle } from "@/seqta/utils/hideSensitiveToggle
|
|||||||
import { installSeqtaMenuColourPatch } from "@/seqta/utils/patchSeqtaMenuUpdateColours";
|
import { installSeqtaMenuColourPatch } from "@/seqta/utils/patchSeqtaMenuUpdateColours";
|
||||||
import { installThemeImagePagePatch } from "@/seqta/utils/patchThemeImagesPageContext";
|
import { installThemeImagePagePatch } from "@/seqta/utils/patchThemeImagesPageContext";
|
||||||
import { initVerboseLogging, verboseInfo } from "@/utils/verboseLog";
|
import { initVerboseLogging, verboseInfo } from "@/utils/verboseLog";
|
||||||
import { getRemoteStatus, loadRemoteStatus, refreshRemoteStatus } from "@/seqta/utils/remoteStatus";
|
import {
|
||||||
|
hasSeenPause,
|
||||||
|
isPaused,
|
||||||
|
loadRemoteStatus,
|
||||||
|
refreshRemoteStatus,
|
||||||
|
} from "@/seqta/utils/remoteStatus";
|
||||||
|
import { showPauseNotice } from "@/seqta/utils/pauseNotice";
|
||||||
import { ensureSettingsAccess } from "@/seqta/utils/ensureSettingsAccess";
|
import { ensureSettingsAccess } from "@/seqta/utils/ensureSettingsAccess";
|
||||||
import { recoverFromStaleDevModuleGraph } from "@/seqta/devModuleGraphRecovery";
|
import { recoverFromStaleDevModuleGraph } from "@/seqta/devModuleGraphRecovery";
|
||||||
|
|
||||||
@@ -98,7 +104,7 @@ async function init() {
|
|||||||
await loadRemoteStatus();
|
await loadRemoteStatus();
|
||||||
void refreshRemoteStatus();
|
void refreshRemoteStatus();
|
||||||
|
|
||||||
if (settingsState.onoff !== false && !getRemoteStatus().off) {
|
if (settingsState.onoff !== false && !isPaused()) {
|
||||||
await main();
|
await main();
|
||||||
|
|
||||||
const { init: Monofile } = await import("@/plugins/monofile");
|
const { init: Monofile } = await import("@/plugins/monofile");
|
||||||
@@ -110,6 +116,7 @@ async function init() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await ensureSettingsAccess();
|
await ensureSettingsAccess();
|
||||||
|
if (settingsState.onoff !== false && !hasSeenPause()) showPauseNotice();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settingsState.devMode) {
|
if (settingsState.devMode) {
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { choosePause, pauseMessage } from "@/seqta/utils/remoteStatus";
|
||||||
|
|
||||||
|
// SEQTA's page styles aren't patched while paused, so the bar carries its own inline styles.
|
||||||
|
const BUTTON_STYLE =
|
||||||
|
"border:0;border-radius:8px;padding:6px 12px;font:inherit;font-weight:600;cursor:pointer;";
|
||||||
|
|
||||||
|
export function showPauseNotice(): void {
|
||||||
|
const bar = document.createElement("div");
|
||||||
|
bar.setAttribute("role", "status");
|
||||||
|
bar.style.cssText =
|
||||||
|
"position:fixed;left:50%;bottom:16px;transform:translateX(-50%);z-index:2147483647;display:flex;align-items:center;gap:12px;max-width:min(560px,calc(100vw - 32px));padding:12px 16px;border-radius:12px;background:#1f1f1f;color:#fff;font:14px/1.4 system-ui,sans-serif;box-shadow:0 8px 24px rgba(0,0,0,.3);";
|
||||||
|
|
||||||
|
const text = document.createElement("span");
|
||||||
|
text.textContent = pauseMessage();
|
||||||
|
|
||||||
|
const runAnyway = document.createElement("button");
|
||||||
|
runAnyway.textContent = "Run Anyway";
|
||||||
|
runAnyway.style.cssText = `${BUTTON_STYLE}background:transparent;color:#fff;box-shadow:inset 0 0 0 1px rgba(255,255,255,.4);`;
|
||||||
|
runAnyway.onclick = async () => {
|
||||||
|
await choosePause(true);
|
||||||
|
location.reload();
|
||||||
|
};
|
||||||
|
|
||||||
|
const ok = document.createElement("button");
|
||||||
|
ok.textContent = "OK";
|
||||||
|
ok.style.cssText = `${BUTTON_STYLE}background:#fff;color:#111;`;
|
||||||
|
ok.onclick = async () => {
|
||||||
|
await choosePause(false);
|
||||||
|
bar.remove();
|
||||||
|
};
|
||||||
|
|
||||||
|
bar.append(text, runAnyway, ok);
|
||||||
|
document.body.append(bar);
|
||||||
|
}
|
||||||
@@ -10,6 +10,9 @@ export type RemoteStatus = {
|
|||||||
const STATUS_URL =
|
const STATUS_URL =
|
||||||
"https://raw.githubusercontent.com/BetterSEQTA/BS-Status/main/config/status.json";
|
"https://raw.githubusercontent.com/BetterSEQTA/BS-Status/main/config/status.json";
|
||||||
export const REMOTE_STATUS_KEY = "bsplus_remote_status";
|
export const REMOTE_STATUS_KEY = "bsplus_remote_status";
|
||||||
|
const PAUSE_CHOICE_KEY = "bsplus_pause_choice";
|
||||||
|
|
||||||
|
type PauseChoice = { message: string; runAnyway: boolean };
|
||||||
|
|
||||||
function stringList(value: unknown): string[] {
|
function stringList(value: unknown): string[] {
|
||||||
return Array.isArray(value) ? value.filter((key): key is string => typeof key === "string") : [];
|
return Array.isArray(value) ? value.filter((key): key is string => typeof key === "string") : [];
|
||||||
@@ -34,6 +37,9 @@ export async function readRemoteStatus(): Promise<RemoteStatus> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let status = normalizeRemoteStatus(null);
|
let status = normalizeRemoteStatus(null);
|
||||||
|
let pauseChoice: PauseChoice | null = null;
|
||||||
|
|
||||||
|
export const pauseMessage = (): string => status.message ?? "BetterSEQTA+ is paused for now.";
|
||||||
|
|
||||||
export const getRemoteStatus = (): RemoteStatus => status;
|
export const getRemoteStatus = (): RemoteStatus => status;
|
||||||
|
|
||||||
@@ -41,8 +47,22 @@ export const isFeatureDisabled = (key: string): boolean =>
|
|||||||
status.disabledFeatures.includes(key) ||
|
status.disabledFeatures.includes(key) ||
|
||||||
!!status.sites[location.hostname.toLowerCase()]?.includes(key);
|
!!status.sites[location.hostname.toLowerCase()]?.includes(key);
|
||||||
|
|
||||||
|
const currentPauseChoice = (): PauseChoice | null =>
|
||||||
|
status.off && pauseChoice?.message === pauseMessage() ? pauseChoice : null;
|
||||||
|
|
||||||
|
export const isPaused = (): boolean => status.off && !currentPauseChoice()?.runAnyway;
|
||||||
|
|
||||||
|
export const hasSeenPause = (): boolean => currentPauseChoice() !== null;
|
||||||
|
|
||||||
|
export async function choosePause(runAnyway: boolean): Promise<void> {
|
||||||
|
pauseChoice = { message: pauseMessage(), runAnyway };
|
||||||
|
await browser.storage.local.set({ [PAUSE_CHOICE_KEY]: pauseChoice });
|
||||||
|
}
|
||||||
|
|
||||||
export async function loadRemoteStatus(): Promise<void> {
|
export async function loadRemoteStatus(): Promise<void> {
|
||||||
status = await readRemoteStatus();
|
status = await readRemoteStatus();
|
||||||
|
const stored = await browser.storage.local.get(PAUSE_CHOICE_KEY);
|
||||||
|
pauseChoice = (stored[PAUSE_CHOICE_KEY] as PauseChoice | undefined) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function refreshRemoteStatus(): Promise<void> {
|
export async function refreshRemoteStatus(): Promise<void> {
|
||||||
|
|||||||
Reference in new issue
Block a user