2929
3030define ( function ( require , exports , module ) {
3131 const Strings = require ( "strings" ) ,
32+ PreferencesManager = require ( "preferences/PreferencesManager" ) ,
3233 NodeConnector = require ( 'NodeConnector' ) ;
3334 const UTILS_NODE_CONNECTOR = "ph_utils" ;
3435
36+ const PREF_STATE_LICENSED_DEVICE_CHECK = "LICENSED_DEVICE_CHECK" ;
37+
3538 let utilsConnector ;
3639 if ( Phoenix . isNativeApp ) {
3740 // node not available in browser builds!
@@ -203,6 +206,7 @@ define(function (require, exports, module) {
203206 throw new Error ( "addDeviceLicense not available in browser" ) ;
204207 }
205208 try {
209+ PreferencesManager . stateManager . set ( PREF_STATE_LICENSED_DEVICE_CHECK , true ) ;
206210 await utilsConnector . execPeer ( "addDeviceLicense" ) ;
207211 return true ;
208212 } catch ( err ) {
@@ -223,6 +227,7 @@ define(function (require, exports, module) {
223227 throw new Error ( "removeDeviceLicense not available in browser" ) ;
224228 }
225229 try {
230+ PreferencesManager . stateManager . set ( PREF_STATE_LICENSED_DEVICE_CHECK , false ) ;
226231 await utilsConnector . execPeer ( "removeDeviceLicense" ) ;
227232 return true ;
228233 } catch ( err ) {
@@ -232,13 +237,12 @@ define(function (require, exports, module) {
232237 }
233238
234239 /**
235- * Checks if the current machine is licensed.
236- * This validates that the system-wide license file exists,
237- * contains valid JSON, and has `licensedDevice: true`.
240+ * Checks if the current machine is configured to check for system-wide device license for all users at app start.
241+ * This validates that the system-wide license file exists, contains valid JSON, and has `licensedDevice: true`.
238242 *
239243 * @returns {Promise<boolean> } - Resolves with `true` if the device is licensed, `false` otherwise.
240244 */
241- async function isLicensedDevice ( ) {
245+ async function isLicensedDeviceSystemWide ( ) {
242246 if ( ! Phoenix . isNativeApp ) {
243247 console . error ( "isLicensedDevice not available in browser" ) ;
244248 return false ;
@@ -251,6 +255,16 @@ define(function (require, exports, module) {
251255 return false ;
252256 }
253257
258+ /**
259+ * Checks if app is configured to check for device licenses at app start at system or user level.
260+ *
261+ * @returns {Promise<boolean> } - Resolves with `true` if the device is licensed, `false` otherwise.
262+ */
263+ async function isLicensedDevice ( ) {
264+ const userCheck = PreferencesManager . stateManager . get ( PREF_STATE_LICENSED_DEVICE_CHECK ) ;
265+ const systemCheck = await isLicensedDeviceSystemWide ( ) ;
266+ return userCheck || systemCheck ;
267+ }
254268
255269 if ( NodeConnector . isNodeAvailable ( ) ) {
256270 // todo we need to update the strings if a user extension adds its translations. Since we dont support
@@ -277,6 +291,8 @@ define(function (require, exports, module) {
277291 console . error ( "Error setting Phoenix.isTestWindowGitHubActions" , e ) ;
278292 }
279293
294+ PreferencesManager . stateManager . definePreference ( PREF_STATE_LICENSED_DEVICE_CHECK , "boolean" , false ) ;
295+
280296 // private apis
281297 exports . _loadNodeExtensionModule = _loadNodeExtensionModule ;
282298 exports . _npmInstallInFolder = _npmInstallInFolder ;
@@ -293,6 +309,7 @@ define(function (require, exports, module) {
293309 exports . addDeviceLicense = addDeviceLicense ;
294310 exports . removeDeviceLicense = removeDeviceLicense ;
295311 exports . isLicensedDevice = isLicensedDevice ;
312+ exports . isLicensedDeviceSystemWide = isLicensedDeviceSystemWide ;
296313
297314 /**
298315 * checks if Node connector is ready
0 commit comments