48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const path = require('node:path');
|
|
const fs = require('node:fs');
|
|
const { app } = require('electron');
|
|
|
|
const CORE_FILE = process.platform === 'win32' ? 'teamspeach-core.exe' : 'teamspeach-core';
|
|
const APP_ROOT = path.resolve(__dirname, '..', '..');
|
|
const RENDERER_DIR = path.join(APP_ROOT, 'app', 'renderer');
|
|
|
|
/** Candidate locations of the native core. Only main decides these; nothing comes from the renderer. */
|
|
function coreCandidates() {
|
|
if (app.isPackaged) return [path.join(process.resourcesPath, 'core', CORE_FILE)];
|
|
return [
|
|
path.join(APP_ROOT, 'core', 'target', 'release', CORE_FILE),
|
|
path.join(APP_ROOT, 'core', 'target', 'debug', CORE_FILE),
|
|
];
|
|
}
|
|
|
|
/** Newest existing candidate wins in development so a fresh debug build is not shadowed by a stale release build. */
|
|
function resolveCoreBinary() {
|
|
const candidates = coreCandidates();
|
|
let best = null;
|
|
for (const candidate of candidates) {
|
|
try {
|
|
const stat = fs.statSync(candidate);
|
|
if (stat.isFile() && (!best || stat.mtimeMs > best.mtimeMs)) best = { path: candidate, mtimeMs: stat.mtimeMs };
|
|
} catch {
|
|
// missing candidate
|
|
}
|
|
}
|
|
return { path: best ? best.path : null, candidates };
|
|
}
|
|
|
|
function dataDir() {
|
|
return path.join(app.getPath('userData'), 'core');
|
|
}
|
|
|
|
function logsDir() {
|
|
return path.join(app.getPath('userData'), 'logs');
|
|
}
|
|
|
|
function prefsFile() {
|
|
return path.join(app.getPath('userData'), 'prefs.json');
|
|
}
|
|
|
|
module.exports = { APP_ROOT, RENDERER_DIR, CORE_FILE, resolveCoreBinary, dataDir, logsDir, prefsFile };
|