Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Auto update data logging #14220

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/brackets.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"extension_registry" : "https://s3.amazonaws.com/extend.brackets/registry.json",
"extension_url" : "https://s3.amazonaws.com/extend.brackets/{0}/{0}-{1}.zip",
"linting.enabled_by_default" : true,
"build_timestamp" : ""
"build_timestamp" : "",
"update_download_url" : "https://github.com/adobe/brackets/releases/download/"
}
}
21 changes: 21 additions & 0 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ define(function (require, exports, module) {
CommandManager = require("command/CommandManager"),
Commands = require("command/Commands"),
DeprecationWarning = require("utils/DeprecationWarning"),
EventDispatcher = require("utils/EventDispatcher"),
ProjectManager = require("project/ProjectManager"),
DocumentManager = require("document/DocumentManager"),
MainViewManager = require("view/MainViewManager"),
Expand Down Expand Up @@ -135,7 +136,14 @@ define(function (require, exports, module) {
PreferencesManager.definePreference("defaultExtension", "string", "", {
excludeFromHints: true
});
EventDispatcher.makeEventDispatcher(exports);

/**
* Event triggered when File Save is cancelled, when prompted to save dirty files
*/
var APP_QUIT_CANCELLED = "appQuitCancelled";


/**
* JSLint workaround for circular dependency
* @type {function}
Expand Down Expand Up @@ -847,6 +855,14 @@ define(function (require, exports, module) {

return result.promise();
}

/**
* Dispatches the app quit cancelled event
*/
function dispatchAppQuitCancelledEvent() {
exports.trigger(exports.APP_QUIT_CANCELLED);
}


/**
* Opens the native OS save as dialog and saves document.
Expand Down Expand Up @@ -996,6 +1012,7 @@ define(function (require, exports, module) {
if (selectedPath) {
_doSaveAfterSaveDialog(selectedPath);
} else {
dispatchAppQuitCancelledEvent();
result.reject(USER_CANCELED);
}
} else {
Expand Down Expand Up @@ -1217,6 +1234,7 @@ define(function (require, exports, module) {
)
.done(function (id) {
if (id === Dialogs.DIALOG_BTN_CANCEL) {
dispatchAppQuitCancelledEvent();
result.reject();
} else if (id === Dialogs.DIALOG_BTN_OK) {
// "Save" case: wait until we confirm save has succeeded before closing
Expand Down Expand Up @@ -1322,6 +1340,7 @@ define(function (require, exports, module) {
)
.done(function (id) {
if (id === Dialogs.DIALOG_BTN_CANCEL) {
dispatchAppQuitCancelledEvent();
result.reject();
} else if (id === Dialogs.DIALOG_BTN_OK) {
// Save all unsaved files, then if that succeeds, close all
Expand Down Expand Up @@ -1784,6 +1803,8 @@ define(function (require, exports, module) {

// Define public API
exports.showFileOpenError = showFileOpenError;
exports.APP_QUIT_CANCELLED = APP_QUIT_CANCELLED;


// Deprecated commands
CommandManager.register(Strings.CMD_ADD_TO_WORKING_SET, Commands.FILE_ADD_TO_WORKING_SET, handleFileAddToWorkingSet);
Expand Down
41 changes: 41 additions & 0 deletions src/extensions/default/AutoUpdate/MessageIds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018 - present Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

define(function (require, exports, module) {
"use strict";

exports.DOWNLOAD_INSTALLER = "node.downloadInstaller";
exports.PERFORM_CLEANUP = "node.performCleanup";
exports.VALIDATE_INSTALLER = "node.validateInstaller";
exports.INITIALIZE_STATE = "node.initializeState";
exports.CHECK_INSTALLER_STATUS = "node.checkInstallerStatus";
exports.SHOW_STATUS_INFO = "brackets.showStatusInfo";
exports.NOTIFY_DOWNLOAD_SUCCESS = "brackets.notifyDownloadSuccess";
exports.SHOW_ERROR_MESSAGE = "brackets.showErrorMessage";
exports.NOTIFY_DOWNLOAD_FAILURE = "brackets.notifyDownloadFailure";
exports.NOTIFY_SAFE_TO_DOWNLOAD = "brackets.notifySafeToDownload";
exports.NOTIFY_INITIALIZATION_COMPLETE = "brackets.notifyinitializationComplete";
exports.NOTIFY_VALIDATION_STATUS = "brackets.notifyvalidationStatus";
exports.NOTIFY_INSTALLATION_STATUS = "brackets.notifyInstallationStatus";
exports.REGISTER_BRACKETS_FUNCTIONS = "brackets.registerBracketsFunctions";
});
214 changes: 214 additions & 0 deletions src/extensions/default/AutoUpdate/StateHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/*
* Copyright (c) 2018 - present Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

define(function (require, exports, module) {
"use strict";

var FileSystem = brackets.getModule("filesystem/FileSystem"),
FileUtils = brackets.getModule("file/FileUtils");

var FILE_NOT_FOUND = 0,
FILE_NOT_READ = 1,
FILE_PARSE_EXCEPTION = 2,
FILE_READ_FAIL = 3;

/**
* @constructor
* Creates a StateHandler object for a JSON file. It maintains the following :
* path - path to the JSON file,
* state - parsed content of the file
* @param {string} path - path to the JSON file
*/
var StateHandler = function (path) {
this.path = path;
this.state = null;
};

/**
* Checks if the file exists
* @returns {$.Deferred} - a jquery deferred promise,
* that is resolved with existence or non-existence
* of json file.
*/
StateHandler.prototype.exists = function () {
var result = $.Deferred(),
_file = FileSystem.getFileForPath(this.path);

_file.exists(function (err, exists) {
if(err) {
result.reject();
} else if(exists) {
result.resolve();
} else {
result.reject();
}
});

return result.promise();
};

/**
* Parses the JSON file, and maintains a state for the parsed data
* @returns {$.Deferred} - a jquery deferred promise,
* that is resolved with a parsing success or failure
*/
StateHandler.prototype.parse = function () {
var result = $.Deferred(),
_file = FileSystem.getFileForPath(this.path);
var self = this;

this.exists()
.done(function () {
FileUtils.readAsText(_file)
.done(function (text) {
try {
if (text) {
self.state = JSON.parse(text);
result.resolve();
} else {
result.reject(FILE_READ_FAIL);
}
} catch (error) {
result.reject(FILE_PARSE_EXCEPTION);
}
})
.fail(function () {
result.reject(FILE_NOT_READ);
});

})
.fail(function () {
result.reject(FILE_NOT_FOUND);
});

return result.promise();
};

/**
* Sets the value of a key in a json file.
* @param {string} key - key for which the value is to be set
* @param {string} value - the value to be set for the given key
* @returns {$.Deferred} - a jquery deferred promise, that is resolved with a write success or failure
*/
StateHandler.prototype.set = function (key, value) {
this.state = this.state || {};
this.state[key] = value;

return this.write(true);
};

/**
* Gets the value for a given key, from the in-memory state maintained for a json file.
* @param {string} key - key for which value is to be retrieved
* @returns {string} value for the given key
*/
StateHandler.prototype.get = function (key) {
var retval = null;

if (this.state && this.state[key]) {
retval = this.state[key];
}

return retval;
};


/**
* Performs the write of JSON object to a file.
* @param {string} filepath - path to JSON file
* @param {object} json - JSON object to write
* @returns {$.Deferred} - a jquery deferred promise,
* that is resolved with the write success or failure
*/
function _write(filePath, json) {
var result = $.Deferred(),
_file = FileSystem.getFileForPath(filePath);

if (_file) {

var content = JSON.stringify(json);
FileUtils.writeText(_file, content, true)
.done(function () {
result.resolve();
})
.fail(function (err) {
result.reject();
});

} else {
result.reject();
}

return result.promise();
}
/**
* Writes content into a json file
* @param {boolean} overwrite - true if file is to be overwritten, false otherwise
* @param {object} [content=this.state] - content to be written into the json file.
* @returns {$.Deferred} - a jquery deferred promise, that is resolved with a write success or failure
*/
StateHandler.prototype.write = function (overwrite) {
var result = $.Deferred(),
self = this;

function writePromise(path, contentToWrite) {
_write(path, contentToWrite)
.done(function () {
result.resolve();
})
.fail(function (err) {
result.reject();
});
}

var content = self.state;
if (overwrite) {
writePromise(self.path, content);
} else {
//check for existence
self.exists()
.fail(function () {
writePromise(self.path, content);
}).done(function (){
result.reject();
});
}

return result.promise();
};

/**
* Resets the content of the in-memory state
*/
StateHandler.prototype.reset = function () {
this.state = null;
};

exports.StateHandler = StateHandler;
exports.MessageKeys = {
FILE_NOT_FOUND: FILE_NOT_FOUND,
FILE_NOT_READ: FILE_NOT_READ,
FILE_PARSE_EXCEPTION: FILE_PARSE_EXCEPTION,
FILE_READ_FAIL: FILE_READ_FAIL
};
});
Loading