u2a 3.5.5 → 3.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +9 -4
- package/src/commands/configure.js +184 -184
- package/src/utils/app.js +243 -243
- package/src/utils/appGenerator.js +124 -124
- package/src/utils/builder.js +125 -125
- package/src/utils/config.js +3 -3
- package/src/utils/logger.js +1 -1
- package/src/utils/noroot.js +41 -41
- package/src/utils/osIntegration.js +187 -187
- package/src/utils/postinstall.js +156 -156
- package/src/utils/sanitize.js +20 -20
- package/src/utils/securexec.js +12 -12
- package/src/utils/settings.js +114 -114
- package/src/utils/upgradeLA.js +140 -140
- package/src/utils/url.js +12 -9
- package/src/utils/versionCheck.js +149 -149
- package/.github/workflows/npm-publish.yml +0 -22
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
//Todo: replace electron logo with the one of the app in popup windows
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const Logger = require('./logger');
|
|
7
|
-
|
|
8
|
-
const logger = new Logger('appGenerator');
|
|
9
|
-
|
|
10
|
-
function generateMainJs(appName, url, iconPath, options = {}) {
|
|
11
|
-
const width = options.width || 1200;
|
|
12
|
-
const height = options.height || 800;
|
|
13
|
-
|
|
14
|
-
const templatePath = path.join(__dirname, 'app.js');
|
|
15
|
-
let template;
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
template = fs.readFileSync(templatePath, 'utf8');
|
|
19
|
-
} catch (error) {
|
|
20
|
-
logger.error('Error reading electronApp.js template', error);
|
|
21
|
-
throw new Error('Failed to read Electron application template');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const mainJs = template
|
|
25
|
-
.replace('{APP_NAME}', appName)
|
|
26
|
-
.replace('{APP_URL}', url)
|
|
27
|
-
.replace('{APP_ICON_PATH}', iconPath.replace(/\\/g, '\\\\'))
|
|
28
|
-
.replace('{WINDOW_WIDTH}', width)
|
|
29
|
-
.replace('{WINDOW_HEIGHT}', height);
|
|
30
|
-
|
|
31
|
-
return mainJs;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function createPackageJson(appName, iconPath, isExecutable = false, createSetup = false) {
|
|
35
|
-
const u2aPackagePath = path.resolve(__dirname, '../../package.json');
|
|
36
|
-
|
|
37
|
-
let u2aVersion = '1.0.0';
|
|
38
|
-
try {
|
|
39
|
-
const u2aPackageContent = fs.readFileSync(u2aPackagePath, 'utf8');
|
|
40
|
-
const u2aPackage = JSON.parse(u2aPackageContent);
|
|
41
|
-
u2aVersion = u2aPackage.version || u2aVersion;
|
|
42
|
-
} catch (error) {
|
|
43
|
-
logger.error('Error while fetching u2a package.json', error);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (createSetup) {
|
|
47
|
-
const { processFavicon } = require('./favicon');
|
|
48
|
-
iconPath = await processFavicon(iconPath);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const packageJson = {
|
|
52
|
-
name: `u2a-${appName.replace(/\s+/g, '-')}`,
|
|
53
|
-
version: u2aVersion,
|
|
54
|
-
description: `Web app for ${appName}`,
|
|
55
|
-
main: 'main.js',
|
|
56
|
-
author: `${appName}`,
|
|
57
|
-
scripts: {
|
|
58
|
-
start: 'electron .'
|
|
59
|
-
},
|
|
60
|
-
dependencies: {
|
|
61
|
-
electron: '^22.0.0'
|
|
62
|
-
},
|
|
63
|
-
build: {
|
|
64
|
-
appId: `com.u2a.${appName.replace(/\s+/g, '-')}`,
|
|
65
|
-
productName: appName,
|
|
66
|
-
icon: iconPath
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
if (isExecutable) {
|
|
71
|
-
packageJson.devDependencies = {
|
|
72
|
-
"electron-packager": "^17.1.1",
|
|
73
|
-
"electron-builder": "^24.6.3",
|
|
74
|
-
"electron": "^22.0.0"
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
packageJson.dependencies = {};
|
|
78
|
-
|
|
79
|
-
packageJson.scripts.package = "electron-packager . --overwrite --asar";
|
|
80
|
-
packageJson.scripts.setup = "electron-builder";
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (isExecutable && createSetup) {
|
|
84
|
-
packageJson.build = {
|
|
85
|
-
...packageJson.build,
|
|
86
|
-
appId: `com.u2a.${appName.replace(/\s+/g, '-')}`,
|
|
87
|
-
productName: appName,
|
|
88
|
-
directories: {
|
|
89
|
-
output: "installer"
|
|
90
|
-
},
|
|
91
|
-
files: [
|
|
92
|
-
"**/*",
|
|
93
|
-
"!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme}",
|
|
94
|
-
"!**/node_modules/*/{test,__tests__,tests,powered-test,example,examples}",
|
|
95
|
-
"!**/node_modules/*.d.ts",
|
|
96
|
-
"!**/node_modules/.bin",
|
|
97
|
-
"!**/.{idea,git,cache,build,dist}",
|
|
98
|
-
"!dist/**/*",
|
|
99
|
-
"!installer/**/*"
|
|
100
|
-
],
|
|
101
|
-
win: {
|
|
102
|
-
target: "nsis",
|
|
103
|
-
icon: iconPath
|
|
104
|
-
},
|
|
105
|
-
mac: {
|
|
106
|
-
target: "dmg"
|
|
107
|
-
},
|
|
108
|
-
linux: {
|
|
109
|
-
target: "AppImage",
|
|
110
|
-
icon: iconPath
|
|
111
|
-
},
|
|
112
|
-
nsis: {
|
|
113
|
-
oneClick: false,
|
|
114
|
-
allowToChangeInstallationDirectory: true
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return packageJson;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
module.exports = {
|
|
123
|
-
generateMainJs,
|
|
124
|
-
createPackageJson
|
|
1
|
+
//Todo: replace electron logo with the one of the app in popup windows
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const Logger = require('./logger');
|
|
7
|
+
|
|
8
|
+
const logger = new Logger('appGenerator');
|
|
9
|
+
|
|
10
|
+
function generateMainJs(appName, url, iconPath, options = {}) {
|
|
11
|
+
const width = options.width || 1200;
|
|
12
|
+
const height = options.height || 800;
|
|
13
|
+
|
|
14
|
+
const templatePath = path.join(__dirname, 'app.js');
|
|
15
|
+
let template;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
template = fs.readFileSync(templatePath, 'utf8');
|
|
19
|
+
} catch (error) {
|
|
20
|
+
logger.error('Error reading electronApp.js template', error);
|
|
21
|
+
throw new Error('Failed to read Electron application template');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const mainJs = template
|
|
25
|
+
.replace('{APP_NAME}', appName)
|
|
26
|
+
.replace('{APP_URL}', url)
|
|
27
|
+
.replace('{APP_ICON_PATH}', iconPath.replace(/\\/g, '\\\\'))
|
|
28
|
+
.replace('{WINDOW_WIDTH}', width)
|
|
29
|
+
.replace('{WINDOW_HEIGHT}', height);
|
|
30
|
+
|
|
31
|
+
return mainJs;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function createPackageJson(appName, iconPath, isExecutable = false, createSetup = false) {
|
|
35
|
+
const u2aPackagePath = path.resolve(__dirname, '../../package.json');
|
|
36
|
+
|
|
37
|
+
let u2aVersion = '1.0.0';
|
|
38
|
+
try {
|
|
39
|
+
const u2aPackageContent = fs.readFileSync(u2aPackagePath, 'utf8');
|
|
40
|
+
const u2aPackage = JSON.parse(u2aPackageContent);
|
|
41
|
+
u2aVersion = u2aPackage.version || u2aVersion;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
logger.error('Error while fetching u2a package.json', error);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (createSetup) {
|
|
47
|
+
const { processFavicon } = require('./favicon');
|
|
48
|
+
iconPath = await processFavicon(iconPath);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const packageJson = {
|
|
52
|
+
name: `u2a-${appName.replace(/\s+/g, '-')}`,
|
|
53
|
+
version: u2aVersion,
|
|
54
|
+
description: `Web app for ${appName}`,
|
|
55
|
+
main: 'main.js',
|
|
56
|
+
author: `${appName}`,
|
|
57
|
+
scripts: {
|
|
58
|
+
start: 'electron .'
|
|
59
|
+
},
|
|
60
|
+
dependencies: {
|
|
61
|
+
electron: '^22.0.0'
|
|
62
|
+
},
|
|
63
|
+
build: {
|
|
64
|
+
appId: `com.u2a.${appName.replace(/\s+/g, '-')}`,
|
|
65
|
+
productName: appName,
|
|
66
|
+
icon: iconPath
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (isExecutable) {
|
|
71
|
+
packageJson.devDependencies = {
|
|
72
|
+
"electron-packager": "^17.1.1",
|
|
73
|
+
"electron-builder": "^24.6.3",
|
|
74
|
+
"electron": "^22.0.0"
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
packageJson.dependencies = {};
|
|
78
|
+
|
|
79
|
+
packageJson.scripts.package = "electron-packager . --overwrite --asar";
|
|
80
|
+
packageJson.scripts.setup = "electron-builder";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (isExecutable && createSetup) {
|
|
84
|
+
packageJson.build = {
|
|
85
|
+
...packageJson.build,
|
|
86
|
+
appId: `com.u2a.${appName.replace(/\s+/g, '-')}`,
|
|
87
|
+
productName: appName,
|
|
88
|
+
directories: {
|
|
89
|
+
output: "installer"
|
|
90
|
+
},
|
|
91
|
+
files: [
|
|
92
|
+
"**/*",
|
|
93
|
+
"!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme}",
|
|
94
|
+
"!**/node_modules/*/{test,__tests__,tests,powered-test,example,examples}",
|
|
95
|
+
"!**/node_modules/*.d.ts",
|
|
96
|
+
"!**/node_modules/.bin",
|
|
97
|
+
"!**/.{idea,git,cache,build,dist}",
|
|
98
|
+
"!dist/**/*",
|
|
99
|
+
"!installer/**/*"
|
|
100
|
+
],
|
|
101
|
+
win: {
|
|
102
|
+
target: "nsis",
|
|
103
|
+
icon: iconPath
|
|
104
|
+
},
|
|
105
|
+
mac: {
|
|
106
|
+
target: "dmg"
|
|
107
|
+
},
|
|
108
|
+
linux: {
|
|
109
|
+
target: "AppImage",
|
|
110
|
+
icon: iconPath
|
|
111
|
+
},
|
|
112
|
+
nsis: {
|
|
113
|
+
oneClick: false,
|
|
114
|
+
allowToChangeInstallationDirectory: true
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return packageJson;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
module.exports = {
|
|
123
|
+
generateMainJs,
|
|
124
|
+
createPackageJson
|
|
125
125
|
};
|
package/src/utils/builder.js
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const Logger = require('./logger');
|
|
4
|
-
const { secureExec } = require('./securexec');
|
|
5
|
-
|
|
6
|
-
const logger = new Logger('builder');
|
|
7
|
-
|
|
8
|
-
async function buildExecutable(appDir, appName, platform, iconPath, options) {
|
|
9
|
-
logger.info(`Building executable for ${platform}...`);
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
const installOptions = {
|
|
13
|
-
cwd: appDir,
|
|
14
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
15
|
-
windowsHide: true
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
secureExec('npm install --save-dev electron-packager electron', installOptions);
|
|
19
|
-
|
|
20
|
-
let platformFlag = '';
|
|
21
|
-
let archFlag = `--arch=${options.arch || 'x64'}`;
|
|
22
|
-
let iconOption = '';
|
|
23
|
-
|
|
24
|
-
switch (platform) {
|
|
25
|
-
case 'windows':
|
|
26
|
-
platformFlag = '--platform=win32';
|
|
27
|
-
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
28
|
-
break;
|
|
29
|
-
case 'darwin':
|
|
30
|
-
platformFlag = '--platform=darwin';
|
|
31
|
-
if (iconPath && !iconPath.endsWith('.icns')) {
|
|
32
|
-
logger.warn('MacOs Icons are not supported at this time.');
|
|
33
|
-
}
|
|
34
|
-
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
35
|
-
break;
|
|
36
|
-
case 'linux':
|
|
37
|
-
platformFlag = '--platform=linux';
|
|
38
|
-
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
platformFlag = `--platform=${process.platform}`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const packageCommand = `npx electron-packager . "${appName}" ${platformFlag} ${archFlag} --out=dist --overwrite --asar ${iconOption}`;
|
|
45
|
-
|
|
46
|
-
logger.debug(`Executing: ${packageCommand}`);
|
|
47
|
-
|
|
48
|
-
secureExec(packageCommand, installOptions);
|
|
49
|
-
|
|
50
|
-
let distPlatform = '';
|
|
51
|
-
switch (platform) {
|
|
52
|
-
case 'windows': distPlatform = 'win32'; break;
|
|
53
|
-
case 'darwin': distPlatform = 'darwin'; break;
|
|
54
|
-
case 'linux': distPlatform = 'linux'; break;
|
|
55
|
-
default: distPlatform = process.platform;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const outputPath = path.join(appDir, 'dist', `${appName}-${distPlatform}-x64`);
|
|
59
|
-
|
|
60
|
-
if (fs.existsSync(outputPath)) {
|
|
61
|
-
logger.debug(`Executable built successfully at: ${outputPath}`);
|
|
62
|
-
return outputPath;
|
|
63
|
-
} else {
|
|
64
|
-
logger.error(`Failed to find the built executable at: ${outputPath}`);
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
} catch (error) {
|
|
68
|
-
logger.error(`Error while building executable:`, error);
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async function buildSetup(appDir, platform, arch) {
|
|
74
|
-
logger.info(`Building setup for ${platform}${arch ? ` (${arch})` : ''}...`);
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const installOptions = {
|
|
78
|
-
cwd: appDir,
|
|
79
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
80
|
-
windowsHide: true
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
secureExec('npm install --save-dev electron-builder', installOptions);
|
|
84
|
-
|
|
85
|
-
let builderArgs = '';
|
|
86
|
-
switch (platform) {
|
|
87
|
-
case 'windows':
|
|
88
|
-
builderArgs = '--win';
|
|
89
|
-
break;
|
|
90
|
-
case 'darwin':
|
|
91
|
-
builderArgs = '--mac';
|
|
92
|
-
break;
|
|
93
|
-
case 'linux':
|
|
94
|
-
builderArgs = '--linux';
|
|
95
|
-
break;
|
|
96
|
-
default:
|
|
97
|
-
builderArgs = '';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (arch) {
|
|
101
|
-
builderArgs += ` --${arch}`;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const builderCommand = `npx electron-builder ${builderArgs}`;
|
|
105
|
-
logger.debug(`Executing: ${builderCommand}`);
|
|
106
|
-
secureExec(builderCommand, installOptions);
|
|
107
|
-
|
|
108
|
-
const installerPath = path.join(appDir, 'installer');
|
|
109
|
-
if (fs.existsSync(installerPath)) {
|
|
110
|
-
logger.debug(`Setup created at: ${installerPath}`);
|
|
111
|
-
return installerPath;
|
|
112
|
-
} else {
|
|
113
|
-
logger.error(`Failed to find the built installer at: ${installerPath}`);
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
} catch (error) {
|
|
117
|
-
logger.error(`Error while building setup.`, error);
|
|
118
|
-
logger.warn('Try to run u2a with administrator privileges to avoid this error.');
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
module.exports = {
|
|
124
|
-
buildExecutable,
|
|
125
|
-
buildSetup
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const Logger = require('./logger');
|
|
4
|
+
const { secureExec } = require('./securexec');
|
|
5
|
+
|
|
6
|
+
const logger = new Logger('builder');
|
|
7
|
+
|
|
8
|
+
async function buildExecutable(appDir, appName, platform, iconPath, options) {
|
|
9
|
+
logger.info(`Building executable for ${platform}...`);
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const installOptions = {
|
|
13
|
+
cwd: appDir,
|
|
14
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
15
|
+
windowsHide: true
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
secureExec('npm install --save-dev electron-packager electron', installOptions);
|
|
19
|
+
|
|
20
|
+
let platformFlag = '';
|
|
21
|
+
let archFlag = `--arch=${options.arch || 'x64'}`;
|
|
22
|
+
let iconOption = '';
|
|
23
|
+
|
|
24
|
+
switch (platform) {
|
|
25
|
+
case 'windows':
|
|
26
|
+
platformFlag = '--platform=win32';
|
|
27
|
+
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
28
|
+
break;
|
|
29
|
+
case 'darwin':
|
|
30
|
+
platformFlag = '--platform=darwin';
|
|
31
|
+
if (iconPath && !iconPath.endsWith('.icns')) {
|
|
32
|
+
logger.warn('MacOs Icons are not supported at this time.');
|
|
33
|
+
}
|
|
34
|
+
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
35
|
+
break;
|
|
36
|
+
case 'linux':
|
|
37
|
+
platformFlag = '--platform=linux';
|
|
38
|
+
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
platformFlag = `--platform=${process.platform}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const packageCommand = `npx electron-packager . "${appName}" ${platformFlag} ${archFlag} --out=dist --overwrite --asar ${iconOption}`;
|
|
45
|
+
|
|
46
|
+
logger.debug(`Executing: ${packageCommand}`);
|
|
47
|
+
|
|
48
|
+
secureExec(packageCommand, installOptions);
|
|
49
|
+
|
|
50
|
+
let distPlatform = '';
|
|
51
|
+
switch (platform) {
|
|
52
|
+
case 'windows': distPlatform = 'win32'; break;
|
|
53
|
+
case 'darwin': distPlatform = 'darwin'; break;
|
|
54
|
+
case 'linux': distPlatform = 'linux'; break;
|
|
55
|
+
default: distPlatform = process.platform;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const outputPath = path.join(appDir, 'dist', `${appName}-${distPlatform}-x64`);
|
|
59
|
+
|
|
60
|
+
if (fs.existsSync(outputPath)) {
|
|
61
|
+
logger.debug(`Executable built successfully at: ${outputPath}`);
|
|
62
|
+
return outputPath;
|
|
63
|
+
} else {
|
|
64
|
+
logger.error(`Failed to find the built executable at: ${outputPath}`);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
logger.error(`Error while building executable:`, error);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function buildSetup(appDir, platform, arch) {
|
|
74
|
+
logger.info(`Building setup for ${platform}${arch ? ` (${arch})` : ''}...`);
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const installOptions = {
|
|
78
|
+
cwd: appDir,
|
|
79
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
80
|
+
windowsHide: true
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
secureExec('npm install --save-dev electron-builder', installOptions);
|
|
84
|
+
|
|
85
|
+
let builderArgs = '';
|
|
86
|
+
switch (platform) {
|
|
87
|
+
case 'windows':
|
|
88
|
+
builderArgs = '--win';
|
|
89
|
+
break;
|
|
90
|
+
case 'darwin':
|
|
91
|
+
builderArgs = '--mac';
|
|
92
|
+
break;
|
|
93
|
+
case 'linux':
|
|
94
|
+
builderArgs = '--linux';
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
builderArgs = '';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (arch) {
|
|
101
|
+
builderArgs += ` --${arch}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const builderCommand = `npx electron-builder ${builderArgs}`;
|
|
105
|
+
logger.debug(`Executing: ${builderCommand}`);
|
|
106
|
+
secureExec(builderCommand, installOptions);
|
|
107
|
+
|
|
108
|
+
const installerPath = path.join(appDir, 'installer');
|
|
109
|
+
if (fs.existsSync(installerPath)) {
|
|
110
|
+
logger.debug(`Setup created at: ${installerPath}`);
|
|
111
|
+
return installerPath;
|
|
112
|
+
} else {
|
|
113
|
+
logger.error(`Failed to find the built installer at: ${installerPath}`);
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
} catch (error) {
|
|
117
|
+
logger.error(`Error while building setup.`, error);
|
|
118
|
+
logger.warn('Try to run u2a with administrator privileges to avoid this error.');
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
module.exports = {
|
|
124
|
+
buildExecutable,
|
|
125
|
+
buildSetup
|
|
126
126
|
}
|
package/src/utils/config.js
CHANGED
|
@@ -2,6 +2,7 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const os = require('os');
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
const CONFIG_DIR = path.join(os.homedir(), '.u2a');
|
|
6
7
|
const APPS_DIR = path.join(CONFIG_DIR, 'apps');
|
|
7
8
|
const LOGS_DIR = path.join(CONFIG_DIR, 'logs');
|
|
@@ -34,11 +35,10 @@ function writeDB(data) {
|
|
|
34
35
|
fs.writeFileSync(DB_PATH, JSON.stringify(data, null, 2));
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
function addAppToDB(
|
|
38
|
+
function addAppToDB(appName, appData) {
|
|
38
39
|
const db = readDB();
|
|
39
|
-
db[
|
|
40
|
+
db[appName] = appData;
|
|
40
41
|
writeDB(db);
|
|
41
|
-
logger.debug(`Application recorded in the database:`, domain);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
module.exports = {
|
package/src/utils/logger.js
CHANGED
package/src/utils/noroot.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
const os = require('os');
|
|
2
|
-
const isAdmin = require('is-admin');
|
|
3
|
-
const Logger = require('./logger')
|
|
4
|
-
|
|
5
|
-
const logger = new Logger('noroot');
|
|
6
|
-
|
|
7
|
-
async function checkNotRoot(allowRoot = false) {
|
|
8
|
-
if (allowRoot) {
|
|
9
|
-
logger.warn('Running with elevated privileges. This is not recommended.');
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const platform = os.platform();
|
|
14
|
-
|
|
15
|
-
switch (platform) {
|
|
16
|
-
case 'win32':
|
|
17
|
-
if (await isAdmin()) {
|
|
18
|
-
logger.error('This application should not be run as an administrator.');
|
|
19
|
-
logger.warn('Run with --allowroot to avoid this message.');
|
|
20
|
-
logger.warn('Running u2a as administrator can be dangerous.');
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
break;
|
|
24
|
-
|
|
25
|
-
case 'darwin':
|
|
26
|
-
case 'linux':
|
|
27
|
-
if (process.getuid() === 0) {
|
|
28
|
-
logger.error('This application should not be run as root.');
|
|
29
|
-
logger.warn('Run with --allowroot to avoid this message.');
|
|
30
|
-
logger.warn('Running u2a as root can be dangerous.');
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
break;
|
|
34
|
-
|
|
35
|
-
default:
|
|
36
|
-
logger.error('Unsupported platform:', platform);
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = { checkNotRoot };
|
|
1
|
+
const os = require('os');
|
|
2
|
+
const isAdmin = require('is-admin');
|
|
3
|
+
const Logger = require('./logger')
|
|
4
|
+
|
|
5
|
+
const logger = new Logger('noroot');
|
|
6
|
+
|
|
7
|
+
async function checkNotRoot(allowRoot = false) {
|
|
8
|
+
if (allowRoot) {
|
|
9
|
+
logger.warn('Running with elevated privileges. This is not recommended.');
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const platform = os.platform();
|
|
14
|
+
|
|
15
|
+
switch (platform) {
|
|
16
|
+
case 'win32':
|
|
17
|
+
if (await isAdmin()) {
|
|
18
|
+
logger.error('This application should not be run as an administrator.');
|
|
19
|
+
logger.warn('Run with --allowroot to avoid this message.');
|
|
20
|
+
logger.warn('Running u2a as administrator can be dangerous.');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
break;
|
|
24
|
+
|
|
25
|
+
case 'darwin':
|
|
26
|
+
case 'linux':
|
|
27
|
+
if (process.getuid() === 0) {
|
|
28
|
+
logger.error('This application should not be run as root.');
|
|
29
|
+
logger.warn('Run with --allowroot to avoid this message.');
|
|
30
|
+
logger.warn('Running u2a as root can be dangerous.');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
|
|
35
|
+
default:
|
|
36
|
+
logger.error('Unsupported platform:', platform);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = { checkNotRoot };
|