Add default browser & external-open support
Introduce default-browser integration and external open handling across platforms. Added platform/default_browser.h with a Windows implementation (registry registration + settings UI invocation) and mac/linux stubs. Exposed new commands from the renderer (check-default-browser / set-default-browser) and implemented request/response plumbing in NebulaController (SendDefaultBrowserResult) and BrowserClient. Added UI controls and JS helpers in settings and setup pages to check and prompt the user to make Nebula the default browser. Also added single-instance launch target handling: command-line URL normalization, passing/consolidating the launch target, forwarding it to an existing window on Windows via WM_COPYDATA, and exposing OnExternalOpenRequested on the window/controller. Implemented delayed navigation (CefTask) to safely load pending initial URLs after CEF initialization. Updated CMakeLists and platform startup signatures to include and accept the new files/parameters.
This commit is contained in:
+76
-2
@@ -16,6 +16,78 @@ function hasNebulaNativeBridge() {
|
||||
return !!(window.nebulaNative && typeof window.nebulaNative.postMessage === 'function');
|
||||
}
|
||||
|
||||
const defaultBrowserRequests = new Map();
|
||||
let defaultBrowserRequestId = 0;
|
||||
|
||||
window.addEventListener('nebula-default-browser-result', (event) => {
|
||||
const detail = event.detail || {};
|
||||
const pending = defaultBrowserRequests.get(detail.requestId);
|
||||
if (!pending) return;
|
||||
|
||||
defaultBrowserRequests.delete(detail.requestId);
|
||||
pending.resolve(detail);
|
||||
});
|
||||
|
||||
function sendDefaultBrowserRequest(command) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!hasNebulaNativeBridge()) {
|
||||
reject(new Error('Native browser integration is unavailable.'));
|
||||
return;
|
||||
}
|
||||
|
||||
const requestId = `default-browser-${Date.now()}-${++defaultBrowserRequestId}`;
|
||||
const timeout = setTimeout(() => {
|
||||
defaultBrowserRequests.delete(requestId);
|
||||
reject(new Error('Timed out waiting for default browser status.'));
|
||||
}, 10000);
|
||||
|
||||
defaultBrowserRequests.set(requestId, {
|
||||
resolve: (value) => {
|
||||
clearTimeout(timeout);
|
||||
resolve(value);
|
||||
},
|
||||
reject: (error) => {
|
||||
clearTimeout(timeout);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
window.nebulaNative.postMessage(command, requestId);
|
||||
} catch (error) {
|
||||
defaultBrowserRequests.delete(requestId);
|
||||
clearTimeout(timeout);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createNebulaNativeApi() {
|
||||
return {
|
||||
async getAllThemes() {
|
||||
return { default: getPresetThemes() };
|
||||
},
|
||||
async isDefaultBrowser() {
|
||||
const result = await sendDefaultBrowserRequest('check-default-browser');
|
||||
return !!result.isDefault;
|
||||
},
|
||||
async setAsDefaultBrowser() {
|
||||
return sendDefaultBrowserRequest('set-default-browser');
|
||||
},
|
||||
async applyTheme(themeId) {
|
||||
const theme = getThemeById(themeId);
|
||||
if (theme) {
|
||||
localStorage.setItem('currentTheme', JSON.stringify(normalizeTheme(theme)));
|
||||
}
|
||||
localStorage.setItem('activeThemeName', themeId);
|
||||
},
|
||||
async completeFirstRun(data) {
|
||||
localStorage.setItem('nebula-first-run-complete', JSON.stringify(data));
|
||||
window.nebulaNative.postMessage('complete-first-run', JSON.stringify(data));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getPresetThemes() {
|
||||
if (typeof BrowserCustomizer === 'function') {
|
||||
const customizer = new BrowserCustomizer({ skipInit: true });
|
||||
@@ -61,7 +133,7 @@ function normalizeTheme(theme) {
|
||||
};
|
||||
}
|
||||
|
||||
const nativeApi = window.api || {
|
||||
const fallbackApi = {
|
||||
async getAllThemes() {
|
||||
return { default: getPresetThemes() };
|
||||
},
|
||||
@@ -86,6 +158,8 @@ const nativeApi = window.api || {
|
||||
}
|
||||
};
|
||||
|
||||
const nativeApi = window.api || (hasNebulaNativeBridge() ? createNebulaNativeApi() : fallbackApi);
|
||||
|
||||
// Initialize setup when DOM is ready
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
console.log('[Setup] Initializing first-time setup...');
|
||||
@@ -402,7 +476,7 @@ async function setDefaultBrowser() {
|
||||
const result = await nativeApi.setAsDefaultBrowser();
|
||||
|
||||
if (result.success) {
|
||||
const isDefault = await window.api.isDefaultBrowser();
|
||||
const isDefault = !!result.isDefault || await nativeApi.isDefaultBrowser();
|
||||
if (isDefault) {
|
||||
setupState.defaultBrowserSet = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user