-
Notifications
You must be signed in to change notification settings - Fork 7.6k
AutoUpdate Framework #14177
AutoUpdate Framework #14177
Changes from 9 commits
409d4ed
ac37cde
446e389
ca0000e
0ff81d1
ada6b28
537430b
7b30fb4
4f9ac69
4efe928
bcb2a3e
b50f8de
4fb6582
b272289
9ae2fc5
9b89697
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.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.REGISTER_BRACKETS_FUNCTIONS = "brackets.registerBracketsFunctions"; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
/* | ||
* 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check for validity of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _write is an internal function, which I have wrapped inside the function writePromise(), which in turn, is wrapped inside the write() function, which checks for the validity of the file. Hence, checking here is redundant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is not harm in checking for validity of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nethip , the requirement here is to do a force write. If the file exists, the content is overwritten. If it doesn't exist, the file is created and written. I am passing the boolean to be "true" in writeText, which ensures this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mbhavi Let us not have discussion of having a null check or not. It is a simple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
var content = JSON.stringify(json); | ||
FileUtils.writeText(_file, content, true) | ||
.done(function () { | ||
result.resolve(); | ||
}) | ||
.fail(function (err) { | ||
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 | ||
}; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
if (brackets.app.isAutoUpdateInProgress) {
to check if this function is registered or not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isAutoUpdateInProgress() function has been added to the core. It is not a registered function. Hence, we need not have this check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbhavi It is a registered in
appshell_extensions.js
. Consider this scenario where a user who is running the older shell but with newerbrackets
code, will never find this function, so it is a good idea to bailout. Please add a check here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly believe suppressing the error would turn out to be harmful in this case, not showing the error to the user would be misleading to him/her believing that the feature can work with just the brackets changes.
Moreover, I don't see that with any of the other functions' invocations. I believe doing that will be unnecessary bloating of the code, as this is most likely to happen only in the dev machines, which I think should be okay.