electron/shell/browser/auto_updater_mac.mm
electron-roller[bot] bc1ba1fe9d
chore: bump chromium to 120.0.6099.0 (main) (#40316)
* chore: bump chromium in DEPS to 120.0.6086.0

* chore: update patches

* chore: rename FrameSubscriber::OnNewCropVersion()

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4905819

just a simple renaming

* chore: rename ToJsTime() to .InMillisecondsFSinceUnixEpoch()

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4956111

function renamed upstream

* chore: rename ToDoubleT() to .InSecondsFSinceUnixEpoch()

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4956111

function renamed upstream

* chore: rename FromDoubleT() to .FromSecondsSinceUnixEpoch()

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4956111

function renamed upstream

* chore: bump chromium in DEPS to 120.0.6088.2

* chore: update patches

* chore: regen filenames.libcxx.gni

* chore: migrate from (removed upstream) inputFormType to formControlType

* chore: bump chromium in DEPS to 120.0.6089.0

* chore: update allow_disabling_blink_scheduler_throttling_per_renderview.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4828507

manually sync to upstream changes + reduce diff size

* chore: update patches

* chore: bump chromium in DEPS to 120.0.6090.0

* chore: update fix_disabling_background_throttling_in_compositor.patch

no manual changes; patch applied with fuzz 2 (4 lines)

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4944206

* chore: update fix_handle_no_top_level_aura_window_in_webcontentsimpl.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4946653

do not patch WebContentsImpl::SetWindowShowState() any longer because it has been removed

* chore: update patches

* chore: bump chromium in DEPS to 120.0.6091.0

* chore: update patches

* chore: bump chromium in DEPS to 120.0.6093.0

* chore: bump chromium in DEPS to 120.0.6095.0

* chore: bump chromium in DEPS to 120.0.6096.0

* chore: bump chromium in DEPS to 120.0.6097.0

* chore: update patches

* chore: update patch after rebase

* 4961495: [document pip] Focus the window when opened manually

https://chromium-review.googlesource.com/c/chromium/src/+/4961495

* [Extensions UserScripts] Store extensions with user scripts in tracker

 | https://chromium-review.googlesource.com/c/chromium/src/+/4950530

* chore: bump chromium in DEPS to 120.0.6099.0

* chore: update patches

* chore: update filenames.libcxx.gni

* chore: remove trailing space

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2023-11-01 10:02:12 -04:00

190 lines
6.2 KiB
Text

// Copyright (c) 2013 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/auto_updater.h"
#include <string>
#import <ReactiveObjC/NSObject+RACPropertySubscribing.h>
#import <ReactiveObjC/RACCommand.h>
#import <ReactiveObjC/RACSignal.h>
#import <Squirrel/Squirrel.h>
#include "base/functional/bind.h"
#include "base/strings/sys_string_conversions.h"
#include "base/time/time.h"
#include "gin/arguments.h"
#include "shell/browser/browser.h"
#include "shell/common/gin_converters/value_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/error_thrower.h"
namespace auto_updater {
namespace {
// The global SQRLUpdater object.
SQRLUpdater* __strong g_updater = nil;
} // namespace
namespace {
bool g_update_available = false;
std::string update_url_ = ""; // NOLINT(runtime/string)
} // namespace
std::string AutoUpdater::GetFeedURL() {
return update_url_;
}
// static
void AutoUpdater::SetFeedURL(gin::Arguments* args) {
gin_helper::ErrorThrower thrower(args->isolate());
gin_helper::Dictionary opts;
std::string feed;
HeaderMap requestHeaders;
std::string serverType = "default";
v8::Local<v8::Value> first_arg = args->PeekNext();
if (!first_arg.IsEmpty() && first_arg->IsString()) {
if (args->GetNext(&feed)) {
args->GetNext(&requestHeaders);
}
} else if (args->GetNext(&opts)) {
if (!opts.Get("url", &feed)) {
thrower.ThrowError(
"Expected options object to contain a 'url' string property in "
"setFeedUrl call");
return;
}
opts.Get("headers", &requestHeaders);
opts.Get("serverType", &serverType);
if (serverType != "default" && serverType != "json") {
thrower.ThrowError("Expected serverType to be 'default' or 'json'");
return;
}
} else {
thrower.ThrowError(
"Expected an options object with a 'url' property to be provided");
return;
}
Delegate* delegate = GetDelegate();
if (!delegate)
return;
update_url_ = feed;
NSURL* url = [NSURL URLWithString:base::SysUTF8ToNSString(feed)];
NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url];
for (const auto& it : requestHeaders) {
[urlRequest setValue:base::SysUTF8ToNSString(it.second)
forHTTPHeaderField:base::SysUTF8ToNSString(it.first)];
}
if (g_updater)
g_updater = nil;
// Initialize the SQRLUpdater.
@try {
if (serverType == "json") {
NSString* nsAppVersion =
base::SysUTF8ToNSString(electron::Browser::Get()->GetVersion());
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest
forVersion:nsAppVersion];
} else {
// default
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest];
}
} @catch (NSException* error) {
delegate->OnError(base::SysNSStringToUTF8(error.reason));
return;
}
[[g_updater rac_valuesForKeyPath:@"state" observer:g_updater]
subscribeNext:^(NSNumber* stateNumber) {
int state = [stateNumber integerValue];
// Dispatching the event on main thread.
dispatch_async(dispatch_get_main_queue(), ^{
if (state == SQRLUpdaterStateCheckingForUpdate)
delegate->OnCheckingForUpdate();
else if (state == SQRLUpdaterStateDownloadingUpdate)
delegate->OnUpdateAvailable();
});
}];
}
// static
void AutoUpdater::CheckForUpdates() {
Delegate* delegate = GetDelegate();
if (!delegate)
return;
[[[[g_updater.checkForUpdatesCommand execute:nil]
// Send a `nil` after everything...
concat:[RACSignal return:nil]]
// But only take the first value. If an update is sent, we'll get that.
// Otherwise, we'll get our inserted `nil` value.
take:1]
subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) {
if (downloadedUpdate) {
g_update_available = true;
SQRLUpdate* update = downloadedUpdate.update;
// There is a new update that has been downloaded.
delegate->OnUpdateDownloaded(
base::SysNSStringToUTF8(update.releaseNotes),
base::SysNSStringToUTF8(update.releaseName),
base::Time::FromSecondsSinceUnixEpoch(
update.releaseDate.timeIntervalSince1970),
base::SysNSStringToUTF8(update.updateURL.absoluteString));
} else {
g_update_available = false;
// When the completed event is sent with no update, then we know there
// is no update available.
delegate->OnUpdateNotAvailable();
}
}
error:^(NSError* error) {
NSMutableString* failureString =
[NSMutableString stringWithString:error.localizedDescription];
if (error.localizedFailureReason) {
[failureString appendString:@": "];
[failureString appendString:error.localizedFailureReason];
}
if (error.localizedRecoverySuggestion) {
if (![failureString hasSuffix:@"."])
[failureString appendString:@"."];
[failureString appendString:@" "];
[failureString appendString:error.localizedRecoverySuggestion];
}
delegate->OnError(base::SysNSStringToUTF8(failureString), error.code,
base::SysNSStringToUTF8(error.domain));
}];
}
void AutoUpdater::QuitAndInstall() {
Delegate* delegate = AutoUpdater::GetDelegate();
if (g_update_available) {
[[g_updater relaunchToInstallUpdate] subscribeError:^(NSError* error) {
if (delegate)
delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription),
error.code, base::SysNSStringToUTF8(error.domain));
}];
} else {
if (delegate)
delegate->OnError("No update available, can't quit and install");
}
}
bool AutoUpdater::IsVersionAllowedForUpdate(const std::string& current_version,
const std::string& target_version) {
return [SQRLUpdater
isVersionAllowedForUpdate:base::SysUTF8ToNSString(target_version)
from:base::SysUTF8ToNSString(current_version)];
}
} // namespace auto_updater