Compare commits
No commits in common. "ad6eaad5d28a262eb878994b17d2372ccd1e528a" and "0b5fc9914c6d384eef3a54fffe691d233b9b3275" have entirely different histories.
ad6eaad5d2
...
0b5fc9914c
8 changed files with 3899 additions and 2299 deletions
|
|
@ -50,20 +50,11 @@ jobs:
|
|||
cp "$file" "static/installers/$out"
|
||||
fi
|
||||
}
|
||||
# Copy versioned artifacts for electron-updater
|
||||
cp dist/*.AppImage static/installers/ || true
|
||||
cp dist/*.exe static/installers/ || true
|
||||
cp dist/*.rpm static/installers/ || true
|
||||
cp dist/*.deb static/installers/ || true
|
||||
cp dist/*.msi static/installers/ || true
|
||||
|
||||
# Maintain generic names for stable website links
|
||||
copy_first '*.rpm' 'chattz-linux.rpm'
|
||||
copy_first '*.deb' 'chattz-linux.deb'
|
||||
copy_first '*.AppImage' 'chattz-linux.AppImage'
|
||||
copy_first '*.exe' 'chattz-windows.exe'
|
||||
copy_first '*.msi' 'chattz-windows.msi'
|
||||
|
||||
# Metadata files for electron-updater
|
||||
copy_first 'latest-linux.yml' 'latest-linux.yml'
|
||||
copy_first 'latest.yml' 'latest.yml'
|
||||
|
|
|
|||
1947
desktop/app.js
1947
desktop/app.js
File diff suppressed because it is too large
Load diff
|
|
@ -265,7 +265,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script type="module" src="app.js?v=20260227-shared-core-1"></script>
|
||||
<script src="app.js?v=20260225-voice-debug-1" defer></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -3,15 +3,9 @@ const { contextBridge, ipcRenderer } = require('electron');
|
|||
contextBridge.exposeInMainWorld('electronAPI', {
|
||||
copyToClipboard: (text) => ipcRenderer.invoke('clipboard-write', text),
|
||||
getConfig: () => ipcRenderer.invoke('get-config'),
|
||||
storageGet: (key) => ipcRenderer.invoke('storage-get', key),
|
||||
storageSet: (key, value) => ipcRenderer.invoke('storage-set', key, value),
|
||||
storageRemove: (key) => ipcRenderer.invoke('storage-remove', key),
|
||||
getUpdateState: () => ipcRenderer.invoke('get-update-state'),
|
||||
checkForUpdatesNow: () => ipcRenderer.invoke('check-for-updates-now'),
|
||||
checkForUpdates: () => ipcRenderer.send('check-for-updates'),
|
||||
downloadUpdate: () => ipcRenderer.send('download-update'),
|
||||
quitAndInstall: () => ipcRenderer.send('quit-and-install'),
|
||||
onUpdateState: (callback) => ipcRenderer.on('update-state', (event, state) => callback(state)),
|
||||
onUpdateAvailable: (callback) => ipcRenderer.on('update-available', (event, info) => callback(info)),
|
||||
onUpdateDownloaded: (callback) => ipcRenderer.on('update-downloaded', (event, info) => callback(info)),
|
||||
onUpdateError: (callback) => ipcRenderer.on('update-error', (event, error) => callback(error))
|
||||
|
|
|
|||
182
main.js
182
main.js
|
|
@ -1,88 +1,8 @@
|
|||
const { app, BrowserWindow, session, desktopCapturer, ipcMain, clipboard } = require('electron');
|
||||
const { autoUpdater } = require('electron-updater');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const url = require('url');
|
||||
|
||||
const updateState = {
|
||||
status: 'idle', // idle | checking | available | downloading | downloaded | not-available | error
|
||||
info: null,
|
||||
error: null,
|
||||
};
|
||||
|
||||
function broadcastUpdateState() {
|
||||
const wins = BrowserWindow.getAllWindows();
|
||||
for (const win of wins) {
|
||||
if (!win.isDestroyed()) {
|
||||
win.webContents.send('update-state', updateState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getStorageFilePath() {
|
||||
return path.join(app.getPath('userData'), 'renderer-storage.json');
|
||||
}
|
||||
|
||||
function readPersistentStore() {
|
||||
const filePath = getStorageFilePath();
|
||||
try {
|
||||
if (!fs.existsSync(filePath)) return {};
|
||||
const raw = fs.readFileSync(filePath, 'utf8');
|
||||
const parsed = JSON.parse(raw);
|
||||
return parsed && typeof parsed === 'object' ? parsed : {};
|
||||
} catch (err) {
|
||||
console.error('Failed to read persistent store', err);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function writePersistentStore(store) {
|
||||
const filePath = getStorageFilePath();
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
fs.writeFileSync(filePath, JSON.stringify(store), 'utf8');
|
||||
} catch (err) {
|
||||
console.error('Failed to write persistent store', err);
|
||||
}
|
||||
}
|
||||
|
||||
function isNewerVersionAvailable(info) {
|
||||
const next = info && typeof info.version === 'string' ? info.version : '';
|
||||
return Boolean(next) && next !== app.getVersion();
|
||||
}
|
||||
|
||||
let updateCheckInProgress = false;
|
||||
|
||||
async function runUpdateCheck(reason = 'manual') {
|
||||
if (updateCheckInProgress) {
|
||||
console.log(`Update check skipped (${reason}): another check is already in progress`);
|
||||
return;
|
||||
}
|
||||
updateCheckInProgress = true;
|
||||
updateState.status = 'checking';
|
||||
updateState.error = null;
|
||||
try {
|
||||
const result = await autoUpdater.checkForUpdates();
|
||||
const info = result && result.updateInfo ? result.updateInfo : null;
|
||||
if (isNewerVersionAvailable(info)) {
|
||||
updateState.status = 'available';
|
||||
updateState.info = info;
|
||||
updateState.error = null;
|
||||
} else {
|
||||
updateState.status = 'not-available';
|
||||
updateState.info = info;
|
||||
updateState.error = null;
|
||||
}
|
||||
} catch (err) {
|
||||
updateState.status = 'error';
|
||||
updateState.error = err && err.message ? err.message : String(err);
|
||||
console.error(`Update check failed (${reason})`, err);
|
||||
} finally {
|
||||
updateCheckInProgress = false;
|
||||
broadcastUpdateState();
|
||||
}
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
// Create a persistent session for chattz to keep the user logged in
|
||||
const sess = session.fromPartition('persist:chattz');
|
||||
|
|
@ -101,7 +21,18 @@ function createWindow() {
|
|||
});
|
||||
|
||||
win.setAutoHideMenuBar(true);
|
||||
win.setMenuBarVisibility(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;
|
||||
});
|
||||
|
||||
// Auto-approve media permissions (camera, microphone)
|
||||
sess.setPermissionCheckHandler((webContents, permission) => {
|
||||
|
|
@ -161,14 +92,12 @@ function createWindow() {
|
|||
});
|
||||
};
|
||||
|
||||
// Intercept navigations/redirects that return to the backend with a token
|
||||
// after the OAuth login flow. Two handlers are needed because:
|
||||
// - will-navigate fires for client-side navigations (location.href, link clicks)
|
||||
// - will-redirect fires for server-side 302 redirects (OAuth callback chain)
|
||||
const interceptLoginRedirect = (event, navigatedUrl) => {
|
||||
// Use a navigation listener to detect when the remote login is complete
|
||||
win.webContents.on('will-navigate', (event, navigatedUrl) => {
|
||||
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 === '/') {
|
||||
if (urlObj.searchParams.has('token')) {
|
||||
console.log("Detected login success redirect, returning to desktop UI...");
|
||||
|
|
@ -179,22 +108,10 @@ function createWindow() {
|
|||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
win.webContents.on('will-navigate', interceptLoginRedirect);
|
||||
win.webContents.on('will-redirect', interceptLoginRedirect);
|
||||
});
|
||||
|
||||
loadDesktopApp();
|
||||
|
||||
// Ensure renderer receives latest updater state after any (re)load.
|
||||
// Delay broadcast by 300ms to give the renderer time to register its
|
||||
// onUpdateState IPC listener before we push state.
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
setTimeout(() => {
|
||||
if (!win.isDestroyed()) broadcastUpdateState();
|
||||
}, 300);
|
||||
});
|
||||
|
||||
// Uncomment to debug
|
||||
// win.webContents.openDevTools();
|
||||
}
|
||||
|
|
@ -203,46 +120,6 @@ app.commandLine.appendSwitch('disable-webrtc-hw-encoding'); // Sometime helps re
|
|||
app.commandLine.appendSwitch('log-level', '3'); // Silences standard Chromium warning logs (like SRTP transport unprotect logs which are benign timing issues)
|
||||
|
||||
app.whenReady().then(() => {
|
||||
// Register IPC handlers once (before creating any windows)
|
||||
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;
|
||||
});
|
||||
|
||||
ipcMain.handle('storage-get', (event, key) => {
|
||||
if (typeof key !== 'string' || key.length === 0) return null;
|
||||
const store = readPersistentStore();
|
||||
return Object.prototype.hasOwnProperty.call(store, key) ? store[key] : null;
|
||||
});
|
||||
|
||||
ipcMain.handle('storage-set', (event, key, value) => {
|
||||
if (typeof key !== 'string' || key.length === 0) return false;
|
||||
const store = readPersistentStore();
|
||||
store[key] = value;
|
||||
writePersistentStore(store);
|
||||
return true;
|
||||
});
|
||||
|
||||
ipcMain.handle('storage-remove', (event, key) => {
|
||||
if (typeof key !== 'string' || key.length === 0) return false;
|
||||
const store = readPersistentStore();
|
||||
delete store[key];
|
||||
writePersistentStore(store);
|
||||
return true;
|
||||
});
|
||||
|
||||
ipcMain.handle('get-update-state', () => ({ ...updateState }));
|
||||
ipcMain.handle('check-for-updates-now', async () => {
|
||||
await runUpdateCheck('renderer-direct');
|
||||
return { ...updateState };
|
||||
});
|
||||
|
||||
createWindow();
|
||||
|
||||
// Configure Auto-Updater
|
||||
|
|
@ -250,46 +127,27 @@ app.whenReady().then(() => {
|
|||
autoUpdater.logger = console;
|
||||
|
||||
autoUpdater.on('update-available', (info) => {
|
||||
updateState.status = 'available';
|
||||
updateState.info = info;
|
||||
updateState.error = null;
|
||||
broadcastUpdateState();
|
||||
const wins = BrowserWindow.getAllWindows();
|
||||
if (wins.length > 0) wins[0].webContents.send('update-available', info);
|
||||
});
|
||||
|
||||
autoUpdater.on('update-not-available', (info) => {
|
||||
updateState.status = 'not-available';
|
||||
updateState.info = info || null;
|
||||
updateState.error = null;
|
||||
broadcastUpdateState();
|
||||
});
|
||||
|
||||
autoUpdater.on('update-downloaded', (info) => {
|
||||
updateState.status = 'downloaded';
|
||||
updateState.info = info;
|
||||
updateState.error = null;
|
||||
broadcastUpdateState();
|
||||
const wins = BrowserWindow.getAllWindows();
|
||||
if (wins.length > 0) wins[0].webContents.send('update-downloaded', info);
|
||||
});
|
||||
|
||||
autoUpdater.on('error', (err) => {
|
||||
updateState.status = 'error';
|
||||
updateState.error = err.message;
|
||||
broadcastUpdateState();
|
||||
const wins = BrowserWindow.getAllWindows();
|
||||
if (wins.length > 0) wins[0].webContents.send('update-error', err.message);
|
||||
});
|
||||
|
||||
ipcMain.on('check-for-updates', () => {
|
||||
void runUpdateCheck('manual');
|
||||
autoUpdater.checkForUpdatesAndNotify().catch(err => {
|
||||
console.error("Manual update check failed", err);
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('download-update', () => {
|
||||
updateState.status = 'downloading';
|
||||
updateState.error = null;
|
||||
broadcastUpdateState();
|
||||
autoUpdater.downloadUpdate();
|
||||
});
|
||||
|
||||
|
|
@ -299,7 +157,7 @@ app.whenReady().then(() => {
|
|||
|
||||
// Check once on startup
|
||||
setTimeout(() => {
|
||||
void runUpdateCheck('startup');
|
||||
autoUpdater.checkForUpdatesAndNotify().catch(() => { });
|
||||
}, 5000);
|
||||
|
||||
app.on('activate', () => {
|
||||
|
|
|
|||
1932
static/app.js
1932
static/app.js
File diff suppressed because it is too large
Load diff
|
|
@ -265,7 +265,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script type="module" src="/static/app.js?v=20260227-shared-core-1"></script>
|
||||
<script src="/static/app.js?v=20260225-voice-audiofix-1" defer></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue