Skip to content

Commit 6e46e38

Browse files
committed
chore: reapply systemwide license feature
1 parent f718dd5 commit 6e46e38

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

src/nls/root/strings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,5 +1712,6 @@ define({
17121712
"LICENSE_ACTIVATE_SUCCESS": "License activated successfully!",
17131713
"LICENSE_ACTIVATE_SUCCESS_PARTIAL": "License activated for your account only (not system-wide).",
17141714
"LICENSE_ACTIVATE_FAIL": "Failed to activate license",
1715-
"LICENSE_ENTER_KEY": "Please enter a license key"
1715+
"LICENSE_ENTER_KEY": "Please enter a license key",
1716+
"LICENSE_REAPPLY_TO_DEVICE": "Already activated? Reapply to this device"
17161717
});

src/services/html/license-management.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ <h1 class="dialog-title">{{Strings.MANAGE_LICENSE_DIALOG_TITLE}}</h1>
2020
<button
2121
id="activate-license-btn"
2222
class="btn primary license-activate-btn">
23-
<span class="btn-text">{{Strings.LICENSE_KEY_ACTIVATE}}</span>
23+
<span class="btn-text"><i class="fa fa-key" style="margin-right: 8px;"></i>{{Strings.LICENSE_KEY_ACTIVATE}}</span>
2424
<span class="btn-spinner">
2525
<i class="fa fa-spinner fa-spin" style="margin-right: 8px;"></i>{{Strings.LICENSE_KEY_ACTIVATING}}
2626
</span>
2727
</button>
28+
29+
<!-- Reapply License Secondary Action -->
30+
<div id="reapply-license-container" class="license-reapply-container" style="display: none; margin-top: 12px; text-align: center;">
31+
<a id="reapply-license-link" href="#" style="font-size: 13px; text-decoration: none;">
32+
<i class="fa fa-sync" style="margin-right: 6px;"></i>{{Strings.LICENSE_REAPPLY_TO_DEVICE}}
33+
</a>
34+
</div>
2835
</div>
2936

3037
<!-- Divider -->

src/services/manage-licenses.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,24 +148,32 @@ define(function (require, exports, module) {
148148
/**
149149
* Update the license status display in the dialog
150150
*/
151-
function _updateLicenseStatusDisplay($dialog, licenseData) {
151+
async function _updateLicenseStatusDisplay($dialog, licenseData) {
152152
const $loading = $dialog.find('#license-status-loading');
153153
const $none = $dialog.find('#license-status-none');
154154
const $valid = $dialog.find('#license-status-valid');
155155
const $error = $dialog.find('#license-status-error');
156+
const $reapplyContainer = $dialog.find('#reapply-license-container');
156157

157158
// Hide all status sections
158159
$loading.hide();
159160
$none.hide();
160161
$valid.hide();
161162
$error.hide();
163+
$reapplyContainer.hide();
162164

163165
if (licenseData && licenseData.isValid) {
164166
// Show valid license info
165167
$dialog.find('#licensed-to-name').text(licenseData.licensedToName || Strings.LICENSE_STATUS_UNKNOWN);
166168
$dialog.find('#license-type-name').text(licenseData.licenseTypeName || Strings.LICENSE_STATUS_UNKNOWN);
167169
$dialog.find('#license-valid-till').text(_formatDate(licenseData.validTill));
168170
$valid.show();
171+
172+
// Show reapply button if license is valid but not applied system-wide
173+
const isLicensed = await NodeUtils.isLicensedDevice();
174+
if (!isLicensed) {
175+
$reapplyContainer.show();
176+
}
169177
} else if (licenseData && licenseData.isValid === false) {
170178
// No valid license
171179
$none.show();
@@ -270,6 +278,35 @@ define(function (require, exports, module) {
270278
}
271279
}
272280

281+
/**
282+
* Handle reapply license to device
283+
*/
284+
async function _handleReapplyLicense($dialog) {
285+
const $link = $dialog.find('#reapply-license-link');
286+
const originalText = $link.html();
287+
288+
try {
289+
// Show loading state
290+
$link.html('<i class="fa fa-spinner fa-spin" style="margin-right: 6px;"></i>Applying...');
291+
$link.css('pointer-events', 'none');
292+
293+
const addSuccess = await NodeUtils.addDeviceLicense();
294+
if (addSuccess) {
295+
_showActivationMessage($dialog, true, Strings.LICENSE_ACTIVATE_SUCCESS);
296+
// Refresh license status
297+
await _loadLicenseStatus($dialog);
298+
} else {
299+
_showActivationMessage($dialog, false, 'Failed to apply license to device');
300+
}
301+
} catch (error) {
302+
_showActivationMessage($dialog, false, error.message || 'Failed to apply license to device');
303+
} finally {
304+
// Reset link state
305+
$link.html(originalText);
306+
$link.css('pointer-events', 'auto');
307+
}
308+
}
309+
273310
async function showManageLicensesDialog() {
274311
const $template = $(Mustache.render(licenseManagementHTML, {Strings}));
275312

@@ -279,6 +316,7 @@ define(function (require, exports, module) {
279316
const $dialog = $template;
280317
const $licenseInput = $dialog.find('#license-key-input');
281318
const $activateBtn = $dialog.find('#activate-license-btn');
319+
const $reapplyLink = $dialog.find('#reapply-license-link');
282320

283321
// Handle activate button click
284322
$activateBtn.on('click', async function() {
@@ -298,6 +336,12 @@ define(function (require, exports, module) {
298336
}
299337
});
300338

339+
// Handle reapply license link click
340+
$reapplyLink.on('click', async function(e) {
341+
e.preventDefault();
342+
await _handleReapplyLicense($dialog);
343+
});
344+
301345
// Load current license status
302346
await _loadLicenseStatus($dialog);
303347
}

src/utils/NodeUtils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ define(function (require, exports, module) {
237237
* contains valid JSON, and has `licensedDevice: true`.
238238
*
239239
* @returns {Promise<boolean>} - Resolves with `true` if the device is licensed, `false` otherwise.
240-
* @throws {Error} - If called from the browser.
241240
*/
242241
async function isLicensedDevice() {
243242
if (!Phoenix.isNativeApp) {
244-
throw new Error("isLicensedDevice not available in browser");
243+
console.error("isLicensedDevice not available in browser");
244+
return false;
245245
}
246246
try {
247247
return utilsConnector.execPeer("isLicensedDevice");

0 commit comments

Comments
 (0)