Skip to content

Commit d237f25

Browse files
committed
refactor: remote functions continued
1 parent 3a7a3cf commit d237f25

File tree

4 files changed

+68
-27
lines changed

4 files changed

+68
-27
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function RemoteFunctions(config = {}) {
9393
let imageGallerySelected = config.imageGalleryState !== undefined ? config.imageGalleryState : true;
9494

9595
var req, timeout;
96-
var animateHighlight = function (time) {
96+
function animateHighlight(time) {
9797
if(req) {
9898
window.cancelAnimationFrame(req);
9999
window.clearTimeout(timeout);
@@ -104,6 +104,23 @@ function RemoteFunctions(config = {}) {
104104
window.cancelAnimationFrame(req);
105105
req = null;
106106
}, time * 1000);
107+
}
108+
109+
const _moreOptionsHandlers = {};
110+
function registerNodeMoreOptionsHandler(handlerName, handler) {
111+
if(_moreOptionsHandlers[handlerName]) {
112+
console.error(`lp: More options handler '${handlerName}' already registered. Ignoring new registration`);
113+
return;
114+
}
115+
_moreOptionsHandlers[handlerName] = handler;
116+
}
117+
function getNodeMoreOptionsHandler(handlerName) {
118+
return _moreOptionsHandlers[handlerName];
119+
}
120+
121+
const LivePreviewManager = {
122+
registerNodeMoreOptionsHandler: registerNodeMoreOptionsHandler,
123+
getNodeMoreOptionsHandler: getNodeMoreOptionsHandler
107124
};
108125

109126
/**

src/extensionsIntegrated/phoenix-pro/LivePreviewEdit.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ define(function (require, exports, module) {
2727
const Strings = require("strings");
2828
const ImageFolderDialogTemplate = require("text!./html/image-folder-dialog.html");
2929
const LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol");
30+
const ProUtils = require("./pro-utils");
3031

3132
// state manager key, to save the download location of the image
3233
const IMAGE_DOWNLOAD_FOLDER_KEY = "imageGallery.downloadFolder";
@@ -1786,6 +1787,12 @@ define(function (require, exports, module) {
17861787
* these are the main properties that are passed through the message
17871788
*/
17881789
function handleLivePreviewEditOperation(message) {
1790+
if(!ProUtils.isProEditActivated()) {
1791+
// license check: only log this message if localhost dev build. else this should be a silent
1792+
// bailout to prevent tampering.
1793+
location.host.startsWith("localhost") && console.error("ProEdit is not activated, not editing");
1794+
return;
1795+
}
17891796
// handle save current document in live preview (ctrl/cmd + s)
17901797
if (message.saveCurrentDocument) {
17911798
_handleLivePreviewSave();

src/extensionsIntegrated/phoenix-pro/main.js

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
define(function (require, exports, module) {
77
require("./LivePreviewEdit");
8+
require("./pro-utils");
89
const remoteConstants = require("./remote-constants");
910
const remoteIcons = require("./remote-icons");
1011
const remoteStyles = require("./remote-styles");
@@ -14,30 +15,12 @@ define(function (require, exports, module) {
1415
throw new Error("KernalModeTrust is not defined. Cannot boot without trust ring");
1516
}
1617

17-
const AppInit = require("utils/AppInit"),
18-
WorkspaceManager = require("view/WorkspaceManager"),
19-
LiveDevelopment = require("LiveDevelopment/main"),
20-
LiveDevMultiBrowser = require("LiveDevelopment/LiveDevMultiBrowser"),
21-
Strings = require("strings");
18+
const WorkspaceManager = require("view/WorkspaceManager"),
19+
LiveDevMultiBrowser = require("LiveDevelopment/LiveDevMultiBrowser");
2220

2321
const remoteUtilsCode = require("text!./browser-context/remote-utils.js");
2422
const LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol");
2523

26-
// this will later be assigned its correct values once entitlementsManager loads
27-
let isProEditActivated = false;
28-
// called everytime there is a change in entitlements (app start/every 15 mis, explicit check/ anytime really)
29-
// called everytime there is a change in entitlements (app start/every 15 mis, explicit check/ anytime really)
30-
async function _entitlementsChanged() {
31-
try {
32-
const entitlement = await KernalModeTrust.EntitlementsManager.getLiveEditEntitlement();
33-
isProEditActivated = entitlement.activated;
34-
} catch (error) {
35-
console.error("Error updating pro user status:", error);
36-
isProEditActivated = false;
37-
}
38-
LiveDevelopment._liveEditCapabilityChanged(isProEditActivated);
39-
}
40-
4124
/**
4225
* this function handles escape key for live preview to hide boxes if they are visible
4326
* @param {Event} event
@@ -68,10 +51,4 @@ define(function (require, exports, module) {
6851
LiveDevProtocol.addRemoteFunctionScript("remoteUtilsCode", remoteUtilsCode);
6952
}
7053
_addRemoteScripts();
71-
72-
AppInit.appReady(function () {
73-
_entitlementsChanged();
74-
KernalModeTrust.EntitlementsManager.on(
75-
KernalModeTrust.EntitlementsManager.EVENT_ENTITLEMENTS_CHANGED, _entitlementsChanged);
76-
});
7754
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2021 - present core.ai
3+
* SPDX-License-Identifier: LicenseRef-Proprietary
4+
*/
5+
6+
define(function (require, exports, module) {
7+
const KernalModeTrust = window.KernalModeTrust;
8+
if(!KernalModeTrust){
9+
throw new Error("KernalModeTrust is not defined. Cannot boot without trust ring");
10+
}
11+
12+
const AppInit = require("utils/AppInit"),
13+
LiveDevelopment = require("LiveDevelopment/main");
14+
15+
// this will later be assigned its correct values once entitlementsManager loads
16+
let _isProEditActivated = false;
17+
// called everytime there is a change in entitlements (app start/every 15 mis, explicit check/ anytime really)
18+
async function _entitlementsChanged() {
19+
try {
20+
const entitlement = await KernalModeTrust.EntitlementsManager.getLiveEditEntitlement();
21+
_isProEditActivated = entitlement.activated;
22+
} catch (error) {
23+
console.error("Error updating pro user status:", error);
24+
_isProEditActivated = false;
25+
}
26+
LiveDevelopment._liveEditCapabilityChanged(_isProEditActivated);
27+
}
28+
29+
function isProEditActivated() {
30+
return _isProEditActivated;
31+
}
32+
33+
AppInit.appReady(function () {
34+
_entitlementsChanged();
35+
KernalModeTrust.EntitlementsManager.on(
36+
KernalModeTrust.EntitlementsManager.EVENT_ENTITLEMENTS_CHANGED, _entitlementsChanged);
37+
});
38+
39+
exports.isProEditActivated = isProEditActivated;
40+
});

0 commit comments

Comments
 (0)