Skip to content

Commit ccc942e

Browse files
owenc4a4rogerwang
authored andcommitted
[API] Get the value of manifest
Fix nwjs#360
1 parent 288701c commit ccc942e

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/api/app/app.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ void App::Call(Shell* shell,
113113
return;
114114
} else if (method == "ClearCache") {
115115
ClearCache(GetRenderProcessHost());
116+
} else if (method == "GetPackage") {
117+
result->AppendString(shell->GetPackage()->package_string());
118+
return;
116119
}
117120

118121
NOTREACHED() << "Calling unknown sync method " << method << " of App";

src/api/app/app.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1919
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2020

21-
var argv, fullArgv, dataPath;
21+
var argv, fullArgv, dataPath, manifest;
2222

2323
function App() {
2424
}
@@ -83,6 +83,14 @@ App.prototype.__defineGetter__('dataPath', function() {
8383
return dataPath;
8484
});
8585

86+
App.prototype.__defineGetter__('manifest', function() {
87+
if (!manifest) {
88+
manifest = JSON.parse(
89+
nw.callStaticMethodSync('App', 'GetPackage', [ ])[0]);
90+
}
91+
return manifest;
92+
});
93+
8694
// Store App object in node's context.
8795
if (process['_nw_app']) {
8896
exports.App = process['_nw_app'];

src/nw_package.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "base/file_util.h"
2727
#include "base/files/scoped_temp_dir.h"
2828
#include "base/json/json_file_value_serializer.h"
29+
#include "base/json/json_string_value_serializer.h"
2930
#include "base/strings/string_number_conversions.h"
3031
#include "base/strings/string_tokenizer.h"
3132
#include "base/string_util.h"
@@ -282,6 +283,13 @@ bool Package::InitFromPath() {
282283
// Save result in global
283284
root_.reset(static_cast<DictionaryValue*>(root.release()));
284285

286+
// Save origin package info
287+
// Since we will change some value in root_,
288+
// We need to catch the origin value of package.json
289+
package_string_ = "";
290+
JSONStringValueSerializer stringSerializer(&package_string_);
291+
stringSerializer.Serialize(*root_);
292+
285293
// Check fields
286294
const char* required_fields[] = {
287295
switches::kmMain,

src/nw_package.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class Package {
7878
// Window field of manifest.
7979
base::DictionaryValue* window();
8080

81+
// Manifest string.
82+
std::string package_string() { return package_string_; }
83+
8184
private:
8285
bool InitFromPath();
8386
void InitWithDefault();
@@ -102,6 +105,9 @@ class Package {
102105
// The parsed package.json.
103106
scoped_ptr<base::DictionaryValue> root_;
104107

108+
// The origin JSON string package.json.
109+
std::string package_string_;
110+
105111
// Stored url for error page.
106112
std::string error_page_url_;
107113

0 commit comments

Comments
 (0)