From e3f0832cc70aaccdc4308e29209ba0ab8c4b008f Mon Sep 17 00:00:00 2001 From: abose Date: Mon, 18 Dec 2023 12:46:12 +0530 Subject: [PATCH] chore: add desktop google analytics ids, not wired in --- docs/generatedApiDocs/GitHub-API-Index.md | 1 + docs/generatedApiDocs/NodeConnector-API.md | 28 ++++ .../generatedApiDocs/utils/StringUtils-API.md | 131 ++++++++++++++++++ src/brackets.config.dist.json | 1 + src/brackets.config.staging.json | 1 + src/config.json | 1 + src/utils/Metrics.js | 22 +-- src/utils/StringUtils.js | 28 ++++ test/spec/LowLevelFileIO-test.js | 2 +- 9 files changed, 193 insertions(+), 22 deletions(-) create mode 100644 docs/generatedApiDocs/utils/StringUtils-API.md diff --git a/docs/generatedApiDocs/GitHub-API-Index.md b/docs/generatedApiDocs/GitHub-API-Index.md index 4810815f5..13a67538c 100644 --- a/docs/generatedApiDocs/GitHub-API-Index.md +++ b/docs/generatedApiDocs/GitHub-API-Index.md @@ -11,6 +11,7 @@ The list of all APIs for phoenix. 1. [utils/ExtensionInterface](ExtensionInterface-API) 1. [utils/FeatureGate](FeatureGate-API) 1. [utils/Metrics](Metrics-API) +1. [utils/StringUtils](StringUtils-API) 1. [widgets/NotificationUI](NotificationUI-API) 1. [worker/ExtensionsWorker](ExtensionsWorker-API) 1. [worker/IndexingWorker](IndexingWorker-API) diff --git a/docs/generatedApiDocs/NodeConnector-API.md b/docs/generatedApiDocs/NodeConnector-API.md index d42e279b7..a1a7f3468 100644 --- a/docs/generatedApiDocs/NodeConnector-API.md +++ b/docs/generatedApiDocs/NodeConnector-API.md @@ -163,6 +163,32 @@ Checks if Node.js Engine is available. Returns **[boolean][5]** Returns true if Node.js Engine is available. +## terminateNode + +Terminate the PhNodeEngine node if it is available. Else does nothing. + +Returns **void** + +## setInspectEnabled + +Sets weather to enable node inspector in next boot. + +### Parameters + +* `enabled` **[boolean][5]** true to enable, else false. + +## isInspectEnabled + +Returns whether node inspector is enabled. If node is not present, always returns false. + +Returns **[boolean][5]** True if inspect mode is enabled, false otherwise. + +## getInspectPort + +Retrieves the node inspector port for the Phoenix Node.js engine. + +Returns **[number][6]** The inspection port number. + [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object @@ -172,3 +198,5 @@ Returns **[boolean][5]** Returns true if Node.js Engine is available. [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean + +[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number diff --git a/docs/generatedApiDocs/utils/StringUtils-API.md b/docs/generatedApiDocs/utils/StringUtils-API.md new file mode 100644 index 000000000..50844e13f --- /dev/null +++ b/docs/generatedApiDocs/utils/StringUtils-API.md @@ -0,0 +1,131 @@ + + +## utils/StringUtils + +Utilities functions related to string manipulation + +## format + +Format a string by replacing placeholder symbols with passed in arguments. + +Example: var formatted = StringUtils.format("Hello {0}", "World"); + +### Parameters + +* `str` **[string][1]** The base string + +Returns **[string][1]** Formatted string + +## getLines + +Splits the text by new line characters and returns an array of lines + +### Parameters + +* `text` **[string][1]** + +Returns **[Array][2]<[string][1]>** lines + +## offsetToLineNum + +Returns a line number corresponding to an offset in some text. The text can +be specified as a single string or as an array of strings that correspond to +the lines of the string. + +Specify the text in lines when repeatedly calling the function on the same +text in a loop. Use getLines() to divide the text into lines, then repeatedly call +this function to compute a line number from the offset. + +### Parameters + +* `textOrLines` **([string][1] | [Array][2]<[string][1]>)** string or array of lines from which + to compute the line number from the offset +* `offset` **[number][3]** + +Returns **[number][3]** line number + +## startsWith + +Returns true if the given string starts with the given prefix. + +### Parameters + +* `str` **[String][1]** +* `prefix` **[String][1]** + +Returns **[Boolean][4]** + +## endsWith + +Returns true if the given string ends with the given suffix. + +### Parameters + +* `str` **[string][1]** +* `suffix` **[string][1]** + +## breakableUrl + +Return an escaped path or URL string that can be broken near path separators. + +### Parameters + +* `url` **[string][1]** the path or URL to format + +Returns **[string][1]** the formatted path or URL + +## prettyPrintBytes + +Converts number of bytes into human readable format. +If param bytes is negative it returns the number without any changes. + +### Parameters + +* `bytes` **[number][3]** Number of bytes to convert +* `precision` **[number][3]** Number of digits after the decimal separator + +Returns **[string][1]** + +## truncate + +Truncate text to specified length. + +### Parameters + +* `str` **[string][1]** Text to be truncated. +* `len` **[number][3]** Length to which text should be truncated + +Returns **[string][1]?** Returns truncated text only if it was changed + +## hashCode + +Computes a 32bit hash from the given string +Taken from [http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery][5] + +### Parameters + +* `str` **[string][1]** The string for which hash is to be computed + +Returns **[number][3]** The 32-bit hash + +## randomString + +Generates a random nonce string of the specified length. + +!!!Should not be used for crypto secure workflows.!!! + +### Parameters + +* `stringLength` **[number][3]** The length of the nonce in bytes. + +Returns **[string][1]** The randomly generated nonce. + +[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String + +[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array + +[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number + +[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean + +[5]: http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery diff --git a/src/brackets.config.dist.json b/src/brackets.config.dist.json index b3eaeac10..331d63d50 100644 --- a/src/brackets.config.dist.json +++ b/src/brackets.config.dist.json @@ -1,5 +1,6 @@ { "googleAnalyticsID" : "G-FBK9RP5YK2", + "googleAnalyticsIDDesktop": "G-M7MX9BYZZ3", "mixPanelID" : "8cb6814f733e37c05cc59b4adad26407", "coreAnalyticsID" : "phoenix", "coreAnalyticsAppName" : "phoenix-prod", diff --git a/src/brackets.config.staging.json b/src/brackets.config.staging.json index 2cbd68ab3..ecce029c7 100644 --- a/src/brackets.config.staging.json +++ b/src/brackets.config.staging.json @@ -1,5 +1,6 @@ { "googleAnalyticsID" : "G-FP5S9BKDSJ", + "googleAnalyticsIDDesktop" : "G-D5R1Y6PTS8", "mixPanelID" : "a7e08ffd43c37767c29b13df1d2e6c62", "coreAnalyticsID" : "phoenix", "coreAnalyticsAppName" : "phoenix-stage", diff --git a/src/config.json b/src/config.json index 3ff3b2af8..46400d9bc 100644 --- a/src/config.json +++ b/src/config.json @@ -24,6 +24,7 @@ "linting.enabled_by_default": true, "build_timestamp": "", "googleAnalyticsID": "G-P4HJFPDB76", + "googleAnalyticsIDDesktop": "G-VE5BXWJ0HF", "mixPanelID": "49c4d164b592be2350fc7af06a259bf3", "coreAnalyticsID": "phoenix", "coreAnalyticsAppName": "phoenix-dev", diff --git a/src/utils/Metrics.js b/src/utils/Metrics.js index 6ee4e59b8..740ea5a73 100644 --- a/src/utils/Metrics.js +++ b/src/utils/Metrics.js @@ -129,6 +129,7 @@ define(function (require, exports, module) { script.onload = function(){ gtag('js', new Date()); + // TODO use googleAnalyticsIDDesktop for desktop analytics gtag('config', brackets.config.googleAnalyticsID, { 'page_title': 'Phoenix editor', 'page_path': '/index.html', @@ -198,25 +199,6 @@ define(function (require, exports, module) { }); } - function _sendToMixPanel(category, action, label, count, value) { - if(disabled || window.testEnvironment){ - return; - } - category = category || "category"; - action = action || "action"; - if(!label){ - label = action; - } - count = count || 1; - value = value || 1; - if(!window.mixpanel || !mixpanel.track) { - return; - } - mixpanel.track(category, { - action, label, count, value - }); - } - function _sendToCoreAnalytics(category, action, label, count, value) { // https://developers.google.com/analytics/devguides/collection/analyticsjs/events if(disabled || window.testEnvironment){ @@ -256,7 +238,6 @@ define(function (require, exports, module) { function _countEvent(eventType, eventCategory, eventSubCategory, count= 1) { _logEventForAudit(eventType, eventCategory, eventSubCategory, count, AUDIT_TYPE_COUNT); _sendToGoogleAnalytics(eventType, eventCategory, eventSubCategory, count); - _sendToMixPanel(eventType, eventCategory, eventSubCategory, count); _sendToCoreAnalytics(eventType, eventCategory, eventSubCategory, count); } @@ -286,7 +267,6 @@ define(function (require, exports, module) { function _valueEvent(eventType, eventCategory, eventSubCategory, value) { _logEventForAudit(eventType, eventCategory, eventSubCategory, value, AUDIT_TYPE_VALUE); _sendToGoogleAnalytics(eventType, eventCategory, eventSubCategory, value); - _sendToMixPanel(eventType, eventCategory, eventSubCategory, 1, value); _sendToCoreAnalytics(eventType, eventCategory, eventSubCategory, 1, value); } diff --git a/src/utils/StringUtils.js b/src/utils/StringUtils.js index e7800c582..807069e81 100644 --- a/src/utils/StringUtils.js +++ b/src/utils/StringUtils.js @@ -19,6 +19,8 @@ * */ +// @INCLUDE_IN_API_DOCS + /* The hash code routne is taken from http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery @CC wiki attribution: esmiralha */ @@ -29,6 +31,7 @@ /** * Utilities functions related to string manipulation * + * @module utils/StringUtils */ define(function (require, exports, module) { @@ -243,6 +246,30 @@ define(function (require, exports, module) { return hash; } + /** + * Generates a random nonce string of the specified length. + * + * !!!Should not be used for crypto secure workflows.!!! + * + * @param {number} stringLength - The length of the nonce in bytes. + * @returns {string} - The randomly generated nonce. + */ + function randomString(stringLength) { + const randomBuffer = new Uint8Array(stringLength); + crypto.getRandomValues(randomBuffer); + + // Define the character set for the random string + const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; + + // Convert the ArrayBuffer to a case-sensitive random string with numbers + let randomId = ''; + Array.from(randomBuffer).forEach(byte => { + randomId += charset[byte % charset.length]; + }); + + return randomId; + } + // Define public API exports.format = format; exports.regexEscape = regexEscape; @@ -256,4 +283,5 @@ define(function (require, exports, module) { exports.prettyPrintBytes = prettyPrintBytes; exports.truncate = truncate; exports.hashCode = hashCode; + exports.randomString = randomString; }); diff --git a/test/spec/LowLevelFileIO-test.js b/test/spec/LowLevelFileIO-test.js index 429eff370..97f35a430 100644 --- a/test/spec/LowLevelFileIO-test.js +++ b/test/spec/LowLevelFileIO-test.js @@ -115,7 +115,7 @@ define(function (require, exports, module) { }); it("should getDisplayLocation return correct path in tauri", function () { - if(!brackets.browser.isTauri) { + if(!Phoenix.browser.isTauri) { return; } // tauri paths