Skip to content

Commit

Permalink
[AutoUpdater][OSX] add squirrel auto updater
Browse files Browse the repository at this point in the history
  • Loading branch information
jefry-vcube committed Feb 23, 2017
1 parent 0444a05 commit 03ff41b
Show file tree
Hide file tree
Showing 25 changed files with 1,076 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ tests/tmp-nw
tags
Thumbs.db
/tmp
external_binaries
40 changes: 39 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import("//build/toolchain/toolchain.gni")
if (is_mac) {
import("//build/util/branding.gni")
chrome_framework_name = chrome_product_full_name + " Framework"
cflags = [
"-F",
"../../content/nw/external_binaries",
]
}
import("//build/util/version.gni")

Expand All @@ -12,7 +16,30 @@ group("nwjs") {
"//third_party/ffmpeg:ffmpeg"
]
if (is_mac) {
deps += [ ":copy_ffmpeg" ]
deps += [ ":copy_ffmpeg", ":copy_external_binaries" ]
}
}

static_library("nw_autoupdater") {
deps = [
"//base",
]
sources = [
"src/browser/auto_updater.h",
"src/browser/auto_updater.cc",
"src/browser/auto_updater_mac.mm",
]
if (is_mac) {
libs = [
"Squirrel.framework",
"ReactiveCocoa.framework",
"Mantle.framework",
]
cflags_objcc = [
"-Wno-error=unused-command-line-argument",
"-fobjc-runtime=macosx-10.8",
"-fobjc-weak",
]
}
}

Expand Down Expand Up @@ -92,6 +119,8 @@ nw_chrome_browser_sources = [
"src/api/object_manager.h",
"src/api/object_manager_factory.cc",
"src/api/object_manager_factory.h",
"src/api/auto_updater/api_auto_updater.cc",
"src/api/auto_updater/api_auto_updater.h",
"src/api/base/base.cc",
"src/api/base/base.h",
"src/api/menu/menu.cc",
Expand Down Expand Up @@ -121,6 +150,7 @@ static_library("nw_browser") {
"//third_party/zlib:minizip",
"//skia",
":nw_base",
":nw_autoupdater",
"//content/nw/src/api:nw_api",
"//content/nw/src/api:nw_api_registration",
"//third_party/protobuf:protobuf_lite",
Expand Down Expand Up @@ -256,6 +286,14 @@ if (is_mac) {
"//third_party/ffmpeg:ffmpeg"
]
}
copy("copy_external_binaries") {
sources = [
"external_binaries/Squirrel.framework",
"external_binaries/ReactiveCocoa.framework",
"external_binaries/Mantle.framework",
]
outputs = [ "$root_out_dir/$chrome_product_full_name.app/Contents/Versions/$chrome_version_full/{{source_file_part}}" ]
}
}

copy("copy_node") {
Expand Down
46 changes: 46 additions & 0 deletions nw.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,46 @@
},
},
},
'conditions': [
['OS=="mac"', {
'mac_framework_dirs': [
'<(DEPTH)/../content/nw/external_binaries',
],
}],
],

},
'targets': [
{
'target_name': 'nw_autoupdater',
'type': 'static_library',
'dependencies': [
'<(DEPTH)/base/base.gyp:base',
],
'sources': [
'src/browser/auto_updater.h',
'src/browser/auto_updater.cc',
'src/browser/auto_updater_mac.mm',
],
'conditions': [
['OS == "mac"', {
'link_settings': {
'libraries': [
'external_binaries/Squirrel.framework',
'external_binaries/ReactiveCocoa.framework',
'external_binaries/Mantle.framework',
],
},
'xcode_settings': {
'OTHER_CFLAGS': [
'-Wno-error=unused-command-line-argument',
'-fobjc-runtime=macosx-10.8',
'-fobjc-weak',
],
},
}],
],
},
{
'target_name': 'nw_base',
'type': '<(component)',
Expand Down Expand Up @@ -71,6 +109,7 @@
'<(DEPTH)/third_party/zlib/zlib.gyp:minizip',
'<(DEPTH)/skia/skia.gyp:skia',
'nw_base',
'nw_autoupdater',
'<(DEPTH)/content/nw/src/api/api.gyp:nw_api',
'<(DEPTH)/content/nw/src/api/api_registration.gyp:nw_api_registration',
'<(DEPTH)/extensions/browser/api/api_registration.gyp:extensions_api_registration',
Expand Down Expand Up @@ -107,6 +146,8 @@
'src/api/object_manager.h',
'src/api/object_manager_factory.cc',
'src/api/object_manager_factory.h',
'src/api/auto_updater/api_auto_updater.cc',
'src/api/auto_updater/api_auto_updater.h',
'src/api/base/base.cc',
'src/api/base/base.h',
'src/api/menu/menu.cc',
Expand Down Expand Up @@ -574,5 +615,10 @@
},
}
],
'xcode_settings': {
'LD_RUNPATH_SEARCH_PATHS': [
'@loader_path/..',
],
},
}

