Skip to content

Commit 1fe35f2

Browse files
committed
chore: add NodeUtils.getSystemSettingsDir
1 parent ade508d commit 1fe35f2

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

src-node/constants.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
const os = require('os');
2+
13
exports.SYSTEM_SETTINGS_DIR_WIN = 'C:\\Program Files\\Phoenix Code Control\\';
24
exports.SYSTEM_SETTINGS_DIR_MAC = '/Library/Application Support/phoenix-code-control/';
35
exports.SYSTEM_SETTINGS_DIR_LINUX = '/etc/phoenix-code-control/';
6+
7+
switch (os.platform()) {
8+
case 'win32':
9+
exports.SYSTEM_SETTINGS_DIR = exports.SYSTEM_SETTINGS_DIR_WIN; break;
10+
case 'darwin':
11+
exports.SYSTEM_SETTINGS_DIR = exports.SYSTEM_SETTINGS_DIR_MAC; break;
12+
case 'linux':
13+
exports.SYSTEM_SETTINGS_DIR = exports.SYSTEM_SETTINGS_DIR_LINUX; break;
14+
default:
15+
throw new Error(`Unsupported platform: ${os.platform()}`);
16+
}

src-node/licence-device.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,13 @@ const fs = require('fs');
44
const fsPromise = require('fs').promises;
55
const path = require('path');
66
const { exec } = require('child_process');
7-
const { SYSTEM_SETTINGS_DIR_WIN, SYSTEM_SETTINGS_DIR_MAC, SYSTEM_SETTINGS_DIR_LINUX } = require('./constants');
7+
const { SYSTEM_SETTINGS_DIR } = require('./constants');
88

99
const options = { name: 'Phoenix Code' };
1010
const licenseFileContent = JSON.stringify({});
1111

1212
function getLicensePath() {
13-
switch (os.platform()) {
14-
case 'win32':
15-
return `${SYSTEM_SETTINGS_DIR_WIN}device-license`;
16-
case 'darwin':
17-
return `${SYSTEM_SETTINGS_DIR_MAC}device-license`;
18-
case 'linux':
19-
return `${SYSTEM_SETTINGS_DIR_LINUX}device-license`;
20-
default:
21-
throw new Error(`Unsupported platform: ${os.platform()}`);
22-
}
13+
return `${SYSTEM_SETTINGS_DIR}device-license`;
2314
}
2415

2516
function sudoExec(command) {

src-node/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const fs = require('fs');
44
const fsPromise = require('fs').promises;
55
const path = require('path');
66
const os = require('os');
7+
const { SYSTEM_SETTINGS_DIR } = require('./constants');
78
const { lintFile } = require("./ESLint/service");
89
const { addDeviceLicense, getDeviceID, isLicensedDevice, removeDeviceLicense } = require("./licence-device");
910
let openModule, open; // dynamic import when needed
@@ -274,6 +275,10 @@ async function getOSUserName() {
274275
return os.userInfo().username;
275276
}
276277

278+
async function getSystemSettingsDir() {
279+
return SYSTEM_SETTINGS_DIR;
280+
}
281+
277282
exports.getURLContent = getURLContent;
278283
exports.setLocaleStrings = setLocaleStrings;
279284
exports.getPhoenixBinaryVersion = getPhoenixBinaryVersion;
@@ -288,5 +293,6 @@ exports.removeDeviceLicense = removeDeviceLicense;
288293
exports.isLicensedDevice = isLicensedDevice;
289294
exports.getDeviceID = getDeviceID;
290295
exports.getOSUserName = getOSUserName;
296+
exports.getSystemSettingsDir = getSystemSettingsDir;
291297
exports._loadNodeExtensionModule = _loadNodeExtensionModule;
292298
exports._npmInstallInFolder = _npmInstallInFolder;

src/utils/NodeUtils.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,23 @@ define(function (require, exports, module) {
289289
return utilsConnector.execPeer("getOSUserName");
290290
}
291291

292+
let _systemSettingsDir;
293+
/**
294+
* Retrieves the directory path for system settings. This method is applicable to native apps only.
295+
*
296+
* @return {Promise<string>} A promise that resolves to the path of the system settings directory.
297+
* @throws {Error} If the method is called in browser app.
298+
*/
299+
async function getSystemSettingsDir() {
300+
if (!Phoenix.isNativeApp) {
301+
throw new Error("getSystemSettingsDir is sudo folder is win/linux/mac. not available in browser.");
302+
}
303+
if(!_systemSettingsDir){
304+
_systemSettingsDir = await utilsConnector.execPeer("getSystemSettingsDir");
305+
}
306+
return _systemSettingsDir;
307+
}
308+
292309
if(NodeConnector.isNodeAvailable()) {
293310
// todo we need to update the strings if a user extension adds its translations. Since we dont support
294311
// node extensions for now, should consider when we support node extensions.
@@ -332,6 +349,7 @@ define(function (require, exports, module) {
332349
exports.isLicensedDeviceSystemWide = isLicensedDeviceSystemWide;
333350
exports.getDeviceID = getDeviceID;
334351
exports.getOSUserName = getOSUserName;
352+
exports.getSystemSettingsDir = getSystemSettingsDir;
335353

336354
/**
337355
* checks if Node connector is ready

0 commit comments

Comments
 (0)