Upload via GUI (74 Dateien)
This commit is contained in:
+21
-5
@@ -3,6 +3,9 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
app.setAppUserModelId('de.deskhub.desktop');
|
||||
// Windows hat eine eigene Titelleiste und ein .ico; Mac und Linux nutzen den normalen Fensterrahmen und ein PNG
|
||||
const IS_WIN = process.platform === 'win32', IS_MAC = process.platform === 'darwin', IS_LINUX = process.platform === 'linux';
|
||||
const ICON = path.join(__dirname, 'assets', IS_WIN ? 'icon.ico' : 'icon.png');
|
||||
let win = null;
|
||||
const sessionFile = () => path.join(app.getPath('userData'), 'session.bin');
|
||||
|
||||
@@ -18,7 +21,7 @@ function loadSession() {
|
||||
function saveSession() {
|
||||
if (!session) { try { fs.unlinkSync(sessionFile()); } catch {} return; }
|
||||
const json = JSON.stringify(session);
|
||||
fs.writeFileSync(sessionFile(), safeStorage.isEncryptionAvailable() ? safeStorage.encryptString(json) : json);
|
||||
fs.writeFileSync(sessionFile(), safeStorage.isEncryptionAvailable() ? safeStorage.encryptString(json) : json, { mode: 0o600 });
|
||||
}
|
||||
|
||||
function normalizeUrl(input) {
|
||||
@@ -97,6 +100,7 @@ function isNewer(remote, local) {
|
||||
}
|
||||
let pendingUpdate = null;
|
||||
ipcMain.handle('update:check', async () => {
|
||||
if (!IS_WIN) return { data: { available: false, packaged: false, current: app.getVersion(), unsupported: true } }; // das veröffentlichte Setup ist nur für Windows
|
||||
try {
|
||||
const r = await callApi({ path: 'app_update.php', query: { platform: 'windows' } });
|
||||
const d = r.data;
|
||||
@@ -106,6 +110,7 @@ ipcMain.handle('update:check', async () => {
|
||||
} catch (e) { return { error: { message: e.message || String(e) } }; }
|
||||
});
|
||||
ipcMain.handle('update:install', async () => {
|
||||
if (!IS_WIN) return { error: { message: 'Das Update ist nur für Windows verfügbar.' } };
|
||||
if (!pendingUpdate || !session) return { error: { message: 'Keine Update-Information vorhanden.' } };
|
||||
try {
|
||||
const url = new URL(`${session.serverUrl}/api/staff/v1/app_update.php`);
|
||||
@@ -163,6 +168,17 @@ function loadSettings() { try { settings = { ...DEFAULTS, ...JSON.parse(fs.readF
|
||||
function saveSettings() { try { fs.writeFileSync(settingsFile(), JSON.stringify(settings)); } catch {} }
|
||||
function applyAutostart() {
|
||||
if (!app.isPackaged) return;
|
||||
if (IS_LINUX) { // Electron kennt dort kein setLoginItemSettings: ~/.config/autostart/deskhub.desktop (bei AppImage zeigt APPIMAGE auf die Datei)
|
||||
const file = path.join(app.getPath('home'), '.config', 'autostart', 'deskhub.desktop');
|
||||
try {
|
||||
if (settings.autostart) {
|
||||
const exe = String(process.env.APPIMAGE || process.execPath).replace(/["\r\n]/g, '');
|
||||
fs.mkdirSync(path.dirname(file), { recursive: true });
|
||||
fs.writeFileSync(file, `[Desktop Entry]\nType=Application\nName=DeskHub\nExec="${exe}" --hidden\nIcon=deskhub\nX-GNOME-Autostart-enabled=true\n`);
|
||||
} else fs.rmSync(file, { force: true });
|
||||
} catch { /* ohne Schreibrecht kein Autostart */ }
|
||||
return;
|
||||
}
|
||||
app.setLoginItemSettings({ openAtLogin: !!settings.autostart, args: settings.autostart ? ['--hidden'] : [] });
|
||||
}
|
||||
ipcMain.handle('settings:get', () => ({ ...settings, version: app.getVersion(), packaged: app.isPackaged }));
|
||||
@@ -191,7 +207,7 @@ function trayMenu() {
|
||||
]);
|
||||
}
|
||||
function createTray() {
|
||||
const img = nativeImage.createFromPath(path.join(__dirname, 'assets', 'icon.ico'));
|
||||
const img = nativeImage.createFromPath(ICON);
|
||||
tray = new Tray(img.resize({ width: 16, height: 16 }));
|
||||
tray.setToolTip('DeskHub');
|
||||
tray.setContextMenu(trayMenu());
|
||||
@@ -220,8 +236,8 @@ function createWindow() {
|
||||
const b = settings.bounds || {};
|
||||
win = new BrowserWindow({
|
||||
width: b.width || 1320, height: b.height || 840, x: b.x, y: b.y, minWidth: 960, minHeight: 620,
|
||||
show: false, titleBarStyle: 'hidden', titleBarOverlay: overlayFor(resolvedTheme()), backgroundColor: resolvedTheme() === 'light' ? '#eef1f5' : '#0d141d', title: 'DeskHub', autoHideMenuBar: true,
|
||||
icon: path.join(__dirname, 'assets', 'icon.ico'),
|
||||
show: false, ...(IS_WIN ? { titleBarStyle: 'hidden', titleBarOverlay: overlayFor(resolvedTheme()) } : {}), backgroundColor: resolvedTheme() === 'light' ? '#eef1f5' : '#0d141d', title: 'DeskHub', autoHideMenuBar: true,
|
||||
icon: ICON,
|
||||
webPreferences: { preload: path.join(__dirname, 'preload.js'), contextIsolation: true, nodeIntegration: false, sandbox: true, backgroundThrottling: false },
|
||||
});
|
||||
if (b.maximized) win.maximize();
|
||||
@@ -244,6 +260,6 @@ if (!lock) app.quit();
|
||||
else {
|
||||
app.on('second-instance', () => showWindow());
|
||||
app.on('before-quit', () => { quitting = true; });
|
||||
app.whenReady().then(() => { Menu.setApplicationMenu(null); loadSettings(); loadSession(); createWindow(); setImmediate(() => { createTray(); applyAutostart(); }); });
|
||||
app.whenReady().then(() => { Menu.setApplicationMenu(IS_MAC ? Menu.buildFromTemplate([{ role: 'appMenu' }, { role: 'editMenu' }, { role: 'windowMenu' }]) : null); loadSettings(); loadSession(); createWindow(); setImmediate(() => { createTray(); applyAutostart(); }); });
|
||||
app.on('window-all-closed', () => { if (quitting || !settings.closeToTray) app.quit(); });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user