4 changes: 4 additions & 0 deletions src/api/_api_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"channel": "stable",
"contexts": ["blessed_extension"]
},
"nw.AutoUpdater": {
"channel": "stable",
"contexts": ["blessed_extension"]
},
"nw.Window": {
"channel": "stable",
"contexts": ["blessed_extension"]
Expand Down
127 changes: 127 additions & 0 deletions src/api/auto_updater/api_auto_updater.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Copyright (c) 2016 Jefry Tedjokusumo <[email protected]>
//
// 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 co
// pies 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 al
// l copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
// ETHER 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.

#include "base/values.h"
#include "content/nw/src/api/auto_updater/api_auto_updater.h"
#include "content/nw/src/api/nw_auto_updater.h"
#include "content/nw/src/browser/auto_updater.h"
#include "extensions/browser/extensions_browser_client.h"

using namespace extensions::nwapi::nw__auto_updater;
using namespace content;

namespace extensions {

static void DispatchEvent(events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> args) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
ExtensionsBrowserClient::Get()->BroadcastEventToRenderers(
histogram_value, event_name, std::move(args));
}


class AutoUpdaterObserver : public auto_updater::Delegate {

// An error happened.
void OnError(const std::string& error) override {
std::unique_ptr<base::ListValue> arguments (new base::ListValue());
arguments->AppendString(error);
DispatchEvent(events::HistogramValue::UNKNOWN,
nwapi::nw__auto_updater::OnError::kEventName,
std::move(arguments));
}

// Checking to see if there is an update
void OnCheckingForUpdate() override {
std::unique_ptr<base::ListValue> arguments (new base::ListValue());
DispatchEvent(events::HistogramValue::UNKNOWN,
nwapi::nw__auto_updater::OnCheckingForUpdate::kEventName,
std::move(arguments));
}

// There is an update available and it is being downloaded
void OnUpdateAvailable() override {
std::unique_ptr<base::ListValue> arguments (new base::ListValue());
DispatchEvent(events::HistogramValue::UNKNOWN,
nwapi::nw__auto_updater::OnUpdateAvailable::kEventName,
std::move(arguments));
}

// There is no available update.
void OnUpdateNotAvailable() override {
std::unique_ptr<base::ListValue> arguments (new base::ListValue());
DispatchEvent(events::HistogramValue::UNKNOWN,
nwapi::nw__auto_updater::OnUpdateNotAvailable::kEventName,
std::move(arguments));
}

// There is a new update which has been downloaded.
void OnUpdateDownloaded(const std::string& release_notes,
const std::string& release_name,
const base::Time& release_date,
const std::string& update_url) override {
std::unique_ptr<base::ListValue> arguments (new base::ListValue());
arguments->AppendString(release_notes);
arguments->AppendString(release_name);
arguments->AppendDouble(release_date.ToJsTime());
arguments->AppendString(update_url);
DispatchEvent(events::HistogramValue::UNKNOWN,
nwapi::nw__auto_updater::OnUpdateDownloaded::kEventName,
std::move(arguments));
}

public:
AutoUpdaterObserver() {
}

~AutoUpdaterObserver() override {
}

};

AutoUpdaterObserver gAutoUpdateObserver;
NwAutoUpdaterNativeCallSyncFunction::NwAutoUpdaterNativeCallSyncFunction() {}

bool NwAutoUpdaterNativeCallSyncFunction::RunNWSync(base::ListValue* response, std::string* error) {
if (!auto_updater::AutoUpdater::GetDelegate()) {
auto_updater::AutoUpdater::SetDelegate(&gAutoUpdateObserver);
}

std::string method;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &method));

