Repository navigation
Expand file tree
/
Copy pathportable.js
More file actions
36 lines (29 loc) · 1.42 KB
/
Copy pathportable.js
File metadata and controls
36 lines (29 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const { app } = require('electron');
const path = require('node:path');
const fs = require('node:fs');
function setupPortableMode() {
const exeDir = process.env.PORTABLE_EXECUTABLE_DIR || path.dirname(app.getPath('exe'));
const portableDataDir = path.join(exeDir, 'cove-app-data');
const markerFile = path.join(exeDir, 'portable.marker');
// A build produced by electron-builder's portable target always sets
// PORTABLE_EXECUTABLE_DIR, so treat that as portable even on first run
// before any data dir or marker exists — otherwise a pristine portable
// exe would silently write into the host user profile.
const isPortableBuild = !!process.env.PORTABLE_EXECUTABLE_DIR;
if (!isPortableBuild && !fs.existsSync(portableDataDir) && !fs.existsSync(markerFile)) {
return false;
}
fs.mkdirSync(portableDataDir, { recursive: true });
const appDataDir = path.join(portableDataDir, app.name);
fs.mkdirSync(appDataDir, { recursive: true });
app.setPath('userData', appDataDir);
app.setPath('appData', portableDataDir);
for (const sub of ['temp', 'cache', 'logs']) {
fs.mkdirSync(path.join(appDataDir, sub), { recursive: true });
}
app.setPath('temp', path.join(appDataDir, 'temp'));
app.setPath('sessionData', path.join(appDataDir, 'cache'));
app.setPath('logs', path.join(appDataDir, 'logs'));
return true;
}
module.exports = { setupPortableMode };