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.
@@ -1,188 +1,188 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const os = require('os');
4
- const Logger = require('./logger');
5
- const { secureExec } = require('./securexec');
6
-
7
- const logger = new Logger('osIntegration');
8
-
9
- function createWindowsShortcut(appInfo) {
10
- try {
11
- const { appName, appDir, iconPath } = appInfo;
12
- const startMenuPath = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'U2A Apps');
13
-
14
- if (!fs.existsSync(startMenuPath)) {
15
- fs.mkdirSync(startMenuPath, { recursive: true });
16
- }
17
-
18
- const shortcutPath = path.join(startMenuPath, `${appName}.lnk`);
19
- const targetPath = path.join(appDir, 'node_modules', '.bin', 'electron.cmd');
20
- const workingDir = appDir;
21
-
22
- const psScript = `
23
- $WshShell = New-Object -comObject WScript.Shell
24
- $Shortcut = $WshShell.CreateShortcut("${shortcutPath.replace(/\\/g, '\\\\')}")
25
- $Shortcut.TargetPath = "${targetPath.replace(/\\/g, '\\\\')}"
26
- $Shortcut.Arguments = "."
27
- $Shortcut.WorkingDirectory = "${workingDir.replace(/\\/g, '\\\\')}"
28
- $Shortcut.IconLocation = "${iconPath.replace(/\\/g, '\\\\')}"
29
- $Shortcut.Description = "Application Web pour ${appName}"
30
- $Shortcut.Save()
31
- `;
32
-
33
- const tempScriptPath = path.join(os.tmpdir(), `create_shortcut_${appName}.ps1`);
34
- fs.writeFileSync(tempScriptPath, psScript);
35
-
36
- secureExec(`powershell -ExecutionPolicy Bypass -File "${tempScriptPath}"`, {
37
- stdio: ['ignore', 'pipe', 'pipe'],
38
- windowsHide: true
39
- });
40
-
41
- fs.unlinkSync(tempScriptPath);
42
-
43
- logger.success(`Shortcut created in the Start Menu: ${shortcutPath}`);
44
- return shortcutPath;
45
- } catch (error) {
46
- logger.error(`Error while creating the Windows shortcut`, error);
47
- return null;
48
- }
49
- }
50
-
51
- function createLinuxDesktopEntry(appInfo) {
52
- try {
53
- const { appName, url, appDir, iconPath } = appInfo;
54
- const appsDir = path.join(os.homedir(), '.local', 'share', 'applications');
55
-
56
- if (!fs.existsSync(appsDir)) {
57
- fs.mkdirSync(appsDir, { recursive: true });
58
- }
59
-
60
- const desktopEntry = `[Desktop Entry]
61
- Type=Application
62
- Name=${appName}
63
- Exec=${path.join(appDir, 'node_modules', '.bin', 'electron')} ${path.join(appDir, 'main.js')}
64
- Icon=${iconPath}
65
- Comment=Application Web pour ${url}
66
- Categories=Network;WebBrowser;
67
- Terminal=false
68
- `;
69
-
70
- const desktopFilePath = path.join(appsDir, `u2a-${appName}.desktop`);
71
- fs.writeFileSync(desktopFilePath, desktopEntry);
72
-
73
- fs.chmodSync(desktopFilePath, '755');
74
-
75
- logger.success(`Desktop entry created for Linux: ${desktopFilePath}`);
76
- return desktopFilePath;
77
- } catch (error) {
78
- logger.error(`Error while creating the Linux desktop entry`, error);
79
- return null;
80
- }
81
- }
82
-
83
- function createMacOSApp(appInfo) {
84
- try {
85
- const { appName, appDir, iconPath } = appInfo;
86
- const appsDir = path.join(os.homedir(), 'Applications', 'U2A Apps');
87
-
88
- if (!fs.existsSync(appsDir)) {
89
- fs.mkdirSync(appsDir, { recursive: true });
90
- }
91
-
92
- const appPath = path.join(appsDir, `${appName}.app`);
93
- const macOsPath = path.join(appPath, 'Contents', 'MacOS');
94
- const resourcesPath = path.join(appPath, 'Contents', 'Resources');
95
-
96
- fs.mkdirSync(path.join(appPath, 'Contents', 'MacOS'), { recursive: true });
97
- fs.mkdirSync(resourcesPath, { recursive: true });
98
-
99
- const infoPlist = `<?xml version="1.0" encoding="UTF-8"?>
100
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
101
- <plist version="1.0">
102
- <dict>
103
- <key>CFBundleExecutable</key>
104
- <string>AppRunner</string>
105
- <key>CFBundleIconFile</key>
106
- <string>icon.icns</string>
107
- <key>CFBundleIdentifier</key>
108
- <string>com.u2a.${appName.replace(/\s+/g, '-')}</string>
109
- <key>CFBundleName</key>
110
- <string>${appName}</string>
111
- <key>CFBundleDisplayName</key>
112
- <string>${appName}</string>
113
- <key>CFBundlePackageType</key>
114
- <string>APPL</string>
115
- <key>CFBundleVersion</key>
116
- <string>1.0</string>
117
- <key>CFBundleShortVersionString</key>
118
- <string>1.0</string>
119
- </dict>
120
- </plist>`;
121
-
122
- fs.writeFileSync(path.join(appPath, 'Contents', 'Info.plist'), infoPlist);
123
-
124
- const shellScript = `#!/bin/bash
125
- cd "${appDir}"
126
- "${path.join(appDir, 'node_modules', '.bin', 'electron')}" "${path.join(appDir, 'main.js')}"`;
127
-
128
- const shellScriptPath = path.join(macOsPath, 'AppRunner');
129
- fs.writeFileSync(shellScriptPath, shellScript);
130
- fs.chmodSync(shellScriptPath, '755');
131
-
132
- fs.copyFileSync(iconPath, path.join(resourcesPath, 'icon.icns'));
133
-
134
- logger.success(`macOS application created: ${appPath}`);
135
- return appPath;
136
- } catch (error) {
137
- logger.error(`Error while creating the macOS application`, error);
138
- return null;
139
- }
140
- }
141
-
142
- function addAppToOS(appName, url, appDir, iconPath) {
143
- const appInfo = { appName, url, appDir, iconPath };
144
- let desktopPath = null;
145
-
146
- if (process.platform === 'win32') {
147
- desktopPath = createWindowsShortcut(appInfo);
148
- } else if (process.platform === 'darwin') {
149
- desktopPath = createMacOSApp(appInfo);
150
- } else if (process.platform === 'linux') {
151
- desktopPath = createLinuxDesktopEntry(appInfo);
152
- } else {
153
- logger.warn(`Desktop integration not supported for platform ${process.platform}`);
154
- }
155
-
156
- return desktopPath;
157
- }
158
-
159
- function removeAppFromOS(appName) {
160
- try {
161
- if (process.platform === 'win32') {
162
- const startMenuPath = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'U2A Apps', `${appName}.lnk`);
163
- if (fs.existsSync(startMenuPath)) {
164
- fs.unlinkSync(startMenuPath);
165
- logger.success(`Shortcut removed from the Start Menu: ${startMenuPath}`);
166
- }
167
- } else if (process.platform === 'darwin') {
168
- const appPath = path.join(os.homedir(), 'Applications', 'U2A Apps', `${appName}.app`);
169
- if (fs.existsSync(appPath)) {
170
- fs.rmSync(appPath, { recursive: true, force: true });
171
- logger.success(`macOS application removed: ${appPath}`);
172
- }
173
- } else if (process.platform === 'linux') {
174
- const desktopFilePath = path.join(os.homedir(), '.local', 'share', 'applications', `u2a-${appName}.desktop`);
175
- if (fs.existsSync(desktopFilePath)) {
176
- fs.unlinkSync(desktopFilePath);
177
- logger.success(`Linux desktop entry removed: ${desktopFilePath}`);
178
- }
179
- }
180
- } catch (error) {
181
- logger.error(`Error while removing desktop integration for ${appName}`, error);
182
- }
183
- }
184
-
185
- module.exports = {
186
- addAppToOS,
187
- removeAppFromOS
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const os = require('os');
4
+ const Logger = require('./logger');
5
+ const { secureExec } = require('./securexec');
6
+
7
+ const logger = new Logger('osIntegration');
8
+
9
+ function createWindowsShortcut(appInfo) {
10
+ try {
11
+ const { appName, appDir, iconPath } = appInfo;
12
+ const startMenuPath = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'U2A Apps');
13
+
14
+ if (!fs.existsSync(startMenuPath)) {
15
+ fs.mkdirSync(startMenuPath, { recursive: true });
16
+ }
17
+
18
+ const shortcutPath = path.join(startMenuPath, `${appName}.lnk`);
19
+ const targetPath = path.join(appDir, 'node_modules', '.bin', 'electron.cmd');
20
+ const workingDir = appDir;
21
+
22
+ const psScript = `
23
+ $WshShell = New-Object -comObject WScript.Shell
24
+ $Shortcut = $WshShell.CreateShortcut("${shortcutPath.replace(/\\/g, '\\\\')}")
25
+ $Shortcut.TargetPath = "${targetPath.replace(/\\/g, '\\\\')}"
26
+ $Shortcut.Arguments = "."
27
+ $Shortcut.WorkingDirectory = "${workingDir.replace(/\\/g, '\\\\')}"
28
+ $Shortcut.IconLocation = "${iconPath.replace(/\\/g, '\\\\')}"
29
+ $Shortcut.Description = "Application Web pour ${appName}"
30
+ $Shortcut.Save()
31
+ `;
32
+
33
+ const tempScriptPath = path.join(os.tmpdir(), `create_shortcut_${appName}.ps1`);
34
+ fs.writeFileSync(tempScriptPath, psScript);
35
+
36
+ secureExec(`powershell -ExecutionPolicy Bypass -File "${tempScriptPath}"`, {
37
+ stdio: ['ignore', 'pipe', 'pipe'],
38
+ windowsHide: true
39
+ });
40
+
41
+ fs.unlinkSync(tempScriptPath);
42
+
43
+ logger.success(`Shortcut created in the Start Menu: ${shortcutPath}`);
44
+ return shortcutPath;
45
+ } catch (error) {
46
+ logger.error(`Error while creating the Windows shortcut`, error);
47
+ return null;
48
+ }
49
+ }
50
+
51
+ function createLinuxDesktopEntry(appInfo) {
52
+ try {
53
+ const { appName, url, appDir, iconPath } = appInfo;
54
+ const appsDir = path.join(os.homedir(), '.local', 'share', 'applications');
55
+
56
+ if (!fs.existsSync(appsDir)) {
57
+ fs.mkdirSync(appsDir, { recursive: true });
58
+ }
59
+
60
+ const desktopEntry = `[Desktop Entry]
61
+ Type=Application
62
+ Name=${appName}
63
+ Exec=${path.join(appDir, 'node_modules', '.bin', 'electron')} ${path.join(appDir, 'main.js')}
64
+ Icon=${iconPath}
65
+ Comment=Application Web pour ${url}
66
+ Categories=Network;WebBrowser;
67
+ Terminal=false
68
+ `;
69
+
70
+ const desktopFilePath = path.join(appsDir, `u2a-${appName}.desktop`);
71
+ fs.writeFileSync(desktopFilePath, desktopEntry);
72
+
73
+ fs.chmodSync(desktopFilePath, '755');
74
+
75
+ logger.success(`Desktop entry created for Linux: ${desktopFilePath}`);
76
+ return desktopFilePath;
77
+ } catch (error) {
78
+ logger.error(`Error while creating the Linux desktop entry`, error);
79
+ return null;
80
+ }
81
+ }
82
+
83
+ function createMacOSApp(appInfo) {
84
+ try {
85
+ const { appName, appDir, iconPath } = appInfo;
86
+ const appsDir = path.join(os.homedir(), 'Applications', 'U2A Apps');
87
+
88
+ if (!fs.existsSync(appsDir)) {
89
+ fs.mkdirSync(appsDir, { recursive: true });
90
+ }
91
+
92
+ const appPath = path.join(appsDir, `${appName}.app`);
93
+ const macOsPath = path.join(appPath, 'Contents', 'MacOS');
94
+ const resourcesPath = path.join(appPath, 'Contents', 'Resources');
95
+
96
+ fs.mkdirSync(path.join(appPath, 'Contents', 'MacOS'), { recursive: true });
97
+ fs.mkdirSync(resourcesPath, { recursive: true });
98
+
99
+ const infoPlist = `<?xml version="1.0" encoding="UTF-8"?>
100
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
101
+ <plist version="1.0">
102
+ <dict>
103
+ <key>CFBundleExecutable</key>
104
+ <string>AppRunner</string>
105
+ <key>CFBundleIconFile</key>
106
+ <string>icon.icns</string>
107
+ <key>CFBundleIdentifier</key>
108
+ <string>com.u2a.${appName.replace(/\s+/g, '-')}</string>
109
+ <key>CFBundleName</key>
110
+ <string>${appName}</string>
111
+ <key>CFBundleDisplayName</key>
112
+ <string>${appName}</string>
113
+ <key>CFBundlePackageType</key>
114
+ <string>APPL</string>
115
+ <key>CFBundleVersion</key>
116
+ <string>1.0</string>
117
+ <key>CFBundleShortVersionString</key>
118
+ <string>1.0</string>
119
+ </dict>
120
+ </plist>`;
121
+
122
+ fs.writeFileSync(path.join(appPath, 'Contents', 'Info.plist'), infoPlist);
123
+
124
+ const shellScript = `#!/bin/bash
125
+ cd "${appDir}"
126
+ "${path.join(appDir, 'node_modules', '.bin', 'electron')}" "${path.join(appDir, 'main.js')}"`;
127
+
128
+ const shellScriptPath = path.join(macOsPath, 'AppRunner');
129
+ fs.writeFileSync(shellScriptPath, shellScript);
130
+ fs.chmodSync(shellScriptPath, '755');
131
+
132
+ fs.copyFileSync(iconPath, path.join(resourcesPath, 'icon.icns'));
133
+
134
+ logger.success(`macOS application created: ${appPath}`);
135
+ return appPath;
136
+ } catch (error) {
137
+ logger.error(`Error while creating the macOS application`, error);
138
+ return null;
139
+ }
140
+ }
141
+
142
+ function addAppToOS(appName, url, appDir, iconPath) {
143
+ const appInfo = { appName, url, appDir, iconPath };
144
+ let desktopPath = null;
145
+
146
+ if (process.platform === 'win32') {
147
+ desktopPath = createWindowsShortcut(appInfo);
148
+ } else if (process.platform === 'darwin') {
149
+ desktopPath = createMacOSApp(appInfo);
150
+ } else if (process.platform === 'linux') {
151
+ desktopPath = createLinuxDesktopEntry(appInfo);
152
+ } else {
153
+ logger.warn(`Desktop integration not supported for platform ${process.platform}`);
154
+ }
155
+
156
+ return desktopPath;
157
+ }
158
+
159
+ function removeAppFromOS(appName) {
160
+ try {
161
+ if (process.platform === 'win32') {
162
+ const startMenuPath = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'U2A Apps', `${appName}.lnk`);
163
+ if (fs.existsSync(startMenuPath)) {
164
+ fs.unlinkSync(startMenuPath);
165
+ logger.success(`Shortcut removed from the Start Menu: ${startMenuPath}`);
166
+ }
167
+ } else if (process.platform === 'darwin') {
168
+ const appPath = path.join(os.homedir(), 'Applications', 'U2A Apps', `${appName}.app`);
169
+ if (fs.existsSync(appPath)) {
170
+ fs.rmSync(appPath, { recursive: true, force: true });
171
+ logger.success(`macOS application removed: ${appPath}`);
172
+ }
173
+ } else if (process.platform === 'linux') {
174
+ const desktopFilePath = path.join(os.homedir(), '.local', 'share', 'applications', `u2a-${appName}.desktop`);
175
+ if (fs.existsSync(desktopFilePath)) {
176
+ fs.unlinkSync(desktopFilePath);
177
+ logger.success(`Linux desktop entry removed: ${desktopFilePath}`);
178
+ }
179
+ }
180
+ } catch (error) {
181
+ logger.error(`Error while removing desktop integration for ${appName}`, error);
182
+ }
183
+ }
184
+
185
+ module.exports = {
186
+ addAppToOS,
187
+ removeAppFromOS
188
188
  };