if (method == "SetFeedURL") {
auto_updater::AutoUpdater::HeaderMap headers;
std::string url;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &url));
auto_updater::AutoUpdater::SetFeedURL(url, headers);
} else if (method == "GetFeedURL") {
std::string url = auto_updater::AutoUpdater::GetFeedURL();
response->AppendString(url);
} else if (method == "QuitAndInstall") {
auto_updater::AutoUpdater::QuitAndInstall();
} else if (method == "CheckForUpdates") {
auto_updater::AutoUpdater::CheckForUpdates();
}
return true;
}


} // namespace extension
43 changes: 43 additions & 0 deletions src/api/auto_updater/api_auto_updater.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2016 Jefry Tedjokusumo <[email protected]>
//
// 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 co
// pies 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 al
// l copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
// ETHER 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.


#ifndef CONTENT_NW_SRC_API_AUTO_UPDATER_H_
#define CONTENT_NW_SRC_API_AUTO_UPDATER_H_

#include "extensions/browser/extension_function.h"

namespace extensions {

class NwAutoUpdaterNativeCallSyncFunction: public NWSyncExtensionFunction {
public:
NwAutoUpdaterNativeCallSyncFunction();
bool RunNWSync(base::ListValue* response, std::string* error) override;

protected:
~NwAutoUpdaterNativeCallSyncFunction() override {}
DECLARE_EXTENSION_FUNCTION("nw.AutoUpdater.NativeCallSync", UNKNOWN)

private:
DISALLOW_COPY_AND_ASSIGN(NwAutoUpdaterNativeCallSyncFunction);
};

} // namespace extensions

#endif //CONTENT_NW_SRC_API_AUTO_UPDATER_H_
2 changes: 2 additions & 0 deletions src/api/dispatcher_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ DispatcherBindings::RequireNwGui(const v8::FunctionCallbackInfo<v8::Value>& args
NwGui, global, v8::String::NewFromUtf8(isolate, "shortcut.js"), IDR_NW_API_SHORTCUT_JS);
RequireFromResource(args.This(),
NwGui, global, v8::String::NewFromUtf8(isolate, "screen.js"), IDR_NW_API_SCREEN_JS);
RequireFromResource(args.This(),
NwGui, global, v8::String::NewFromUtf8(isolate, "auto_updater.js"), IDR_NW_API_AUTO_UPDATE_JS);

g_context->Exit();
args.GetReturnValue().Set(handle_scope.Escape(NwGui));
Expand Down
6 changes: 6 additions & 0 deletions src/api/dispatcher_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/nw/src/api/api_messages.h"
#include "content/nw/src/api/app/app.h"
#include "content/nw/src/api/auto_updater/api_auto_updater.h"
#include "content/nw/src/api/base/base.h"
#include "content/nw/src/api/clipboard/clipboard.h"
#include "content/nw/src/api/event/event.h"
Expand Down Expand Up @@ -171,6 +172,8 @@ void DispatcherHost::OnAllocateObject(int object_id,
objects_registry_.AddWithID(new Shortcut(object_id, weak_ptr_factory_.GetWeakPtr(), option), object_id);
} else if (type == "Screen") {
objects_registry_.AddWithID(new EventListener(object_id, weak_ptr_factory_.GetWeakPtr(), option), object_id);
} else if (type == "AutoUpdater") {
objects_registry_.AddWithID(new EventListener(object_id, weak_ptr_factory_.GetWeakPtr(), option), object_id);
} else {
LOG(ERROR) << "Allocate an object of unknown type: " << type;
objects_registry_.AddWithID(new Base(object_id, weak_ptr_factory_.GetWeakPtr(), option), object_id);
Expand Down Expand Up @@ -264,6 +267,9 @@ void DispatcherHost::OnCallStaticMethodSync(
} else if (type == "Screen") {
nwapi::Screen::Call(this, method, arguments, result);
return;
} else if (type == "AutoUpdater") {
nwapi::AutoUpdater::Call(this, method, arguments, result);
return;
}

NOTREACHED() << "Calling unknown method " << method << " of class " << type;
Expand Down
19 changes: 19 additions & 0 deletions src/api/nw_auto_updater.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2016 The NW.js Authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.

// nw AutoUpdater API
[implemented_in="content/nw/src/api/auto_updater/api_auto_updater.h"]
namespace nw.AutoUpdater {
interface Events {
static void onError(DOMString msg);
static void onCheckingForUpdate();
static void onUpdateAvailable();
static void onUpdateNotAvailable();
static void onUpdateDownloaded(DOMString releaseNotes, DOMString releaseName, double releaseDate, DOMString updateURL);
};

interface Functions {
static DOMString[] NativeCallSync(DOMString method, DOMString param);
};
};
Loading

0 comments on commit 03ff41b

Please sign in to comment.