Skip to content

Commit 0739fb5

Browse files
committed
chore: manage-licenses.js
1 parent 1a91708 commit 0739fb5

File tree

6 files changed

+73
-3
lines changed

6 files changed

+73
-3
lines changed

src/command/Commands.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ define(function (require, exports, module) {
408408
/** Opens Phoenix Pro page */
409409
exports.HELP_GET_PRO = "help.getPro"; // HelpCommandHandlers.js _handleLinkMenuItem()
410410

411+
/** Manage Pro licenses */
412+
exports.HELP_MANAGE_LICENSES = "help.manageLicenses"; // HelpCommandHandlers.js _handleLinkMenuItem()
413+
411414
/** Opens feature suggestion page */
412415
exports.HELP_SUGGEST = "help.suggest"; // HelpCommandHandlers.js _handleLinkMenuItem()
413416

src/command/DefaultMenus.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ define(function (require, exports, module) {
269269
menu.addMenuItem(Commands.HELP_SUPPORT);
270270
menu.addMenuDivider();
271271
menu.addMenuItem(Commands.HELP_GET_PRO);
272+
if(Phoenix.isNativeApp) {
273+
menu.addMenuItem(Commands.HELP_MANAGE_LICENSES);
274+
}
272275
menu.addMenuDivider();
273276
if (brackets.config.suggest_feature_url) {
274277
menu.addMenuItem(Commands.HELP_SUGGEST);

src/help/HelpCommandHandlers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ define(function (require, exports, module) {
3030
FileUtils = require("file/FileUtils"),
3131
NativeApp = require("utils/NativeApp"),
3232
Strings = require("strings"),
33-
StringUtils = require("utils/StringUtils"),
33+
StringUtils = require("utils/StringUtils"),
34+
ManageLicenses = require("services/manage-licenses"),
3435
AboutDialogTemplate = require("text!htmlContent/about-dialog.html"),
3536
ContributorsTemplate = require("text!htmlContent/contributors-list.html"),
3637
Mustache = require("thirdparty/mustache/mustache");
@@ -168,6 +169,7 @@ define(function (require, exports, module) {
168169
CommandManager.register(Strings.CMD_GET_PRO, Commands.HELP_GET_PRO, _handleLinkMenuItem(brackets.config.purchase_url), {
169170
htmlName: getProString
170171
});
172+
CommandManager.register(Strings.CMD_MANAGE_LICENSES, Commands.HELP_MANAGE_LICENSES, ManageLicenses.showManageLicensesDialog);
171173
CommandManager.register(Strings.CMD_SUGGEST, Commands.HELP_SUGGEST, _handleLinkMenuItem(brackets.config.suggest_feature_url));
172174
CommandManager.register(Strings.CMD_REPORT_ISSUE, Commands.HELP_REPORT_ISSUE, _handleLinkMenuItem(brackets.config.report_issue_url));
173175
CommandManager.register(Strings.CMD_RELEASE_NOTES, Commands.HELP_RELEASE_NOTES, _handleLinkMenuItem(brackets.config.release_notes_url));

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ define({
655655
"CMD_HOW_TO_USE_BRACKETS": "How to Use {APP_NAME}",
656656
"CMD_SUPPORT": "{APP_NAME} Support",
657657
"CMD_GET_PRO": "Get Phoenix Pro",
658+
"CMD_MANAGE_LICENSES": "Manage Licenses",
658659
"CMD_USER_PROFILE": "{APP_NAME} Account",
659660
"CMD_DOCS": "Help, Getting Started",
660661
"CMD_SUGGEST": "Suggest a Feature",

src/phoenix/trust_ring.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ export async function initTrustRing() {
249249
* Generates an SHA-256 hash signature of the provided data string combined with a salt.
250250
*
251251
* @param {string} dataString - The input data string that needs to be signed.
252-
* @param {string} salt - A salt value to combine with the data string for additional uniqueness.
252+
* @param {string} [salt] - A Optional salt value to combine with the data string for additional uniqueness.
253253
* @return {Promise<string>} A promise that resolves to the generated SHA-256 hash signature as a hexadecimal string.
254254
*/
255255
async function generateDataSignature(dataString, salt) {
256-
const signatureData = dataString + "|" + salt;
256+
const signatureData = salt ? dataString + "|" + salt : dataString;
257257
const encoder = new TextEncoder();
258258
const dataBuffer = encoder.encode(signatureData);
259259
const hashBuffer = await crypto.subtle.digest('SHA-256', dataBuffer);

src/services/manage-licenses.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it under
7+
* the terms of the GNU Affero General Public License as published by the Free
8+
* Software Foundation, either version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
* See the GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
16+
*
17+
*/
18+
19+
/*global logger*/
20+
21+
/**
22+
* Shared Login Service
23+
*
24+
* This module contains shared login service functionality used by both
25+
* browser and desktop login implementations, including entitlements management.
26+
*/
27+
28+
define(function (require, exports, module) {
29+
const KernalModeTrust = window.KernalModeTrust;
30+
if(!KernalModeTrust){
31+
// integrated extensions will have access to kernal mode, but not external extensions
32+
throw new Error("manage-licenses should have access to KernalModeTrust. Cannot boot without trust ring");
33+
}
34+
35+
async function _getLinuxDeviceID() {
36+
const LINUX_DEVICE_ID_FILE = Phoenix.VFS.getTauriVirtualPath('/etc/machine-id');
37+
const result = await Phoenix.VFS.readFileResolves(LINUX_DEVICE_ID_FILE, 'utf8');
38+
if(result.error || !result.data) {
39+
logger.reportError(result.error, `Failed to read machine-id file for licensing`);
40+
return null;
41+
}
42+
return KernalModeTrust.generateDataSignature(result.data.trim()); // \n and spaces are trimmed, just id please
43+
}
44+
45+
async function _getDeviceID() {
46+
if(!Phoenix.isNativeApp) {
47+
// We only grant device licenses to desktop apps. Browsers cannot be uniquely device identified obviously.
48+
return null;
49+
}
50+
switch (Phoenix.platform) {
51+
case 'linux': return _getLinuxDeviceID();
52+
default: return null;
53+
}
54+
}
55+
56+
async function showManageLicensesDialog() {
57+
alert(`machine id is: ${await _getDeviceID()}`);
58+
}
59+
60+
exports.showManageLicensesDialog = showManageLicensesDialog;
61+
});

0 commit comments

Comments
 (0)