Skip to content

Commit

Permalink
added analytics data loggiing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitesh Kumar committed Mar 17, 2020
1 parent 9c722a6 commit 4d7268d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 23 deletions.
94 changes: 74 additions & 20 deletions src/extensions/default/OpenWithExternalApplication/GraphicsFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ define(function (require, exports, module) {

var PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
Strings = brackets.getModule("strings"),
StringsUtils = brackets.getModule("utils/StringUtils"),
ProjectManager = brackets.getModule("project/ProjectManager"),
Dialogs = brackets.getModule("widgets/Dialogs"),
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs");
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"),
HealthLogger = brackets.getModule("utils/HealthLogger");


var _requestID = 0,
Expand All @@ -41,15 +43,15 @@ define(function (require, exports, module) {

function init(nodeDomain) {

if(_initialized) {
if (_initialized) {
return;
}
_initialized = true;

_nodeDomain = nodeDomain;

_nodeDomain.on('checkFileTypesInFolderResponse', function (event, response) {
if(response.id !== _requestID) {
if (response.id !== _requestID) {
return;
}
_graphicsFilePresentInProject(response.present);
Expand All @@ -66,7 +68,7 @@ define(function (require, exports, module) {

function _checkForGraphicsFileInPrjct() {

if(PreferencesManager.getViewState("AssociateGraphicsFileDialogShown")) {
if (PreferencesManager.getViewState("AssociateGraphicsFileDialogShown")) {
return;
}

Expand All @@ -80,7 +82,7 @@ define(function (require, exports, module) {

function _graphicsFilePresentInProject(isPresent) {

if(!isPresent) {
if (!isPresent) {
return;
}

Expand All @@ -90,28 +92,66 @@ define(function (require, exports, module) {
Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG,
[
{ className: Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL,
text: Strings.BUTTON_NO
text: Strings.CANCEL
},
{ className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK,
text: Strings.BUTTON_YES
text: Strings.OK
}
]
).done(function (id) {

if(id !== Dialogs.DIALOG_BTN_OK) {

if (id !== Dialogs.DIALOG_BTN_OK) {
HealthLogger.sendAnalyticsData(
"externalEditorsCancelled",
"usage",
"externalEditors",
"Cancelled",
""
);
return;
}
HealthLogger.sendAnalyticsData(
"LinkExternalEditors",
"usage",
"externalEditors",
"LinkExternalEditors",
""
);

brackets.app.getSystemDefaultApp(_graphicsFileTypes.join(), function (err, out) {

if(err) {
if (err) {
return;
}
var associateApp = out.split(','),
fileTypeToAppMap = {};
fileTypeToAppMap = {},
AppToFileTypeMap = {};

associateApp.forEach(function (item) {

var filetype = item.split('##')[0],
app = item.split('##')[1];

if (!filetype) {
return;
}

if (filetype === "xd") {
if (app.toLowerCase() !== "adobe xd" && app !== "adobe.cc.xd") {
return;
}
app = "Adobe XD";
}
fileTypeToAppMap[filetype] = app;

associateApp.forEach(function(item) {
fileTypeToAppMap[item.split('##')[0]] = item.split('##')[1];
if (brackets.platform === "win" && !app.toLowerCase().endsWith('.exe')) {
app = app.substring(app.lastIndexOf('//') + 2, app.length - 4);
}
if (AppToFileTypeMap[app]) {
AppToFileTypeMap[app].push(filetype);
} else {
AppToFileTypeMap[app] = [filetype];
}
});

var prefs = PreferencesManager.get('externalApplications');
Expand All @@ -120,26 +160,40 @@ define(function (require, exports, module) {
if (fileTypeToAppMap.hasOwnProperty(key)) {
if(key && !prefs[key]) {
prefs[key] = fileTypeToAppMap[key];
if(brackets.platform === "win" && !fileTypeToAppMap[key].endsWith('.exe') &&
!fileTypeToAppMap[key].endsWith('.EXE')) {
if(brackets.platform === "win" && !fileTypeToAppMap[key].toLowerCase().endsWith('.exe')) {
prefs[key] = "default";
}
HealthLogger.sendAnalyticsData(
"AddExternalEditorForFileType_" + key.toUpperCase(),
"usage",
"externalEditors",
"AddExternalEditorForFileType_" + key.toUpperCase(),
""
);
}
}
}

PreferencesManager.set('externalApplications', prefs);

var str = "";
for(var app in AppToFileTypeMap) {
str += AppToFileTypeMap[app].join() + "->" + app + "<br/>";
}

if(!str) {
return;
}

str+="<br/>";

Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_INFO,
Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE,
out,
StringsUtils.format(Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_CNF_MSG, str),
[
{ className: Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL,
text: Strings.BUTTON_NO
},
{ className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK,
text: Strings.BUTTON_YES
text: Strings.OK
}
]
);
Expand Down
7 changes: 4 additions & 3 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,11 @@ define({
"REMOTE_DEBUGGING_PORT_INVALID" : "Cannot enable remote debugging on port {0}. Port numbers should be between {1} and {2}.",

//Associate File Type to External App
"DESCRIPTION_EXTERNAL_APPLICATION_ASSOCIATE" : "Add File type association to external App here",
"DESCRIPTION_EXTERNAL_APPLICATION_ASSOCIATE" : "Associate File type to external App settings. e.g { \"<file_type>\": \"<app_name>\" } app_name is OS dependant, for example \"google chrome\" on macOS and \"chrome\" on Windows. app_name can also be given as \"default\" for OS default application.",

"ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE" : "Open Graphics Files in external editors?",
"ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG" : "Click Yes to associate the graphic files with its appropriate external editors."
"ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE" : "Open Graphic Files in External Editors.",
"ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG" : "Your current folder has graphic file types which are not supported by Brackets.<br/>You can now associate specific file types with external editors. Once associated, you can open graphic files like .xd, .psd, .jpg, .png, .ai, .svg in their default applications by double clicking on the files in File Tree.<br/><br/>Please click on ‘Ok’ button to associate the graphic file types with their respective default applications.",
"ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_CNF_MSG" : "Following file types have been successfully associated with default applications.<br/>{0} You can further add new file type associations or customize in brackets.json by going to “Debug->Open Preferences File” menu."


});

0 comments on commit 4d7268d

Please sign in to comment.