a
This commit is contained in:
parent
a4abbf7844
commit
63d8aa9fe3
6 changed files with 4536 additions and 517 deletions
59
main.js
59
main.js
|
|
@ -19,6 +19,15 @@ function createWindow() {
|
|||
}
|
||||
});
|
||||
|
||||
win.setAutoHideMenuBar(true);
|
||||
win.setMenuBarVisibility(false);
|
||||
|
||||
ipcMain.handle('get-config', () => {
|
||||
return {
|
||||
backendUrl: (process.env.CHATTZ_URL || 'https://discord.flegr.me').replace(/\/$/, '')
|
||||
};
|
||||
});
|
||||
|
||||
ipcMain.handle('clipboard-write', (event, text) => {
|
||||
clipboard.writeText(text);
|
||||
return true;
|
||||
|
|
@ -60,20 +69,25 @@ function createWindow() {
|
|||
const backendUrl = (process.env.CHATTZ_URL || 'https://discord.flegr.me').replace(/\/$/, '');
|
||||
const indexPath = path.join(__dirname, 'desktop', 'index.html');
|
||||
|
||||
// Construct the local file URL with the backend parameter
|
||||
const localUrl = url.format({
|
||||
pathname: indexPath,
|
||||
protocol: 'file:',
|
||||
slashes: true,
|
||||
query: { backend: backendUrl }
|
||||
});
|
||||
|
||||
console.log(`Loading desktop app from: ${localUrl}`);
|
||||
|
||||
const loadDesktopApp = (queryParams = '') => {
|
||||
const fullUrl = queryParams ? `${localUrl}&${queryParams}` : localUrl;
|
||||
win.loadURL(fullUrl).catch((err) => {
|
||||
console.error(`Failed to load desktop file: ${err}`);
|
||||
const options = {};
|
||||
if (queryParams) {
|
||||
try {
|
||||
options.query = Object.fromEntries(new URLSearchParams(queryParams));
|
||||
} catch (e) {
|
||||
console.error("Failed to parse query params", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Use setImmediate to ensure the current navigation tick is cleared,
|
||||
// which prevents ERR_ABORTED (-3) on some platforms when interrupting a redirect.
|
||||
setImmediate(() => {
|
||||
if (win.isDestroyed()) return;
|
||||
win.loadFile(indexPath, options).catch((err) => {
|
||||
// Ignore aborted errors as they often happen during fast redirects
|
||||
if (err.toString().includes('-3') || err.code === -3) return;
|
||||
console.error(`Failed to load desktop file: ${err}`);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -82,26 +96,19 @@ function createWindow() {
|
|||
try {
|
||||
const urlObj = new URL(navigatedUrl);
|
||||
const backendObj = new URL(backendUrl);
|
||||
// Detect the redirect back to the home page with a token
|
||||
if (urlObj.origin === backendObj.origin && urlObj.pathname === '/') {
|
||||
console.log("Detected remote landing (login success), returning to desktop UI...");
|
||||
event.preventDefault();
|
||||
loadDesktopApp(urlObj.search.slice(1));
|
||||
if (urlObj.searchParams.has('token')) {
|
||||
console.log("Detected login success redirect, returning to desktop UI...");
|
||||
event.preventDefault();
|
||||
loadDesktopApp(urlObj.search.slice(1));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
win.webContents.on('did-navigate', (event, navigatedUrl) => {
|
||||
try {
|
||||
const urlObj = new URL(navigatedUrl);
|
||||
const backendObj = new URL(backendUrl);
|
||||
if (urlObj.origin === backendObj.origin && urlObj.pathname === '/') {
|
||||
loadDesktopApp(urlObj.search.slice(1));
|
||||
}
|
||||
} catch (e) { }
|
||||
});
|
||||
|
||||
loadDesktopApp();
|
||||
|
||||
// Uncomment to debug
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue