Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Done notification on by default

Bowen Xue7a9abbdcf3c6
diff --git a/scripts/test_freevideo_entry.mjs b/scripts/test_freevideo_entry.mjs
index 8e25a9f..124f326 100644
--- a/scripts/test_freevideo_entry.mjs
+++ b/scripts/test_freevideo_entry.mjs
@@ -39,6 +39,7 @@ class Element {
close() { this.open = false; this.onclose?.(); }
}
+globalThis.__permissionAsks = [];
test('main browser entry registers both views and preserves node hooks', async t => {
const extensions = [], opened = [], installed = [], events = new EventTarget();
const issueURLs = [];
@@ -48,7 +49,7 @@ test('main browser entry registers both views and preserves node hooks', async t
let launchReady = null;
const opening = {setName: name => openingEvents.push(['name', name]), cover: () => openingEvents.push(['cover']), finish: () => openingEvents.push(['finish'])};
const casts = [];
- let progressView, progressOptions, realProgressFactory, studioView;
+ let progressView, progressOptions, realProgressFactory, studioView, doneNotifyOptions;
const app = {
registerExtension(extension) { extensions.push(extension); },
graph: {extra: {freevideo_studio: true}, _nodes: [], getNodeById() {}},
@@ -90,7 +91,7 @@ test('main browser entry registers both views and preserves node hooks', async t
notifyCompatibility: async () => { compatibilityChecks++; },
startUpdateChecks: () => { updateChecks++; },
startWhiteboxWorker: () => ({stop() {}}),
- startDoneNotify: () => { doneNotifyStarts++; }, askDesktopPermission: () => {},
+ startDoneNotify: options => { doneNotifyStarts++; doneNotifyOptions = options; },
installNavigation: callback => installed.push(callback),
refreshNavigation: () => refreshed++, preferredView: () => rememberedView,
beginWorkspaceRestore: () => { openingEvents.push(['begin']); return opening; }, finishWorkspaceRestore: () => { restoreReleases++; }, waitForLauncherRestore: () => launchReady,
@@ -123,7 +124,7 @@ test('main browser entry registers both views and preserves node hooks', async t
.replace("import { notifyCompatibility } from './compatibility.js';", 'const {notifyCompatibility} = globalThis.__freevideoEntryTest;')
.replace("import { startWhiteboxWorker } from './whitebox_worker.js';", 'const {startWhiteboxWorker} = globalThis.__freevideoEntryTest;')
.replace("import { startUpdateChecks } from './updates.js';", 'const {startUpdateChecks} = globalThis.__freevideoEntryTest;')
- .replace("import { startDoneNotify, askDesktopPermission, DESKTOP_SETTING } from './done_notify.js';", 'const {startDoneNotify,askDesktopPermission} = globalThis.__freevideoEntryTest; const DESKTOP_SETTING = "FreeVideo.DoneNotify.Desktop";')
+ .replace("import { startDoneNotify, askDesktopPermission, DESKTOP_SETTING } from './done_notify.js';", 'const {startDoneNotify} = globalThis.__freevideoEntryTest; const askDesktopPermission = (...args) => globalThis.__permissionAsks.push(args); const DESKTOP_SETTING = "FreeVideo.DoneNotify.Desktop";')
.replace("import { attachReferencePicker, referenceItems, syncReferencePrompt, referenceInputs, mediaRows } from './prompt_references.js';", 'const {attachReferencePicker,referenceItems,syncReferencePrompt,referenceInputs,mediaRows} = globalThis.__freevideoEntryTest;')
.replace("import { expandCast } from './cast_mention.js';", 'const {expandCast} = globalThis.__freevideoEntryTest;')
.replace("import { outputDownloadURL } from './output_download.js';", 'const {outputDownloadURL} = globalThis.__freevideoEntryTest;')
@@ -153,6 +154,41 @@ test('main browser entry registers both views and preserves node hooks', async t
assert.equal(updateChecks, 1);
assert.equal(doneNotifyStarts, 1);
+ await t.test('desktop notification uses the registered default without overwriting stored opt-outs', () => {
+ const setting = extension.settings.find(row => row.id === 'FreeVideo.DoneNotify.Desktop');
+ assert.equal(setting.defaultValue, true);
+ assert.equal(typeof setting.onChange, 'function', 'turning the setting on is a user request');
+ globalThis.__permissionAsks.length = 0;
+ setting.onChange(true, undefined);
+ setting.onChange(true, true);
+ setting.onChange(false, true);
+ assert.equal(globalThis.__permissionAsks.length, 0, 'registration and unrelated changes never ask');
+ setting.onChange(true, false);
+ assert.equal(globalThis.__permissionAsks.length, 1, 'switching from off to on asks once');
+ assert.equal(doneNotifyOptions.desktop(), true, 'missing values use the new default');
+ // ComfyUI keeps explicit values separately and get() uses value ?? default.
+ // Registration must not write true over a previously stored false.
+ const values = new Map();
+ app.extensionManager = {setting: {get: key => values.get(key) ?? setting.defaultValue}};
+ app.ui = {settings: {getSettingValue: () => true}};
+ assert.equal(doneNotifyOptions.desktop(), true);
+ assert.equal(values.size, 0, 'an untouched default is not persisted');
+ values.set(setting.id, false);
+ assert.equal(doneNotifyOptions.desktop(), false, 'modern false wins over legacy true');
+ assert.equal(values.get(setting.id), false);
+ app.extensionManager.setting.get = () => undefined;
+ app.ui.settings.getSettingValue = () => false;
+ assert.equal(doneNotifyOptions.desktop(), false, 'legacy false is also preserved');
+ app.ui.settings.getSettingValue = () => undefined;
+ assert.equal(doneNotifyOptions.desktop(), true);
+ app.graph._nodes.push({type: 'KSampler'});
+ assert.equal(doneNotifyOptions.isFreeVideoWorkflow(), false);
+ app.graph._nodes.push({comfyClass: 'FreeVideoGenerate'});
+ assert.equal(doneNotifyOptions.isFreeVideoWorkflow(), true);
+ app.graph._nodes.length = 0;
+ delete app.extensionManager; delete app.ui;
+ });
+
class GenerateNode {
constructor() {
this.id = 7; this.type = 'FreeVideoGenerate';
diff --git a/web/done_notify.js b/web/done_notify.js
index d5bf111..53fac99 100644
--- a/web/done_notify.js
+++ b/web/done_notify.js
@@ -1,11 +1,14 @@
// Tells the user a long run has finished while FreeVideo is in a background tab:
// the tab title flashes and one short beep plays until the page is shown again.
-// A desktop notification is sent only when the user turned it on in the settings.
+// Desktop notifications default on; an explicit opt-out keeps them off.
// Only a queue that ran a FreeVideo node counts: other workflows finish silently.
export const DESKTOP_SETTING = 'FreeVideo.DoneNotify.Desktop';
+const PERMISSION_ASKED = 'freevideo.desktop.notification-asked';
+const permissionAsked = new WeakSet();
const LONG_RUN_MS = 20000, FLASH_MS = 1000;
-export function startDoneNotify({api, text, doc = document, win = window, now = () => Date.now(), desktop = () => false, isFreeVideoNode = () => false,
+export function startDoneNotify({api, text, doc = document, win = window, now = () => Date.now(), desktop = () => true, isFreeVideoNode = () => false,
+ isFreeVideoWorkflow = () => false,
beep = playBeep, notify = desktopNotice, minimum = LONG_RUN_MS, setTimer = setInterval, clearTimer = clearInterval} = {}) {
let busySince = null, failed = false, cancelled = false, flashing = null, involved = false;
const away = () => doc.hidden || (typeof doc.hasFocus === 'function' && !doc.hasFocus());
@@ -43,6 +46,12 @@ export function startDoneNotify({api, text, doc = document, win = window, now =
};
const interrupted = () => { cancelled = true; };
const shown = () => { if (!away()) stopFlashing(); };
+ // Capture the actual Generate click before the host starts any async work.
+ // The workspace marks its button; current and older ComfyUI use the other two.
+ const generate = event => {
+ const button = event.target?.closest?.('[data-fv-guide="generate"], [data-testid="queue-button"], #queue-button');
+ if (button && !button.disabled && desktop() && isFreeVideoWorkflow()) askDesktopPermission(win);
+ };
api.addEventListener('status', status);
api.addEventListener('execution_error', error);
api.addEventListener('execution_interrupted', interrupted);
@@ -50,13 +59,15 @@ export function startDoneNotify({api, text, doc = document, win = window, now =
api.addEventListener('freevideo_prewarm', freevideo);
api.addEventListener('executing', executing);
doc.addEventListener('visibilitychange', shown);
+ doc.addEventListener('click', generate, true);
win.addEventListener?.('focus', shown);
return {stop() {
api.removeEventListener('status', status); api.removeEventListener('execution_error', error);
api.removeEventListener('execution_interrupted', interrupted);
api.removeEventListener('freevideo_progress', freevideo); api.removeEventListener('freevideo_prewarm', freevideo);
api.removeEventListener('executing', executing);
- doc.removeEventListener('visibilitychange', shown); win.removeEventListener?.('focus', shown); stopFlashing();
+ doc.removeEventListener('visibilitychange', shown); doc.removeEventListener('click', generate, true);
+ win.removeEventListener?.('focus', shown); stopFlashing();
}};
}
@@ -82,7 +93,17 @@ function desktopNotice(win, label, clicked) {
notice.onclick = () => { clicked(); notice.close?.(); };
}
-// Asks for notification permission when the user switches the setting on.
-export function askDesktopPermission(win = window) {
- try { win.Notification?.requestPermission?.(); } catch { /* Optional. */ }
+// Call synchronously from a Generate gesture, never at startup or on completion.
+// A user turning the setting on is an explicit request, so it ignores the earlier record.
+export function askDesktopPermission(win = window, {explicit = false} = {}) {
+ const Notice = win.Notification;
+ if (Notice?.permission !== 'default' || typeof Notice.requestPermission !== 'function') return;
+ if (!explicit) {
+ if (permissionAsked.has(win)) return;
+ try { if (win.localStorage.getItem(PERMISSION_ASKED) === '1') return; } catch { /* Storage may be blocked. */ }
+ }
+ // Remember before requesting, including dismissals, throws and pending promises.
+ permissionAsked.add(win);
+ try { win.localStorage.setItem(PERMISSION_ASKED, '1'); } catch { /* Keep the in-memory guard. */ }
+ try { Notice.requestPermission()?.catch?.(() => {}); } catch { /* Optional. */ }
}
diff --git a/web/freevideo.js b/web/freevideo.js
index 081d66a..a539278 100644
--- a/web/freevideo.js
+++ b/web/freevideo.js
@@ -690,12 +690,14 @@ async function openFromMenu() {
}
}
-const desktopNoticeEnabled = () => (app.extensionManager?.setting?.get?.(DESKTOP_SETTING) ?? app.ui?.settings?.getSettingValue?.(DESKTOP_SETTING)) === true;
+const desktopNoticeEnabled = () => (app.extensionManager?.setting?.get?.(DESKTOP_SETTING) ?? app.ui?.settings?.getSettingValue?.(DESKTOP_SETTING) ?? true) === true;
app.registerExtension({
name: "FreeVideo.UnifiedMedia",
settings: [{id: DESKTOP_SETTING, name: text('Desktop notification when done', '完成时发桌面通知'),
- type: 'boolean', defaultValue: false, onChange: value => { if (value) askDesktopPermission(); }}],
+ type: 'boolean', defaultValue: true,
+ // ComfyUI calls onChange(value, undefined) while registering; only a switch from off to on is a user request.
+ onChange: (value, oldValue) => { if (oldValue === false && value === true) askDesktopPermission(window, {explicit: true}); }}],
// The one entry that stays in ComfyUI's own menu, whatever workflow is in front.
commands: [{id: 'FreeVideo.Open', label: 'FreeVideo', function: openFromMenu}],
menuCommands: [{path: ['Extensions'], commands: ['FreeVideo.Open']}],
@@ -703,7 +705,8 @@ app.registerExtension({
async setup() {
// One failing part must not take the others down; health.js shows what failed.
for (const [where, start] of [['progress', () => progressConnection.start()], ['navigation', () => installNavigation(showStudio, agentInterfaceState(api), {openWorkflow: openFreeVideoWorkflow, recheck: () => agentInterfaceState(api)})],
- ['updates', startUpdateChecks], ['done-notify', () => startDoneNotify({api, text, desktop: desktopNoticeEnabled, isFreeVideoNode})],
+ ['updates', startUpdateChecks], ['done-notify', () => startDoneNotify({api, text, desktop: desktopNoticeEnabled, isFreeVideoNode,
+ isFreeVideoWorkflow: () => (app.graph?._nodes || []).some(isGenerate)})],
['whitebox', () => startWhiteboxWorker({api})]]) {
try { start(); } catch (error) { health({type: 'error', where, error}); }
}