u2a 3.2.6 → 3.3.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u2a",
3
- "version": "3.2.6",
3
+ "version": "3.3.0",
4
4
  "description": "URL to App - Turn any URL into a desktop application",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -29,7 +29,8 @@
29
29
  "inquirer": "^8.2.5",
30
30
  "open": "^8.4.0",
31
31
  "png-to-ico": "^2.1.8",
32
- "sharp": "^0.33.5"
32
+ "sharp": "^0.33.5",
33
+ "is-admin": "^3.0.0"
33
34
  },
34
35
  "homepage": "https://urltoapp.xyz",
35
36
  "repository": {
package/src/index.js CHANGED
@@ -1,58 +1,62 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- ver = process.versions.node;
3
+ const ver = process.versions.node;
4
4
 
5
5
  if (ver < '22.0.0') {
6
6
  console.error("You need a nodejs installation equal or superior to 22.0.0. Please upgrade your node installation and retry.");
7
7
  process.exit(1);
8
8
  }
9
9
 
10
-
11
10
  const { program } = require('commander');
12
11
  const { createApp } = require('./commands/create');
13
12
  const { listApps } = require('./commands/list');
14
13
  const { removeApp } = require('./commands/remove');
15
14
  const { version } = require('../package.json');
16
15
  const { setupConfig } = require('./utils/config');
16
+ const { checkNotRoot } = require('./utils/noroot');
17
17
 
18
- setupConfig();
18
+ (async () => {
19
+ await checkNotRoot();
19
20
 
20
- program
21
- .name('u2a')
22
- .description('Convert websites into desktop applications')
23
- .version(version);
21
+ setupConfig();
24
22
 
25
23
  program
26
- .command('create <url>')
27
- .description('Create a new application from a URL')
28
- .option('--name <name>', 'Specify the application name')
29
- .option('--width <width>', 'Specify the window width', parseInt)
30
- .option('--height <height>', 'Specify the window height', parseInt)
31
- .option('--executable [windows|darwin|linux]', 'Create a single executable for the target system')
32
- .option('--arch [x64|armv7l|arm64|universal]', 'Specify the target architecture for the executable')
33
- .option('--setup', 'Creates a setup file for the executable')
34
- .action((url, options) => {
35
- createApp(url, options);
36
- });
24
+ .name('u2a')
25
+ .description('Convert websites into desktop applications')
26
+ .version(version);
37
27
 
38
- program
39
- .command('list')
40
- .description('List all available applications')
41
- .action(listApps);
28
+ program
29
+ .command('create <url>')
30
+ .description('Create a new application from a URL')
31
+ .option('--name <name>', 'Specify the application name')
32
+ .option('--width <width>', 'Specify the window width', parseInt)
33
+ .option('--height <height>', 'Specify the window height', parseInt)
34
+ .option('--executable [windows|darwin|linux]', 'Create a single executable for the target system')
35
+ .option('--arch [x64|armv7l|arm64|universal]', 'Specify the target architecture for the executable')
36
+ .option('--setup', 'Creates a setup file for the executable')
37
+ .action((url, options) => {
38
+ createApp(url, options);
39
+ });
42
40
 
43
- program
44
- .command('remove <url>')
45
- .description('Remove an existing application')
46
- .action(removeApp);
41
+ program
42
+ .command('list')
43
+ .description('List all available applications')
44
+ .action(listApps);
47
45
 
48
- program.on('command:*', () => {
49
- console.error(`\nInvalid command: ${program.args.join(' ')}`);
50
- console.log(`\nUse --help to see the list of available commands.`);
51
- process.exit(1);
52
- });
46
+ program
47
+ .command('remove <url>')
48
+ .description('Remove an existing application')
49
+ .action(removeApp);
50
+
51
+ program.on('command:*', () => {
52
+ console.error(`\nInvalid command: ${program.args.join(' ')}`);
53
+ console.log(`\nUse --help to see the list of available commands.`);
54
+ process.exit(1);
55
+ });
53
56
 
54
- program.parse(process.argv);
57
+ program.parse(process.argv);
55
58
 
56
- if (process.argv.length <= 2) {
57
- program.help();
58
- }
59
+ if (process.argv.length <= 2) {
60
+ program.help();
61
+ }
62
+ })();
@@ -0,0 +1,32 @@
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() {
8
+ const platform = os.platform();
9
+
10
+ switch (platform) {
11
+ case 'win32':
12
+ if (await isAdmin()) {
13
+ logger.error('This application should not be run as an administrator.', '');
14
+ process.exit(1);
15
+ }
16
+ break;
17
+
18
+ case 'darwin':
19
+ case 'linux':
20
+ if (process.getuid() === 0) {
21
+ logger.error('This application should not be run as root.', '');
22
+ process.exit(1);
23
+ }
24
+ break;
25
+
26
+ default:
27
+ logger.error('Unsupported platform:', platform);
28
+ process.exit(1);
29
+ }
30
+ }
31
+
32
+ module.exports = { checkNotRoot };