mirror of
https://github.com/electron/electron.git
synced 2026-02-26 03:01:17 -05:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c49899af4c | ||
|
|
92ef86b64a | ||
|
|
30d8e1834c | ||
|
|
b35f4eeaf0 | ||
|
|
63f7692da5 | ||
|
|
a4af2354dc | ||
|
|
bd49864f1d | ||
|
|
abc5d1280d | ||
|
|
712bafde02 | ||
|
|
013768c429 | ||
|
|
681a2c1aba | ||
|
|
98521d22ec |
11
.github/workflows/apply-patches.yml
vendored
11
.github/workflows/apply-patches.yml
vendored
@@ -56,16 +56,17 @@ jobs:
|
||||
path: src/electron
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
- name: Rebase onto Base Branch
|
||||
ref: ${{ github.event.pull_request.base.ref }}
|
||||
- name: Merge PR HEAD
|
||||
working-directory: src/electron
|
||||
env:
|
||||
BASE_REF: ${{ github.event.pull_request.base.ref }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
run: |
|
||||
git config user.email "electron@github.com"
|
||||
git config user.name "Electron Bot"
|
||||
git fetch origin ${BASE_REF}
|
||||
git rebase origin/${BASE_REF}
|
||||
git fetch origin refs/pull/${PR_NUMBER}/head
|
||||
git merge --squash FETCH_HEAD
|
||||
git commit -n -m "Squashed commits"
|
||||
- name: Checkout & Sync & Save
|
||||
uses: ./src/electron/.github/actions/checkout
|
||||
with:
|
||||
|
||||
8
.github/workflows/rerun-apply-patches.yml
vendored
8
.github/workflows/rerun-apply-patches.yml
vendored
@@ -35,20 +35,20 @@ jobs:
|
||||
echo "Processing PR #${PR_NUMBER}"
|
||||
|
||||
# Find the Apply Patches workflow check for this PR
|
||||
CHECK=$(gh pr checks "$PR_NUMBER" --json link,name,state,workflow --jq '[.[] | select(.workflow == "Apply Patches" and .name == "apply-patches")] | first')
|
||||
CHECK=$(gh pr view "$PR_NUMBER" --json statusCheckRollup --jq '[.statusCheckRollup[] | select(.workflowName == "Apply Patches" and .name == "apply-patches")] | first')
|
||||
|
||||
if [ -z "$CHECK" ] || [ "$CHECK" = "null" ]; then
|
||||
echo " No Apply Patches workflow found for PR #${PR_NUMBER}"
|
||||
continue
|
||||
fi
|
||||
|
||||
STATE=$(echo "$CHECK" | jq -r '.state')
|
||||
if [ "$STATE" = "SKIPPED" ]; then
|
||||
CONCLUSION=$(echo "$CHECK" | jq -r '.conclusion')
|
||||
if [ "$CONCLUSION" = "SKIPPED" ]; then
|
||||
echo " apply-patches job was skipped for PR #${PR_NUMBER} (no patches)"
|
||||
continue
|
||||
fi
|
||||
|
||||
LINK=$(echo "$CHECK" | jq -r '.link')
|
||||
LINK=$(echo "$CHECK" | jq -r '.detailsUrl')
|
||||
|
||||
# Extract the run ID from the link (format: .../runs/RUN_ID/job/JOB_ID)
|
||||
RUN_ID=$(echo "$LINK" | grep -oE 'runs/[0-9]+' | cut -d'/' -f2)
|
||||
|
||||
32
BUILD.gn
32
BUILD.gn
@@ -420,37 +420,6 @@ action("electron_generate_node_defines") {
|
||||
args = [ rebase_path(target_gen_dir) ] + rebase_path(inputs)
|
||||
}
|
||||
|
||||
# MSIX updater needs to be in a separate source_set because it uses C++/WinRT
|
||||
# headers that require exceptions to be enabled.
|
||||
source_set("electron_msix_updater") {
|
||||
sources = [
|
||||
"shell/browser/api/electron_api_msix_updater.cc",
|
||||
"shell/browser/api/electron_api_msix_updater.h",
|
||||
]
|
||||
|
||||
configs += [ "//third_party/electron_node:node_external_config" ]
|
||||
|
||||
public_configs = [ ":electron_lib_config" ]
|
||||
|
||||
if (is_win) {
|
||||
cflags_cc = [
|
||||
"/EHsc", # Enable C++ exceptions for C++/WinRT
|
||||
"-Wno-c++98-compat-extra-semi", #Suppress C++98 compatibility warnings
|
||||
]
|
||||
|
||||
include_dirs = [ "//third_party/nearby/src/internal/platform/implementation/windows/generated" ]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//content/public/browser",
|
||||
"//gin",
|
||||
"//third_party/electron_node/deps/simdjson",
|
||||
"//third_party/electron_node/deps/uv",
|
||||
"//v8",
|
||||
]
|
||||
}
|
||||
|
||||
source_set("electron_lib") {
|
||||
configs += [
|
||||
"//v8:external_startup_data",
|
||||
@@ -466,7 +435,6 @@ source_set("electron_lib") {
|
||||
":electron_fuses",
|
||||
":electron_generate_node_defines",
|
||||
":electron_js2c",
|
||||
":electron_msix_updater",
|
||||
":electron_version_header",
|
||||
":resources",
|
||||
"buildflags",
|
||||
|
||||
@@ -756,6 +756,9 @@ Returns [`Rectangle`](structures/rectangle.md) - The `bounds` of the window as `
|
||||
> [!NOTE]
|
||||
> On macOS, the y-coordinate value returned will be at minimum the [Tray](tray.md) height. For example, calling `win.setBounds({ x: 25, y: 20, width: 800, height: 600 })` with a tray height of 38 means that `win.getBounds()` will return `{ x: 25, y: 38, width: 800, height: 600 }`.
|
||||
|
||||
> [!NOTE]
|
||||
> On Wayland, this method will return `{ x: 0, y: 0, ... }` as introspecting or programmatically changing the global window coordinates is prohibited.
|
||||
|
||||
#### `win.getBackgroundColor()`
|
||||
|
||||
Returns `string` - Gets the background color of the window in Hex (`#RRGGBB`) format.
|
||||
@@ -969,6 +972,9 @@ Moves window to `x` and `y`.
|
||||
|
||||
Returns `Integer[]` - Contains the window's current position.
|
||||
|
||||
> [!NOTE]
|
||||
> On Wayland, this method will return `[0, 0]` as introspecting or programmatically changing the global window coordinates is prohibited.
|
||||
|
||||
#### `win.setTitle(title)`
|
||||
|
||||
* `title` string
|
||||
|
||||
@@ -862,6 +862,9 @@ Returns [`Rectangle`](structures/rectangle.md) - The `bounds` of the window as `
|
||||
> [!NOTE]
|
||||
> On macOS, the y-coordinate value returned will be at minimum the [Tray](tray.md) height. For example, calling `win.setBounds({ x: 25, y: 20, width: 800, height: 600 })` with a tray height of 38 means that `win.getBounds()` will return `{ x: 25, y: 38, width: 800, height: 600 }`.
|
||||
|
||||
> [!NOTE]
|
||||
> On Wayland, this method will return `{ x: 0, y: 0, ... }` as introspecting or programmatically changing the global window coordinates is prohibited.
|
||||
|
||||
#### `win.getBackgroundColor()`
|
||||
|
||||
Returns `string` - Gets the background color of the window in Hex (`#RRGGBB`) format.
|
||||
@@ -1087,6 +1090,9 @@ Not supported on Wayland (Linux).
|
||||
|
||||
Returns `Integer[]` - Contains the window's current position.
|
||||
|
||||
> [!NOTE]
|
||||
> On Wayland, this method will return `[0, 0]` as introspecting or programmatically changing the global window coordinates is prohibited.
|
||||
|
||||
#### `win.setTitle(title)`
|
||||
|
||||
* `title` string
|
||||
|
||||
@@ -107,7 +107,7 @@ A `string` (optional) indicating the item's role, if set. Can be `undo`, `redo`,
|
||||
|
||||
#### `menuItem.accelerator`
|
||||
|
||||
An `Accelerator` (optional) indicating the item's accelerator, if set.
|
||||
An `Accelerator | null` indicating the item's accelerator, if set.
|
||||
|
||||
#### `menuItem.userAccelerator` _Readonly_ _macOS_
|
||||
|
||||
|
||||
@@ -277,6 +277,8 @@ filenames = {
|
||||
"shell/browser/api/electron_api_in_app_purchase.h",
|
||||
"shell/browser/api/electron_api_menu.cc",
|
||||
"shell/browser/api/electron_api_menu.h",
|
||||
"shell/browser/api/electron_api_msix_updater.cc",
|
||||
"shell/browser/api/electron_api_msix_updater.h",
|
||||
"shell/browser/api/electron_api_native_theme.cc",
|
||||
"shell/browser/api/electron_api_native_theme.h",
|
||||
"shell/browser/api/electron_api_net_log.cc",
|
||||
|
||||
@@ -353,6 +353,7 @@ export function shouldOverrideCheckStatus (role: RoleId) {
|
||||
|
||||
export function getDefaultAccelerator (role: RoleId) {
|
||||
if (hasRole(role)) return roleList[role].accelerator;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function shouldRegisterAccelerator (role: RoleId) {
|
||||
|
||||
@@ -25,7 +25,7 @@ const MenuItem = function (this: any, options: any) {
|
||||
|
||||
this.overrideReadOnlyProperty('type', roles.getDefaultType(this.role));
|
||||
this.overrideReadOnlyProperty('role');
|
||||
this.overrideReadOnlyProperty('accelerator');
|
||||
this.overrideReadOnlyProperty('accelerator', roles.getDefaultAccelerator(this.role));
|
||||
this.overrideReadOnlyProperty('icon');
|
||||
this.overrideReadOnlyProperty('submenu');
|
||||
|
||||
|
||||
@@ -148,3 +148,4 @@ viz_do_not_overallocate_surface_on_initial_render.patch
|
||||
viz_create_isbufferqueuesupportedandenabled.patch
|
||||
viz_fix_visual_artifacts_while_resizing_window_with_dcomp.patch
|
||||
graphite_handle_out_of_order_recording_errors.patch
|
||||
ozone_wayland_treat_dnd_drop_performed_with_none_action_as_a.patch
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: AbdAlRahman Gad <agad@igalia.com>
|
||||
Date: Wed, 15 Oct 2025 09:34:12 -0700
|
||||
Subject: Ozone/Wayland: Treat DND drop performed with NONE action as a
|
||||
cancellation
|
||||
|
||||
According to the Wayland protocol, a "drop performed" event can be
|
||||
followed with a `cancelled` event. This is the behavior of compositors
|
||||
like KWin.
|
||||
|
||||
We were always treating "drop performed" as a completed drop. This
|
||||
change corrects the logic to pass `DragResult::kCancelled` in this
|
||||
scenario.
|
||||
|
||||
Bug: 447037092
|
||||
Change-Id: I0f3805365355bb364e15a9ab6d5a6954698cce1f
|
||||
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7002773
|
||||
Reviewed-by: Nick Yamane <nickdiego@igalia.com>
|
||||
Reviewed-by: Max Ihlenfeldt <max@igalia.com>
|
||||
Commit-Queue: AbdAlRahman Gad <agad@igalia.com>
|
||||
Cr-Commit-Position: refs/heads/main@{#1530269}
|
||||
|
||||
diff --git a/ui/ozone/platform/wayland/host/wayland_data_device.h b/ui/ozone/platform/wayland/host/wayland_data_device.h
|
||||
index 128baea3fe9a03f9d76afa234d6c21e9a4583cf7..d9824490e402308e64b5f54cbf9b46646f6021e8 100644
|
||||
--- a/ui/ozone/platform/wayland/host/wayland_data_device.h
|
||||
+++ b/ui/ozone/platform/wayland/host/wayland_data_device.h
|
||||
@@ -90,6 +90,8 @@ class WaylandDataDevice : public WaylandDataDeviceBase {
|
||||
FRIEND_TEST_ALL_PREFIXES(WaylandDataDragControllerTest, StartDrag);
|
||||
FRIEND_TEST_ALL_PREFIXES(WaylandDataDragControllerTest, ReceiveDrag);
|
||||
FRIEND_TEST_ALL_PREFIXES(WaylandDataDragControllerTest, CancelIncomingDrag);
|
||||
+ FRIEND_TEST_ALL_PREFIXES(WaylandDataDragControllerTest,
|
||||
+ DndDropPerformedWithNoneActionThenCancelled);
|
||||
FRIEND_TEST_ALL_PREFIXES(WaylandDataDragControllerTest,
|
||||
DestroyWindowWhileFetchingForeignData);
|
||||
FRIEND_TEST_ALL_PREFIXES(WaylandDataDragControllerTest,
|
||||
diff --git a/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc b/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc
|
||||
index 893bf03a8f4aa473faf3a1232ea1902d226d8ca6..b557e4654dbe2a5d6f94bf31466c78bf83744c32 100644
|
||||
--- a/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc
|
||||
+++ b/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc
|
||||
@@ -573,7 +573,13 @@ void WaylandDataDragController::OnDataSourceDropPerformed(
|
||||
<< " origin=" << !!origin_window_
|
||||
<< " nested_dispatcher=" << !!nested_dispatcher_;
|
||||
|
||||
- HandleDragEnd(DragResult::kCompleted, timestamp);
|
||||
+ // Treat a "drop performed" event with a `dnd_action` of NONE (0) as a
|
||||
+ // cancellation (passing `kCancelled`). Per the protocol, `cancelled` event
|
||||
+ // can be sent after "drop performed", that is what `KWin` does, for example.
|
||||
+ // See crbug.com/447037092.
|
||||
+ HandleDragEnd(data_source_->dnd_action() ? DragResult::kCompleted
|
||||
+ : DragResult::kCancelled,
|
||||
+ timestamp);
|
||||
}
|
||||
|
||||
void WaylandDataDragController::OnDataSourceSend(WaylandDataSource* source,
|
||||
diff --git a/ui/ozone/platform/wayland/host/wayland_data_drag_controller_unittest.cc b/ui/ozone/platform/wayland/host/wayland_data_drag_controller_unittest.cc
|
||||
index c70a03d082f518b48dda58be893fc9181507e1ab..baf42205a786d42a341a6dc9265c8d929c6a7454 100644
|
||||
--- a/ui/ozone/platform/wayland/host/wayland_data_drag_controller_unittest.cc
|
||||
+++ b/ui/ozone/platform/wayland/host/wayland_data_drag_controller_unittest.cc
|
||||
@@ -497,6 +497,36 @@ MATCHER_P(PointFNear, n, "") {
|
||||
return arg.IsWithinDistance(n, 0.01f);
|
||||
}
|
||||
|
||||
+// Tests that if the compositor sends wl_data_source.dnd_drop_performed with
|
||||
+// DND_ACTION_NONE, the drag controller treats it as a cancelled operation by
|
||||
+// calling OnDragLeave, and can still handle a subsequent
|
||||
+// wl_data_source.cancelled event gracefully. Regression test for
|
||||
+// https://crbug.com/447037092.
|
||||
+TEST_P(WaylandDataDragControllerTest,
|
||||
+ DndDropPerformedWithNoneActionThenCancelled) {
|
||||
+ FocusAndPressLeftPointerButton(window_.get(), &delegate_);
|
||||
+
|
||||
+ // Post test task to be performed asynchronously once the dnd-related protocol
|
||||
+ // objects are ready.
|
||||
+ ScheduleTestTask(base::BindLambdaForTesting([&]() {
|
||||
+ // Now the server can read the data and give it to our callback.
|
||||
+ ReadAndCheckData(kMimeTypeUtf8PlainText, kSampleTextForDragAndDrop);
|
||||
+
|
||||
+ EXPECT_CALL(*drop_handler_, OnDragLeave()).Times(1);
|
||||
+ SendDndDropPerformed();
|
||||
+
|
||||
+ // Emulate server sending an wl_data_source::cancelled event so the drag
|
||||
+ // loop is finished.
|
||||
+ EXPECT_CALL(*drop_handler_, OnDragLeave()).Times(0);
|
||||
+ SendDndCancelled();
|
||||
+ }));
|
||||
+
|
||||
+ RunMouseDragWithSampleData(window_.get(), DragDropTypes::DRAG_NONE);
|
||||
+
|
||||
+ // Ensure drag delegate it properly reset when the drag loop quits.
|
||||
+ EXPECT_FALSE(data_device()->drag_delegate_);
|
||||
+}
|
||||
+
|
||||
TEST_P(WaylandDataDragControllerTest, ReceiveDrag) {
|
||||
const uint32_t surface_id = window_->root_surface()->get_surface_id();
|
||||
|
||||
diff --git a/ui/ozone/platform/wayland/host/wayland_data_source.cc b/ui/ozone/platform/wayland/host/wayland_data_source.cc
|
||||
index 761f6a456456e11ad0e8c4dbe408c360de50f02d..f1b74febf52ecadef0da6574d50dfe3709ee48d7 100644
|
||||
--- a/ui/ozone/platform/wayland/host/wayland_data_source.cc
|
||||
+++ b/ui/ozone/platform/wayland/host/wayland_data_source.cc
|
||||
@@ -30,12 +30,12 @@ DataSource<T>::DataSource(T* data_source,
|
||||
DCHECK(delegate_);
|
||||
|
||||
Initialize();
|
||||
- VLOG(1) << "DataSoure created:" << this;
|
||||
+ VLOG(1) << "DataSource created:" << this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DataSource<T>::~DataSource() {
|
||||
- VLOG(1) << "DataSoure deleted:" << this;
|
||||
+ VLOG(1) << "DataSource deleted:" << this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -9,3 +9,4 @@ refactor_use_non-deprecated_nskeyedarchiver_apis.patch
|
||||
chore_turn_off_launchapplicationaturl_deprecation_errors_in_squirrel.patch
|
||||
fix_crash_when_process_to_extract_zip_cannot_be_launched.patch
|
||||
use_uttype_class_instead_of_deprecated_uttypeconformsto.patch
|
||||
fix_clean_up_old_staged_updates_before_downloading_new_update.patch
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Andy Locascio <loc@anthropic.com>
|
||||
Date: Tue, 6 Jan 2026 08:23:03 -0800
|
||||
Subject: fix: clean up old staged updates before downloading new update
|
||||
|
||||
When checkForUpdates() is called while an update is already staged,
|
||||
Squirrel creates a new temporary directory for the download without
|
||||
cleaning up the old one. This can lead to significant disk usage if
|
||||
the app keeps checking for updates without restarting.
|
||||
|
||||
This change adds a force parameter to pruneUpdateDirectories that
|
||||
bypasses the AwaitingRelaunch state check. This is called before
|
||||
creating a new temp directory, ensuring old staged updates are
|
||||
cleaned up when a new download starts.
|
||||
|
||||
diff --git a/Squirrel/SQRLUpdater.m b/Squirrel/SQRLUpdater.m
|
||||
index d156616e81e6f25a3bded30e6216b8fc311f31bc..6cd4346bf43b191147aff819cb93387e71275a46 100644
|
||||
--- a/Squirrel/SQRLUpdater.m
|
||||
+++ b/Squirrel/SQRLUpdater.m
|
||||
@@ -543,11 +543,17 @@ - (RACSignal *)downloadBundleForUpdate:(SQRLUpdate *)update intoDirectory:(NSURL
|
||||
#pragma mark File Management
|
||||
|
||||
- (RACSignal *)uniqueTemporaryDirectoryForUpdate {
|
||||
- return [[[RACSignal
|
||||
+ // Clean up any old staged update directories before creating a new one.
|
||||
+ // This prevents disk usage from growing when checkForUpdates() is called
|
||||
+ // multiple times without the app restarting.
|
||||
+ return [[[[[self
|
||||
+ pruneUpdateDirectoriesWithForce:YES]
|
||||
+ ignoreValues]
|
||||
+ concat:[RACSignal
|
||||
defer:^{
|
||||
SQRLDirectoryManager *directoryManager = [[SQRLDirectoryManager alloc] initWithApplicationIdentifier:SQRLShipItLauncher.shipItJobLabel];
|
||||
return [directoryManager storageURL];
|
||||
- }]
|
||||
+ }]]
|
||||
flattenMap:^(NSURL *storageURL) {
|
||||
NSURL *updateDirectoryTemplate = [storageURL URLByAppendingPathComponent:[SQRLUpdaterUniqueTemporaryDirectoryPrefix stringByAppendingString:@"XXXXXXX"]];
|
||||
char *updateDirectoryCString = strdup(updateDirectoryTemplate.path.fileSystemRepresentation);
|
||||
@@ -643,7 +649,7 @@ - (BOOL)isRunningOnReadOnlyVolume {
|
||||
|
||||
- (RACSignal *)performHousekeeping {
|
||||
return [[RACSignal
|
||||
- merge:@[ [self pruneUpdateDirectories], [self truncateLogs] ]]
|
||||
+ merge:@[ [self pruneUpdateDirectoriesWithForce:NO], [self truncateLogs] ]]
|
||||
catch:^(NSError *error) {
|
||||
NSLog(@"Error doing housekeeping: %@", error);
|
||||
return [RACSignal empty];
|
||||
@@ -658,11 +664,12 @@ - (RACSignal *)performHousekeeping {
|
||||
///
|
||||
/// Sends each removed directory then completes, or errors, on an unspecified
|
||||
/// thread.
|
||||
-- (RACSignal *)pruneUpdateDirectories {
|
||||
+- (RACSignal *)pruneUpdateDirectoriesWithForce:(BOOL)force {
|
||||
return [[[RACSignal
|
||||
defer:^{
|
||||
- // If we already have updates downloaded we don't wanna prune them.
|
||||
- if (self.state == SQRLUpdaterStateAwaitingRelaunch) return [RACSignal empty];
|
||||
+ // If we already have updates downloaded we don't wanna prune them,
|
||||
+ // unless force is YES (used when starting a new download).
|
||||
+ if (!force && self.state == SQRLUpdaterStateAwaitingRelaunch) return [RACSignal empty];
|
||||
|
||||
SQRLDirectoryManager *directoryManager = [[SQRLDirectoryManager alloc] initWithApplicationIdentifier:SQRLShipItLauncher.shipItJobLabel];
|
||||
return [directoryManager storageURL];
|
||||
@@ -11,14 +11,9 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
#include "base/task/task_traits.h"
|
||||
#include "base/task/thread_pool.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "shell/browser/browser.h"
|
||||
#include "shell/browser/javascript_environment.h"
|
||||
#include "shell/browser/native_window.h"
|
||||
#include "shell/browser/window_list.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
#include "shell/common/gin_helper/error_thrower.h"
|
||||
#include "shell/common/gin_helper/promise.h"
|
||||
@@ -33,16 +28,10 @@
|
||||
#include <windows.foundation.metadata.h>
|
||||
#include <windows.h>
|
||||
#include <windows.management.deployment.h>
|
||||
// Use pre-generated C++/WinRT headers from //third_party/nearby instead of the
|
||||
// SDK's cppwinrt headers, which are missing implementation files.
|
||||
#include "third_party/nearby/src/internal/platform/implementation/windows/generated/winrt/Windows.ApplicationModel.h"
|
||||
#include "third_party/nearby/src/internal/platform/implementation/windows/generated/winrt/Windows.Foundation.Collections.h"
|
||||
#include "third_party/nearby/src/internal/platform/implementation/windows/generated/winrt/Windows.Foundation.Metadata.h"
|
||||
#include "third_party/nearby/src/internal/platform/implementation/windows/generated/winrt/Windows.Foundation.h"
|
||||
#include "third_party/nearby/src/internal/platform/implementation/windows/generated/winrt/Windows.Management.Deployment.h"
|
||||
#include "third_party/nearby/src/internal/platform/implementation/windows/generated/winrt/base.h"
|
||||
#include <wrl.h>
|
||||
|
||||
#include "base/win/scoped_com_initializer.h"
|
||||
#include "base/win/core_winrt_util.h"
|
||||
#include "base/win/scoped_hstring.h"
|
||||
#endif
|
||||
|
||||
namespace electron {
|
||||
@@ -55,6 +44,53 @@ const bool debug_msix_updater =
|
||||
namespace {
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
|
||||
// Type aliases for cleaner code
|
||||
using ABI::Windows::ApplicationModel::IAppInstallerInfo;
|
||||
using ABI::Windows::ApplicationModel::IPackage;
|
||||
using ABI::Windows::ApplicationModel::IPackage2;
|
||||
using ABI::Windows::ApplicationModel::IPackage4;
|
||||
using ABI::Windows::ApplicationModel::IPackage6;
|
||||
using ABI::Windows::ApplicationModel::IPackageId;
|
||||
using ABI::Windows::ApplicationModel::IPackageStatics;
|
||||
using ABI::Windows::ApplicationModel::PackageSignatureKind;
|
||||
using ABI::Windows::ApplicationModel::PackageSignatureKind_Developer;
|
||||
using ABI::Windows::ApplicationModel::PackageSignatureKind_Enterprise;
|
||||
using ABI::Windows::ApplicationModel::PackageSignatureKind_None;
|
||||
using ABI::Windows::ApplicationModel::PackageSignatureKind_Store;
|
||||
using ABI::Windows::ApplicationModel::PackageSignatureKind_System;
|
||||
using ABI::Windows::Foundation::AsyncStatus;
|
||||
using ABI::Windows::Foundation::IAsyncInfo;
|
||||
using ABI::Windows::Foundation::IUriRuntimeClass;
|
||||
using ABI::Windows::Foundation::IUriRuntimeClassFactory;
|
||||
using ABI::Windows::Foundation::Metadata::IApiInformationStatics;
|
||||
using ABI::Windows::Management::Deployment::DeploymentOptions;
|
||||
using ABI::Windows::Management::Deployment::
|
||||
DeploymentOptions_ForceApplicationShutdown;
|
||||
using ABI::Windows::Management::Deployment::
|
||||
DeploymentOptions_ForceTargetApplicationShutdown;
|
||||
using ABI::Windows::Management::Deployment::
|
||||
DeploymentOptions_ForceUpdateFromAnyVersion;
|
||||
using ABI::Windows::Management::Deployment::DeploymentOptions_None;
|
||||
using ABI::Windows::Management::Deployment::IAddPackageOptions;
|
||||
using ABI::Windows::Management::Deployment::IDeploymentResult;
|
||||
using ABI::Windows::Management::Deployment::IPackageManager;
|
||||
using ABI::Windows::Management::Deployment::IPackageManager5;
|
||||
using ABI::Windows::Management::Deployment::IPackageManager9;
|
||||
using Microsoft::WRL::Callback;
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
// Type alias for deployment async operation
|
||||
// AddPackageByUriAsync returns IAsyncOperationWithProgress<DeploymentResult*,
|
||||
// DeploymentProgress>
|
||||
using DeploymentAsyncOp = ABI::Windows::Foundation::IAsyncOperationWithProgress<
|
||||
ABI::Windows::Management::Deployment::DeploymentResult*,
|
||||
ABI::Windows::Management::Deployment::DeploymentProgress>;
|
||||
using DeploymentCompletedHandler =
|
||||
ABI::Windows::Foundation::IAsyncOperationWithProgressCompletedHandler<
|
||||
ABI::Windows::Management::Deployment::DeploymentResult*,
|
||||
ABI::Windows::Management::Deployment::DeploymentProgress>;
|
||||
|
||||
// Helper function for debug logging
|
||||
void DebugLog(std::string_view log_msg) {
|
||||
if (electron::debug_msix_updater)
|
||||
@@ -84,32 +120,274 @@ struct RegisterPackageOptions {
|
||||
bool force_update_from_any_version = false;
|
||||
};
|
||||
|
||||
// Helper: Create PackageManager using RoActivateInstance
|
||||
//
|
||||
// Note on COM interface versioning: In COM/WinRT, each interface version
|
||||
// (IPackageManager, IPackageManager5, IPackageManager9, etc.) is a separate
|
||||
// interface that must be queried independently. Unlike C++ inheritance,
|
||||
// IPackageManager9 does NOT inherit methods from IPackageManager5 or the base
|
||||
// IPackageManager. Each version only contains the methods that were newly
|
||||
// added in that version. To call methods from different versions, you must
|
||||
// QueryInterface (or ComPtr::As) for each specific interface version needed.
|
||||
HRESULT CreatePackageManager(ComPtr<IPackageManager>* package_manager) {
|
||||
base::win::ScopedHString class_id = base::win::ScopedHString::Create(
|
||||
RuntimeClass_Windows_Management_Deployment_PackageManager);
|
||||
if (!class_id.is_valid()) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
ComPtr<IInspectable> inspectable;
|
||||
HRESULT hr = base::win::RoActivateInstance(class_id.get(), &inspectable);
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
return inspectable.As(package_manager);
|
||||
}
|
||||
|
||||
// Helper: Create URI using IUriRuntimeClassFactory
|
||||
HRESULT CreateUri(const std::wstring& uri_string,
|
||||
ComPtr<IUriRuntimeClass>* uri) {
|
||||
ComPtr<IUriRuntimeClassFactory> uri_factory;
|
||||
HRESULT hr =
|
||||
base::win::GetActivationFactory<IUriRuntimeClassFactory,
|
||||
RuntimeClass_Windows_Foundation_Uri>(
|
||||
&uri_factory);
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
base::win::ScopedHString uri_hstring =
|
||||
base::win::ScopedHString::Create(uri_string);
|
||||
if (!uri_hstring.is_valid()) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return uri_factory->CreateUri(uri_hstring.get(), uri->GetAddressOf());
|
||||
}
|
||||
|
||||
// Helper: Create and configure AddPackageOptions
|
||||
HRESULT CreateAddPackageOptions(const UpdateMsixOptions& opts,
|
||||
ComPtr<IAddPackageOptions>* package_options) {
|
||||
base::win::ScopedHString class_id = base::win::ScopedHString::Create(
|
||||
RuntimeClass_Windows_Management_Deployment_AddPackageOptions);
|
||||
if (!class_id.is_valid()) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
ComPtr<IInspectable> inspectable;
|
||||
HRESULT hr = base::win::RoActivateInstance(class_id.get(), &inspectable);
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = inspectable.As(package_options);
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
// Configure options using ABI interface methods
|
||||
(*package_options)
|
||||
->put_DeferRegistrationWhenPackagesAreInUse(opts.defer_registration);
|
||||
(*package_options)->put_DeveloperMode(opts.developer_mode);
|
||||
(*package_options)->put_ForceAppShutdown(opts.force_shutdown);
|
||||
(*package_options)->put_ForceTargetAppShutdown(opts.force_target_shutdown);
|
||||
(*package_options)
|
||||
->put_ForceUpdateFromAnyVersion(opts.force_update_from_any_version);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// Helper: Check if API contract is present
|
||||
HRESULT CheckApiContractPresent(UINT16 version, boolean* is_present) {
|
||||
ComPtr<IApiInformationStatics> api_info;
|
||||
HRESULT hr = base::win::GetActivationFactory<
|
||||
IApiInformationStatics,
|
||||
RuntimeClass_Windows_Foundation_Metadata_ApiInformation>(&api_info);
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
base::win::ScopedHString contract_name = base::win::ScopedHString::Create(
|
||||
L"Windows.Foundation.UniversalApiContract");
|
||||
if (!contract_name.is_valid()) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return api_info->IsApiContractPresentByMajor(contract_name.get(), version,
|
||||
is_present);
|
||||
}
|
||||
|
||||
// Helper: Get current package using IPackageStatics
|
||||
HRESULT GetCurrentPackage(ComPtr<IPackage>* package) {
|
||||
ComPtr<IPackageStatics> package_statics;
|
||||
HRESULT hr = base::win::GetActivationFactory<
|
||||
IPackageStatics, RuntimeClass_Windows_ApplicationModel_Package>(
|
||||
&package_statics);
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
return package_statics->get_Current(package->GetAddressOf());
|
||||
}
|
||||
|
||||
// Structure to hold callback data for async operations
|
||||
struct DeploymentCallbackData {
|
||||
scoped_refptr<base::SingleThreadTaskRunner> reply_runner;
|
||||
gin_helper::Promise<void> promise;
|
||||
bool fire_and_forget;
|
||||
ComPtr<DeploymentAsyncOp> async_op; // Keep async_op alive
|
||||
std::string operation_name; // "Deployment" or "Registration" for logs
|
||||
};
|
||||
|
||||
// Handler for deployment/registration completion
|
||||
void OnDeploymentCompleted(std::unique_ptr<DeploymentCallbackData> data,
|
||||
DeploymentAsyncOp* async_op,
|
||||
AsyncStatus status) {
|
||||
std::string error;
|
||||
const std::string& op_name = data->operation_name;
|
||||
|
||||
if (data->fire_and_forget) {
|
||||
std::ostringstream oss;
|
||||
oss << op_name
|
||||
<< " initiated. Force shutdown or target shutdown requested. "
|
||||
"Good bye!";
|
||||
DebugLog(oss.str());
|
||||
// Don't wait for result in fire-and-forget mode
|
||||
data->reply_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise) { promise.Resolve(); },
|
||||
std::move(data->promise)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (status == AsyncStatus::Error) {
|
||||
ComPtr<IDeploymentResult> result;
|
||||
HRESULT hr = async_op->GetResults(&result);
|
||||
if (SUCCEEDED(hr) && result) {
|
||||
HSTRING error_text_hstring;
|
||||
hr = result->get_ErrorText(&error_text_hstring);
|
||||
if (SUCCEEDED(hr)) {
|
||||
base::win::ScopedHString scoped_error(error_text_hstring);
|
||||
error = scoped_error.GetAsUTF8();
|
||||
}
|
||||
|
||||
ComPtr<IAsyncInfo> async_info;
|
||||
hr = async_op->QueryInterface(IID_PPV_ARGS(&async_info));
|
||||
if (SUCCEEDED(hr)) {
|
||||
HRESULT error_code;
|
||||
hr = async_info->get_ErrorCode(&error_code);
|
||||
if (SUCCEEDED(hr)) {
|
||||
error += " (" + std::to_string(static_cast<int>(error_code)) + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error.empty()) {
|
||||
error = op_name + " failed with unknown error";
|
||||
}
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << op_name << " failed: " << error;
|
||||
DebugLog(oss.str());
|
||||
}
|
||||
} else if (status == AsyncStatus::Canceled) {
|
||||
std::ostringstream oss;
|
||||
oss << op_name << " canceled";
|
||||
DebugLog(oss.str());
|
||||
error = op_name + " canceled";
|
||||
} else if (status == AsyncStatus::Completed) {
|
||||
std::ostringstream oss;
|
||||
oss << "MSIX " << op_name << " completed.";
|
||||
DebugLog(oss.str());
|
||||
} else {
|
||||
error = op_name + " status unknown";
|
||||
std::ostringstream oss;
|
||||
oss << op_name << " status unknown";
|
||||
DebugLog(oss.str());
|
||||
}
|
||||
|
||||
// Post result back to UI thread
|
||||
data->reply_runner->PostTask(
|
||||
FROM_HERE, base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
if (error.empty()) {
|
||||
promise.Resolve();
|
||||
} else {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
}
|
||||
},
|
||||
std::move(data->promise), std::move(error)));
|
||||
}
|
||||
|
||||
// Performs MSIX update on IO thread
|
||||
void DoUpdateMsix(const std::string& package_uri,
|
||||
UpdateMsixOptions opts,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> reply_runner,
|
||||
gin_helper::Promise<void> promise) {
|
||||
DebugLog("DoUpdateMsix: Starting");
|
||||
|
||||
using winrt::Windows::Foundation::AsyncStatus;
|
||||
using winrt::Windows::Foundation::Uri;
|
||||
using winrt::Windows::Management::Deployment::AddPackageOptions;
|
||||
using winrt::Windows::Management::Deployment::DeploymentResult;
|
||||
using winrt::Windows::Management::Deployment::PackageManager;
|
||||
|
||||
std::string error;
|
||||
std::wstring packageUriString =
|
||||
std::wstring(package_uri.begin(), package_uri.end());
|
||||
Uri uri{packageUriString};
|
||||
PackageManager packageManager;
|
||||
AddPackageOptions packageOptions;
|
||||
|
||||
// Use the pre-parsed options
|
||||
packageOptions.DeferRegistrationWhenPackagesAreInUse(opts.defer_registration);
|
||||
packageOptions.DeveloperMode(opts.developer_mode);
|
||||
packageOptions.ForceAppShutdown(opts.force_shutdown);
|
||||
packageOptions.ForceTargetAppShutdown(opts.force_target_shutdown);
|
||||
packageOptions.ForceUpdateFromAnyVersion(opts.force_update_from_any_version);
|
||||
// Create PackageManager
|
||||
ComPtr<IPackageManager> package_manager;
|
||||
HRESULT hr = CreatePackageManager(&package_manager);
|
||||
if (FAILED(hr)) {
|
||||
error = "Failed to create PackageManager";
|
||||
reply_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
},
|
||||
std::move(promise), std::move(error)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get IPackageManager9 for AddPackageByUriAsync
|
||||
ComPtr<IPackageManager9> package_manager9;
|
||||
hr = package_manager.As(&package_manager9);
|
||||
if (FAILED(hr)) {
|
||||
error = "Failed to get IPackageManager9 interface";
|
||||
reply_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
},
|
||||
std::move(promise), std::move(error)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create URI
|
||||
std::wstring uri_wstring = base::UTF8ToWide(package_uri);
|
||||
ComPtr<IUriRuntimeClass> uri;
|
||||
hr = CreateUri(uri_wstring, &uri);
|
||||
if (FAILED(hr)) {
|
||||
error = "Failed to create URI";
|
||||
reply_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
},
|
||||
std::move(promise), std::move(error)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create AddPackageOptions
|
||||
ComPtr<IAddPackageOptions> package_options;
|
||||
hr = CreateAddPackageOptions(opts, &package_options);
|
||||
if (FAILED(hr)) {
|
||||
error = "Failed to create AddPackageOptions";
|
||||
reply_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
},
|
||||
std::move(promise), std::move(error)));
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
@@ -127,63 +405,54 @@ void DoUpdateMsix(const std::string& package_uri,
|
||||
DebugLog(oss.str());
|
||||
}
|
||||
|
||||
auto deploymentOperation =
|
||||
packageManager.AddPackageByUriAsync(uri, packageOptions);
|
||||
|
||||
if (!deploymentOperation) {
|
||||
DebugLog("Deployment operation is null");
|
||||
// Start async operation
|
||||
ComPtr<DeploymentAsyncOp> async_op;
|
||||
hr = package_manager9->AddPackageByUriAsync(uri.Get(), package_options.Get(),
|
||||
&async_op);
|
||||
if (FAILED(hr) || !async_op) {
|
||||
DebugLog("AddPackageByUriAsync failed or returned null");
|
||||
error =
|
||||
"Deployment is NULL. See "
|
||||
"http://go.microsoft.com/fwlink/?LinkId=235160 for diagnosing.";
|
||||
} else {
|
||||
if (!opts.force_shutdown && !opts.force_target_shutdown) {
|
||||
DebugLog("Waiting for deployment...");
|
||||
deploymentOperation.get();
|
||||
DebugLog("Deployment finished.");
|
||||
|
||||
if (deploymentOperation.Status() == AsyncStatus::Error) {
|
||||
auto deploymentResult{deploymentOperation.GetResults()};
|
||||
std::string errorText = winrt::to_string(deploymentResult.ErrorText());
|
||||
std::string errorCode =
|
||||
std::to_string(static_cast<int>(deploymentOperation.ErrorCode()));
|
||||
error = errorText + " (" + errorCode + ")";
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Deployment failed: " << error;
|
||||
DebugLog(oss.str());
|
||||
}
|
||||
} else if (deploymentOperation.Status() == AsyncStatus::Canceled) {
|
||||
DebugLog("Deployment canceled");
|
||||
error = "Deployment canceled";
|
||||
} else if (deploymentOperation.Status() == AsyncStatus::Completed) {
|
||||
DebugLog("MSIX Deployment completed.");
|
||||
} else {
|
||||
error = "Deployment status unknown";
|
||||
DebugLog("Deployment status unknown");
|
||||
}
|
||||
} else {
|
||||
// At this point, we can not await the deployment because we require a
|
||||
// shutdown of the app to continue, so we do a fire and forget. When the
|
||||
// deployment process tries ot shutdown the app, the process waits for us
|
||||
// to finish here. But to finish we need to shutdow. That leads to a 30s
|
||||
// dealock, till we forcefully get shutdown by the OS.
|
||||
DebugLog(
|
||||
"Deployment initiated. Force shutdown or target shutdown requested. "
|
||||
"Good bye!");
|
||||
}
|
||||
reply_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
},
|
||||
std::move(promise), std::move(error)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Post result back
|
||||
reply_runner->PostTask(
|
||||
FROM_HERE, base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
if (error.empty()) {
|
||||
promise.Resolve();
|
||||
} else {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
}
|
||||
},
|
||||
std::move(promise), error));
|
||||
// Set up callback data
|
||||
auto callback_data = std::make_unique<DeploymentCallbackData>();
|
||||
callback_data->reply_runner = reply_runner;
|
||||
callback_data->promise = std::move(promise);
|
||||
callback_data->fire_and_forget =
|
||||
opts.force_shutdown || opts.force_target_shutdown;
|
||||
callback_data->async_op = async_op; // Keep async_op alive
|
||||
callback_data->operation_name = "Deployment";
|
||||
|
||||
// Register completion handler
|
||||
DeploymentCallbackData* raw_data = callback_data.get();
|
||||
hr = async_op->put_Completed(
|
||||
Callback<DeploymentCompletedHandler>([data = std::move(callback_data)](
|
||||
DeploymentAsyncOp* op,
|
||||
AsyncStatus status) mutable {
|
||||
OnDeploymentCompleted(std::move(data), op, status);
|
||||
return S_OK;
|
||||
}).Get());
|
||||
|
||||
if (FAILED(hr)) {
|
||||
DebugLog("Failed to register completion handler");
|
||||
raw_data->reply_runner->PostTask(
|
||||
FROM_HERE, base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise) {
|
||||
promise.RejectWithErrorMessage(
|
||||
"Failed to register completion handler");
|
||||
},
|
||||
std::move(raw_data->promise)));
|
||||
}
|
||||
}
|
||||
|
||||
// Performs package registration on IO thread
|
||||
@@ -192,31 +461,67 @@ void DoRegisterPackage(const std::string& family_name,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> reply_runner,
|
||||
gin_helper::Promise<void> promise) {
|
||||
DebugLog("DoRegisterPackage: Starting");
|
||||
|
||||
using winrt::Windows::Foundation::AsyncStatus;
|
||||
using winrt::Windows::Foundation::Collections::IIterable;
|
||||
using winrt::Windows::Management::Deployment::DeploymentOptions;
|
||||
using winrt::Windows::Management::Deployment::PackageManager;
|
||||
|
||||
std::string error;
|
||||
auto familyNameH = winrt::to_hstring(family_name);
|
||||
PackageManager packageManager;
|
||||
DeploymentOptions deploymentOptions = DeploymentOptions::None;
|
||||
|
||||
// Use the pre-parsed options (no V8 access needed)
|
||||
// Create PackageManager
|
||||
ComPtr<IPackageManager> package_manager;
|
||||
HRESULT hr = CreatePackageManager(&package_manager);
|
||||
if (FAILED(hr)) {
|
||||
error = "Failed to create PackageManager";
|
||||
reply_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
},
|
||||
std::move(promise), std::move(error)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get IPackageManager5 for RegisterPackageByFamilyNameAsync
|
||||
ComPtr<IPackageManager5> package_manager5;
|
||||
hr = package_manager.As(&package_manager5);
|
||||
if (FAILED(hr)) {
|
||||
error = "Failed to get IPackageManager5 interface";
|
||||
reply_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
},
|
||||
std::move(promise), std::move(error)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Build DeploymentOptions flags
|
||||
DeploymentOptions deployment_options = DeploymentOptions_None;
|
||||
if (opts.force_shutdown) {
|
||||
deploymentOptions |= DeploymentOptions::ForceApplicationShutdown;
|
||||
deployment_options = static_cast<DeploymentOptions>(
|
||||
deployment_options | DeploymentOptions_ForceApplicationShutdown);
|
||||
}
|
||||
if (opts.force_target_shutdown) {
|
||||
deploymentOptions |= DeploymentOptions::ForceTargetApplicationShutdown;
|
||||
deployment_options = static_cast<DeploymentOptions>(
|
||||
deployment_options | DeploymentOptions_ForceTargetApplicationShutdown);
|
||||
}
|
||||
if (opts.force_update_from_any_version) {
|
||||
deploymentOptions |= DeploymentOptions::ForceUpdateFromAnyVersion;
|
||||
deployment_options = static_cast<DeploymentOptions>(
|
||||
deployment_options | DeploymentOptions_ForceUpdateFromAnyVersion);
|
||||
}
|
||||
|
||||
// Create empty collections for dependency and optional packages
|
||||
IIterable<winrt::hstring> emptyDependencies{nullptr};
|
||||
IIterable<winrt::hstring> emptyOptional{nullptr};
|
||||
// Create HSTRING for family name
|
||||
base::win::ScopedHString family_name_hstring =
|
||||
base::win::ScopedHString::Create(family_name);
|
||||
if (!family_name_hstring.is_valid()) {
|
||||
error = "Failed to create family name string";
|
||||
reply_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
},
|
||||
std::move(promise), std::move(error)));
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
@@ -233,63 +538,59 @@ void DoRegisterPackage(const std::string& family_name,
|
||||
DebugLog(oss.str());
|
||||
}
|
||||
|
||||
auto deploymentOperation = packageManager.RegisterPackageByFamilyNameAsync(
|
||||
familyNameH, emptyDependencies, deploymentOptions, nullptr,
|
||||
emptyOptional);
|
||||
// RegisterPackageByFamilyNameAndOptionalPackagesAsync (ABI name)
|
||||
ComPtr<DeploymentAsyncOp> async_op;
|
||||
hr = package_manager5->RegisterPackageByFamilyNameAndOptionalPackagesAsync(
|
||||
family_name_hstring.get(),
|
||||
nullptr, // dependencyPackageFamilyNames
|
||||
deployment_options,
|
||||
nullptr, // appDataVolume
|
||||
nullptr, // optionalPackageFamilyNames
|
||||
&async_op);
|
||||
|
||||
if (!deploymentOperation) {
|
||||
if (FAILED(hr) || !async_op) {
|
||||
error =
|
||||
"Deployment is NULL. See "
|
||||
"http://go.microsoft.com/fwlink/?LinkId=235160 for diagnosing.";
|
||||
} else {
|
||||
if (!opts.force_shutdown && !opts.force_target_shutdown) {
|
||||
DebugLog("Waiting for registration...");
|
||||
deploymentOperation.get();
|
||||
DebugLog("Registration finished.");
|
||||
|
||||
if (deploymentOperation.Status() == AsyncStatus::Error) {
|
||||
auto deploymentResult{deploymentOperation.GetResults()};
|
||||
std::string errorText = winrt::to_string(deploymentResult.ErrorText());
|
||||
std::string errorCode =
|
||||
std::to_string(static_cast<int>(deploymentOperation.ErrorCode()));
|
||||
error = errorText + " (" + errorCode + ")";
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Registration failed: " << error;
|
||||
DebugLog(oss.str());
|
||||
}
|
||||
} else if (deploymentOperation.Status() == AsyncStatus::Canceled) {
|
||||
DebugLog("Registration canceled");
|
||||
error = "Registration canceled";
|
||||
} else if (deploymentOperation.Status() == AsyncStatus::Completed) {
|
||||
DebugLog("MSIX Registration completed.");
|
||||
} else {
|
||||
error = "Registration status unknown";
|
||||
DebugLog("Registration status unknown");
|
||||
}
|
||||
} else {
|
||||
// At this point, we can not await the registration because we require a
|
||||
// shutdown of the app to continue, so we do a fire and forget. When the
|
||||
// registration process tries ot shutdown the app, the process waits for
|
||||
// us to finish here. But to finish we need to shutdown. That leads to a
|
||||
// 30s dealock, till we forcefully get shutdown by the OS.
|
||||
DebugLog(
|
||||
"Registration initiated. Force shutdown or target shutdown "
|
||||
"requested. Good bye!");
|
||||
}
|
||||
reply_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
},
|
||||
std::move(promise), std::move(error)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Post result back to UI thread
|
||||
reply_runner->PostTask(
|
||||
FROM_HERE, base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise, std::string error) {
|
||||
if (error.empty()) {
|
||||
promise.Resolve();
|
||||
} else {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
}
|
||||
},
|
||||
std::move(promise), error));
|
||||
// Set up callback data
|
||||
auto callback_data = std::make_unique<DeploymentCallbackData>();
|
||||
callback_data->reply_runner = reply_runner;
|
||||
callback_data->promise = std::move(promise);
|
||||
callback_data->fire_and_forget =
|
||||
opts.force_shutdown || opts.force_target_shutdown;
|
||||
callback_data->async_op = async_op; // Keep async_op alive
|
||||
callback_data->operation_name = "Registration";
|
||||
|
||||
// Register completion handler
|
||||
DeploymentCallbackData* raw_data = callback_data.get();
|
||||
hr = async_op->put_Completed(
|
||||
Callback<DeploymentCompletedHandler>([data = std::move(callback_data)](
|
||||
DeploymentAsyncOp* op,
|
||||
AsyncStatus status) mutable {
|
||||
OnDeploymentCompleted(std::move(data), op, status);
|
||||
return S_OK;
|
||||
}).Get());
|
||||
|
||||
if (FAILED(hr)) {
|
||||
DebugLog("Failed to register completion handler");
|
||||
raw_data->reply_runner->PostTask(
|
||||
FROM_HERE, base::BindOnce(
|
||||
[](gin_helper::Promise<void> promise) {
|
||||
promise.RejectWithErrorMessage(
|
||||
"Failed to register completion handler");
|
||||
},
|
||||
std::move(raw_data->promise)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -307,6 +608,16 @@ v8::Local<v8::Promise> UpdateMsix(const std::string& package_uri,
|
||||
return handle;
|
||||
}
|
||||
|
||||
// Check for required API contract (IPackageManager9 requires v10)
|
||||
boolean is_api_present = FALSE;
|
||||
if (FAILED(CheckApiContractPresent(10, &is_api_present)) || !is_api_present) {
|
||||
DebugLog("UpdateMsix: Required Windows API contract not present");
|
||||
promise.RejectWithErrorMessage(
|
||||
"This Windows version does not support MSIX updates via this API. "
|
||||
"Windows 10 version 2004 or later is required.");
|
||||
return handle;
|
||||
}
|
||||
|
||||
// Parse options on UI thread (where V8 is available)
|
||||
UpdateMsixOptions opts;
|
||||
options.Get("deferRegistration", &opts.defer_registration);
|
||||
@@ -349,6 +660,16 @@ v8::Local<v8::Promise> RegisterPackage(const std::string& family_name,
|
||||
return handle;
|
||||
}
|
||||
|
||||
// Check for required API contract (IPackageManager5 requires v3)
|
||||
boolean is_api_present = FALSE;
|
||||
if (FAILED(CheckApiContractPresent(3, &is_api_present)) || !is_api_present) {
|
||||
DebugLog("RegisterPackage: Required Windows API contract not present");
|
||||
promise.RejectWithErrorMessage(
|
||||
"This Windows version does not support package registration via this "
|
||||
"API. Windows 10 version 1607 or later is required.");
|
||||
return handle;
|
||||
}
|
||||
|
||||
// Parse options on UI thread (where V8 is available)
|
||||
RegisterPackageOptions opts;
|
||||
options.Get("forceShutdown", &opts.force_shutdown);
|
||||
@@ -384,32 +705,30 @@ bool RegisterRestartOnUpdate(const std::string& command_line) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const wchar_t* commandLine = nullptr;
|
||||
// Flags: RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_REBOOT
|
||||
// This means: only restart on updates (RESTART_NO_PATCH is NOT set)
|
||||
const DWORD dwFlags = 1 | 2 | 8; // 11
|
||||
|
||||
// Convert command line to wide string (keep in scope for API call)
|
||||
std::wstring command_line_wide;
|
||||
const wchar_t* command_line_ptr = nullptr;
|
||||
if (!command_line.empty()) {
|
||||
std::wstring commandLineW =
|
||||
std::wstring(command_line.begin(), command_line.end());
|
||||
commandLine = commandLineW.c_str();
|
||||
command_line_wide = base::UTF8ToWide(command_line);
|
||||
command_line_ptr = command_line_wide.c_str();
|
||||
}
|
||||
|
||||
HRESULT hr = RegisterApplicationRestart(commandLine, dwFlags);
|
||||
HRESULT hr = RegisterApplicationRestart(command_line_ptr, dwFlags);
|
||||
if (FAILED(hr)) {
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "RegisterApplicationRestart failed with error code: " << hr;
|
||||
DebugLog(oss.str());
|
||||
}
|
||||
std::ostringstream oss;
|
||||
oss << "RegisterApplicationRestart failed with error code: " << hr;
|
||||
DebugLog(oss.str());
|
||||
return false;
|
||||
}
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "RegisterApplicationRestart succeeded"
|
||||
<< (command_line.empty() ? "" : " with command line");
|
||||
DebugLog(oss.str());
|
||||
}
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "RegisterApplicationRestart succeeded"
|
||||
<< (command_line.empty() ? "" : " with command line");
|
||||
DebugLog(oss.str());
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
@@ -434,57 +753,119 @@ v8::Local<v8::Value> GetPackageInfo() {
|
||||
gin_helper::Dictionary result(isolate, v8::Object::New(isolate));
|
||||
|
||||
// Check API contract version (Windows 10 version 1703 or later)
|
||||
if (winrt::Windows::Foundation::Metadata::ApiInformation::
|
||||
IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", 7)) {
|
||||
using winrt::Windows::ApplicationModel::Package;
|
||||
using winrt::Windows::ApplicationModel::PackageSignatureKind;
|
||||
Package package = Package::Current();
|
||||
boolean is_present = FALSE;
|
||||
HRESULT hr = CheckApiContractPresent(7, &is_present);
|
||||
if (SUCCEEDED(hr) && is_present) {
|
||||
ComPtr<IPackage> package;
|
||||
hr = GetCurrentPackage(&package);
|
||||
if (SUCCEEDED(hr) && package) {
|
||||
// Query all needed package interface versions upfront.
|
||||
// Note: Like IPackageManager, each IPackage version (IPackage2,
|
||||
// IPackage4, IPackage6) is a separate COM interface. IPackage6 does NOT
|
||||
// inherit methods from earlier versions. We must query each version
|
||||
// separately to access its specific methods:
|
||||
// - IPackage2: get_IsDevelopmentMode
|
||||
// - IPackage4: get_SignatureKind
|
||||
// - IPackage6: GetAppInstallerInfo
|
||||
ComPtr<IPackage2> package2;
|
||||
ComPtr<IPackage4> package4;
|
||||
ComPtr<IPackage6> package6;
|
||||
package.As(&package2);
|
||||
package.As(&package4);
|
||||
package.As(&package6);
|
||||
|
||||
// Get package ID and family name
|
||||
std::string packageId = winrt::to_string(package.Id().FullName());
|
||||
std::string familyName = winrt::to_string(package.Id().FamilyName());
|
||||
// Get package ID (from base IPackage)
|
||||
ComPtr<IPackageId> package_id;
|
||||
hr = package->get_Id(&package_id);
|
||||
if (SUCCEEDED(hr) && package_id) {
|
||||
// Get FullName
|
||||
HSTRING full_name;
|
||||
hr = package_id->get_FullName(&full_name);
|
||||
if (SUCCEEDED(hr)) {
|
||||
base::win::ScopedHString scoped_name(full_name);
|
||||
result.Set("id", scoped_name.GetAsUTF8());
|
||||
}
|
||||
|
||||
result.Set("id", packageId);
|
||||
result.Set("familyName", familyName);
|
||||
result.Set("developmentMode", package.IsDevelopmentMode());
|
||||
// Get FamilyName
|
||||
HSTRING family_name;
|
||||
hr = package_id->get_FamilyName(&family_name);
|
||||
if (SUCCEEDED(hr)) {
|
||||
base::win::ScopedHString scoped_name(family_name);
|
||||
result.Set("familyName", scoped_name.GetAsUTF8());
|
||||
}
|
||||
|
||||
// Get package version
|
||||
auto packageVersion = package.Id().Version();
|
||||
std::string version = std::to_string(packageVersion.Major) + "." +
|
||||
std::to_string(packageVersion.Minor) + "." +
|
||||
std::to_string(packageVersion.Build) + "." +
|
||||
std::to_string(packageVersion.Revision);
|
||||
result.Set("version", version);
|
||||
// Get Version
|
||||
ABI::Windows::ApplicationModel::PackageVersion pkg_version;
|
||||
hr = package_id->get_Version(&pkg_version);
|
||||
if (SUCCEEDED(hr)) {
|
||||
std::string version = std::to_string(pkg_version.Major) + "." +
|
||||
std::to_string(pkg_version.Minor) + "." +
|
||||
std::to_string(pkg_version.Build) + "." +
|
||||
std::to_string(pkg_version.Revision);
|
||||
result.Set("version", version);
|
||||
}
|
||||
}
|
||||
|
||||
// Convert signature kind to string
|
||||
std::string signatureKind;
|
||||
switch (package.SignatureKind()) {
|
||||
case PackageSignatureKind::Developer:
|
||||
signatureKind = "developer";
|
||||
break;
|
||||
case PackageSignatureKind::Enterprise:
|
||||
signatureKind = "enterprise";
|
||||
break;
|
||||
case PackageSignatureKind::None:
|
||||
signatureKind = "none";
|
||||
break;
|
||||
case PackageSignatureKind::Store:
|
||||
signatureKind = "store";
|
||||
break;
|
||||
case PackageSignatureKind::System:
|
||||
signatureKind = "system";
|
||||
break;
|
||||
default:
|
||||
signatureKind = "none";
|
||||
break;
|
||||
}
|
||||
result.Set("signatureKind", signatureKind);
|
||||
// Get IsDevelopmentMode (from IPackage2)
|
||||
if (package2) {
|
||||
boolean is_dev_mode = FALSE;
|
||||
hr = package2->get_IsDevelopmentMode(&is_dev_mode);
|
||||
result.Set("developmentMode", SUCCEEDED(hr) && is_dev_mode != FALSE);
|
||||
} else {
|
||||
result.Set("developmentMode", false);
|
||||
}
|
||||
|
||||
// Get app installer info if available
|
||||
auto appInstallerInfo = package.GetAppInstallerInfo();
|
||||
if (appInstallerInfo != nullptr) {
|
||||
std::string uriStr = winrt::to_string(appInstallerInfo.Uri().ToString());
|
||||
result.Set("appInstallerUri", uriStr);
|
||||
// Get SignatureKind (from IPackage4)
|
||||
if (package4) {
|
||||
PackageSignatureKind sig_kind;
|
||||
hr = package4->get_SignatureKind(&sig_kind);
|
||||
if (SUCCEEDED(hr)) {
|
||||
std::string signature_kind;
|
||||
switch (sig_kind) {
|
||||
case PackageSignatureKind_Developer:
|
||||
signature_kind = "developer";
|
||||
break;
|
||||
case PackageSignatureKind_Enterprise:
|
||||
signature_kind = "enterprise";
|
||||
break;
|
||||
case PackageSignatureKind_None:
|
||||
signature_kind = "none";
|
||||
break;
|
||||
case PackageSignatureKind_Store:
|
||||
signature_kind = "store";
|
||||
break;
|
||||
case PackageSignatureKind_System:
|
||||
signature_kind = "system";
|
||||
break;
|
||||
default:
|
||||
signature_kind = "none";
|
||||
break;
|
||||
}
|
||||
result.Set("signatureKind", signature_kind);
|
||||
} else {
|
||||
result.Set("signatureKind", "none");
|
||||
}
|
||||
} else {
|
||||
result.Set("signatureKind", "none");
|
||||
}
|
||||
|
||||
// Get AppInstallerInfo (from IPackage6)
|
||||
if (package6) {
|
||||
ComPtr<IAppInstallerInfo> app_installer_info;
|
||||
hr = package6->GetAppInstallerInfo(&app_installer_info);
|
||||
if (SUCCEEDED(hr) && app_installer_info) {
|
||||
ComPtr<IUriRuntimeClass> uri;
|
||||
hr = app_installer_info->get_Uri(&uri);
|
||||
if (SUCCEEDED(hr) && uri) {
|
||||
HSTRING uri_string;
|
||||
hr = uri->get_AbsoluteUri(&uri_string);
|
||||
if (SUCCEEDED(hr)) {
|
||||
base::win::ScopedHString scoped_uri(uri_string);
|
||||
result.Set("appInstallerUri", scoped_uri.GetAsUTF8());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Windows version doesn't meet minimum API requirements
|
||||
|
||||
@@ -400,31 +400,47 @@ class FileSystemAccessPermissionContext::PermissionGrantImpl
|
||||
}
|
||||
}
|
||||
|
||||
// Updates the in-memory permission grant for the `new_path` in the `grants`
|
||||
// map using the same grant from the `old_path`, and removes the grant entry
|
||||
// for the `old_path`.
|
||||
// If `allow_overwrite` is true, this will replace any pre-existing grant at
|
||||
// `new_path`.
|
||||
static void UpdateGrantPath(
|
||||
std::map<base::FilePath, PermissionGrantImpl*>& grants,
|
||||
const content::PathInfo& old_path,
|
||||
const content::PathInfo& new_path) {
|
||||
const content::PathInfo& new_path,
|
||||
bool allow_overwrite) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
auto entry_it =
|
||||
auto old_path_it =
|
||||
std::ranges::find_if(grants, [&old_path](const auto& entry) {
|
||||
return entry.first == old_path.path;
|
||||
});
|
||||
|
||||
if (entry_it == grants.end()) {
|
||||
// There must be an entry for an ancestor of this entry. Nothing to do
|
||||
// here.
|
||||
if (old_path_it == grants.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK_EQ(entry_it->second->GetActivePermissionStatus(),
|
||||
DCHECK_EQ(old_path_it->second->GetActivePermissionStatus(),
|
||||
PermissionStatus::GRANTED);
|
||||
|
||||
auto* const grant_impl = entry_it->second;
|
||||
grant_impl->SetPath(new_path);
|
||||
auto* const grant_to_move = old_path_it->second;
|
||||
|
||||
// Update the permission grant's key in the map of active permissions.
|
||||
grants.erase(entry_it);
|
||||
grants.emplace(new_path.path, grant_impl);
|
||||
// See https://chromium-review.googlesource.com/4803165
|
||||
if (allow_overwrite) {
|
||||
auto new_path_it = grants.find(new_path.path);
|
||||
if (new_path_it != grants.end() && new_path_it->second != grant_to_move) {
|
||||
new_path_it->second->SetStatus(PermissionStatus::DENIED);
|
||||
}
|
||||
}
|
||||
|
||||
grant_to_move->SetPath(new_path);
|
||||
|
||||
grants.erase(old_path_it);
|
||||
if (allow_overwrite) {
|
||||
grants.insert_or_assign(new_path.path, grant_to_move);
|
||||
} else {
|
||||
grants.emplace(new_path.path, grant_to_move);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -930,12 +946,17 @@ void FileSystemAccessPermissionContext::NotifyEntryMoved(
|
||||
return;
|
||||
}
|
||||
|
||||
// It's possible `new_path` already has existing persistent permission.
|
||||
// See crbug.com/423663220.
|
||||
bool allow_overwrite = base::FeatureList::IsEnabled(
|
||||
features::kFileSystemAccessMoveWithOverwrite);
|
||||
|
||||
auto it = active_permissions_map_.find(origin);
|
||||
if (it != active_permissions_map_.end()) {
|
||||
PermissionGrantImpl::UpdateGrantPath(it->second.write_grants, old_path,
|
||||
new_path);
|
||||
new_path, allow_overwrite);
|
||||
PermissionGrantImpl::UpdateGrantPath(it->second.read_grants, old_path,
|
||||
new_path);
|
||||
new_path, allow_overwrite);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,14 @@ static NSDictionary* UNNotificationResponseToNSDictionary(
|
||||
}
|
||||
|
||||
- (NSMenu*)applicationDockMenu:(NSApplication*)sender {
|
||||
return menu_controller_ ? menu_controller_.menu : nil;
|
||||
if (!menu_controller_)
|
||||
return nil;
|
||||
|
||||
// Manually refresh menu state since menuWillOpen: is not called
|
||||
// by macOS for dock menus for some reason before they are displayed.
|
||||
NSMenu* menu = menu_controller_.menu;
|
||||
[menu_controller_ refreshMenuTree:menu];
|
||||
return menu;
|
||||
}
|
||||
|
||||
- (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename {
|
||||
|
||||
@@ -57,6 +57,10 @@ class ElectronMenuModel;
|
||||
// Whether the menu is currently open.
|
||||
- (BOOL)isMenuOpen;
|
||||
|
||||
// Recursively refreshes the menu tree starting from |menu|, applying the
|
||||
// model state (enabled, checked, hidden etc) to each menu item.
|
||||
- (void)refreshMenuTree:(NSMenu*)menu;
|
||||
|
||||
// NSMenuDelegate methods this class implements. Subclasses should call super
|
||||
// if extending the behavior.
|
||||
- (void)menuWillOpen:(NSMenu*)menu;
|
||||
|
||||
@@ -493,8 +493,6 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) {
|
||||
: NSControlStateValueOff;
|
||||
}
|
||||
|
||||
// Recursively refreshes the menu tree starting from |menu|, applying the
|
||||
// model state to each menu item.
|
||||
- (void)refreshMenuTree:(NSMenu*)menu {
|
||||
for (NSMenuItem* item in menu.itemArray) {
|
||||
[self applyStateToMenuItem:item];
|
||||
|
||||
@@ -150,6 +150,31 @@ bool ElectronDesktopWindowTreeHostWin::HandleMouseEvent(ui::MouseEvent* event) {
|
||||
return views::DesktopWindowTreeHostWin::HandleMouseEvent(event);
|
||||
}
|
||||
|
||||
bool ElectronDesktopWindowTreeHostWin::HandleIMEMessage(UINT message,
|
||||
WPARAM w_param,
|
||||
LPARAM l_param,
|
||||
LRESULT* result) {
|
||||
if ((message == WM_SYSCHAR) && (w_param == VK_SPACE)) {
|
||||
if (native_window_view_->widget() &&
|
||||
native_window_view_->widget()->non_client_view()) {
|
||||
const auto* frame =
|
||||
native_window_view_->widget()->non_client_view()->frame_view();
|
||||
auto location = frame->GetSystemMenuScreenPixelLocation();
|
||||
|
||||
bool prevent_default = false;
|
||||
native_window_view_->NotifyWindowSystemContextMenu(
|
||||
location.x(), location.y(), &prevent_default);
|
||||
|
||||
return prevent_default ||
|
||||
views::DesktopWindowTreeHostWin::HandleIMEMessage(message, w_param,
|
||||
l_param, result);
|
||||
}
|
||||
}
|
||||
|
||||
return views::DesktopWindowTreeHostWin::HandleIMEMessage(message, w_param,
|
||||
l_param, result);
|
||||
}
|
||||
|
||||
void ElectronDesktopWindowTreeHostWin::HandleVisibilityChanged(bool visible) {
|
||||
if (native_window_view_->widget())
|
||||
native_window_view_->widget()->OnNativeWidgetVisibilityChanged(visible);
|
||||
|
||||
@@ -44,6 +44,10 @@ class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin,
|
||||
int frame_thickness) const override;
|
||||
bool HandleMouseEventForCaption(UINT message) const override;
|
||||
bool HandleMouseEvent(ui::MouseEvent* event) override;
|
||||
bool HandleIMEMessage(UINT message,
|
||||
WPARAM w_param,
|
||||
LPARAM l_param,
|
||||
LRESULT* result) override;
|
||||
void HandleVisibilityChanged(bool visible) override;
|
||||
void SetAllowScreenshots(bool allow) override;
|
||||
|
||||
|
||||
@@ -106,7 +106,10 @@ bool ProcessSignatureIsSameWithCurrentApp(pid_t pid) {
|
||||
status = SecCodeCheckValidity(process_code.get(), kSecCSDefaultFlags,
|
||||
self_requirement.get());
|
||||
if (status != errSecSuccess && status != errSecCSReqFailed) {
|
||||
OSSTATUS_LOG(ERROR, status) << "SecCodeCheckValidity";
|
||||
// If the code is unsigned, don't log that (it's not an actual error).
|
||||
if (status != errSecCSUnsigned) {
|
||||
OSSTATUS_LOG(ERROR, status) << "SecCodeCheckValidity";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return status == errSecSuccess;
|
||||
|
||||
@@ -9,6 +9,7 @@ import * as cp from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as http from 'node:http';
|
||||
import { AddressInfo } from 'node:net';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
|
||||
import { copyMacOSFixtureApp, getCodesignIdentity, shouldRunCodesignTests, signApp, spawn } from './lib/codesign-helpers';
|
||||
@@ -67,6 +68,38 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
|
||||
}
|
||||
};
|
||||
|
||||
// Squirrel stores update directories in ~/Library/Caches/com.github.Electron.ShipIt/
|
||||
// as subdirectories named like update.XXXXXXX
|
||||
const getSquirrelCacheDirectory = () => {
|
||||
return path.join(os.homedir(), 'Library', 'Caches', 'com.github.Electron.ShipIt');
|
||||
};
|
||||
|
||||
const getUpdateDirectoriesInCache = async () => {
|
||||
const cacheDir = getSquirrelCacheDirectory();
|
||||
try {
|
||||
const entries = await fs.promises.readdir(cacheDir, { withFileTypes: true });
|
||||
return entries
|
||||
.filter(entry => entry.isDirectory() && entry.name.startsWith('update.'))
|
||||
.map(entry => path.join(cacheDir, entry.name));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const cleanSquirrelCache = async () => {
|
||||
const cacheDir = getSquirrelCacheDirectory();
|
||||
try {
|
||||
const entries = await fs.promises.readdir(cacheDir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
if (entry.isDirectory() && entry.name.startsWith('update.')) {
|
||||
await fs.promises.rm(path.join(cacheDir, entry.name), { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Cache dir may not exist yet
|
||||
}
|
||||
};
|
||||
|
||||
const cachedZips: Record<string, string> = {};
|
||||
|
||||
type Mutation = {
|
||||
@@ -340,6 +373,67 @@ ifdescribe(shouldRunCodesignTests)('autoUpdater behavior', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should clean up old staged update directories when a new update is downloaded', async () => {
|
||||
// Clean up any existing update directories before the test
|
||||
await cleanSquirrelCache();
|
||||
|
||||
await withUpdatableApp({
|
||||
nextVersion: '2.0.0',
|
||||
startFixture: 'update-stack',
|
||||
endFixture: 'update-stack'
|
||||
}, async (appPath, updateZipPath2) => {
|
||||
await withUpdatableApp({
|
||||
nextVersion: '3.0.0',
|
||||
startFixture: 'update-stack',
|
||||
endFixture: 'update-stack'
|
||||
}, async (_, updateZipPath3) => {
|
||||
let updateCount = 0;
|
||||
let downloadCount = 0;
|
||||
let directoriesDuringSecondDownload: string[] = [];
|
||||
|
||||
server.get('/update-file', async (req, res) => {
|
||||
downloadCount++;
|
||||
// When the second download request arrives, Squirrel has already
|
||||
// called uniqueTemporaryDirectoryForUpdate which (with our patch)
|
||||
// cleans up old directories before creating the new one.
|
||||
// Without the patch, both directories would exist at this point.
|
||||
if (downloadCount === 2) {
|
||||
directoriesDuringSecondDownload = await getUpdateDirectoriesInCache();
|
||||
}
|
||||
res.download(updateCount > 1 ? updateZipPath3 : updateZipPath2);
|
||||
});
|
||||
server.get('/update-check', (req, res) => {
|
||||
updateCount++;
|
||||
res.json({
|
||||
url: `http://localhost:${port}/update-file`,
|
||||
name: 'My Release Name',
|
||||
notes: 'Theses are some release notes innit',
|
||||
pub_date: (new Date()).toString()
|
||||
});
|
||||
});
|
||||
const relaunchPromise = new Promise<void>((resolve) => {
|
||||
server.get('/update-check/updated/:version', (req, res) => {
|
||||
res.status(204).send();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
const launchResult = await launchApp(appPath, [`http://localhost:${port}/update-check`]);
|
||||
logOnError(launchResult, () => {
|
||||
expect(launchResult).to.have.property('code', 0);
|
||||
expect(launchResult.out).to.include('Update Downloaded');
|
||||
});
|
||||
|
||||
await relaunchPromise;
|
||||
|
||||
// During the second download, the old staged update directory should
|
||||
// have been cleaned up. With our patch, there should be exactly 1
|
||||
// directory (the new one). Without the patch, there would be 2.
|
||||
expect(directoriesDuringSecondDownload).to.have.lengthOf(1,
|
||||
`Expected 1 update directory during second download but found ${directoriesDuringSecondDownload.length}: ${directoriesDuringSecondDownload.join(', ')}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should update to lower version numbers', async () => {
|
||||
await withUpdatableApp({
|
||||
nextVersion: '0.0.1',
|
||||
|
||||
@@ -43,6 +43,65 @@ describe('MenuItems', () => {
|
||||
expect(item).to.have.property('role').that.is.a('string');
|
||||
expect(item).to.have.property('icon');
|
||||
});
|
||||
|
||||
it('should have a default accelerator for certain roles', () => {
|
||||
const items: Record<string, Electron.MenuItem['accelerator']> = {
|
||||
undo: 'CommandOrControl+Z',
|
||||
redo: process.platform === 'win32' ? 'Control+Y' : 'Shift+CommandOrControl+Z',
|
||||
cut: 'CommandOrControl+X',
|
||||
copy: 'CommandOrControl+C',
|
||||
paste: 'CommandOrControl+V',
|
||||
pasteAndMatchStyle: process.platform === 'darwin' ? 'Cmd+Option+Shift+V' : 'Shift+CommandOrControl+V',
|
||||
delete: null,
|
||||
selectAll: 'CommandOrControl+A',
|
||||
reload: 'CmdOrCtrl+R',
|
||||
forceReload: 'Shift+CmdOrCtrl+R',
|
||||
toggleDevTools: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
|
||||
resetZoom: 'CommandOrControl+0',
|
||||
zoomIn: 'CommandOrControl+Plus',
|
||||
zoomOut: 'CommandOrControl+-',
|
||||
toggleSpellChecker: null,
|
||||
togglefullscreen: process.platform === 'darwin' ? 'Control+Command+F' : 'F11',
|
||||
window: null,
|
||||
minimize: 'CommandOrControl+M',
|
||||
close: 'CommandOrControl+W',
|
||||
help: null,
|
||||
about: null,
|
||||
services: null,
|
||||
hide: 'Command+H',
|
||||
hideOthers: 'Command+Alt+H',
|
||||
unhide: null,
|
||||
quit: process.platform === 'win32' ? null : 'CommandOrControl+Q',
|
||||
showSubstitutions: null,
|
||||
toggleSmartQuotes: null,
|
||||
toggleSmartDashes: null,
|
||||
toggleTextReplacement: null,
|
||||
startSpeaking: null,
|
||||
stopSpeaking: null,
|
||||
zoom: null,
|
||||
front: null,
|
||||
appMenu: null,
|
||||
fileMenu: null,
|
||||
editMenu: null,
|
||||
viewMenu: null,
|
||||
shareMenu: null,
|
||||
recentDocuments: null,
|
||||
toggleTabBar: null,
|
||||
selectNextTab: null,
|
||||
selectPreviousTab: null,
|
||||
showAllTabs: null,
|
||||
mergeAllWindows: null,
|
||||
clearRecentDocuments: null,
|
||||
moveTabToNewWindow: null,
|
||||
windowMenu: null
|
||||
};
|
||||
|
||||
for (const role in items) {
|
||||
if (!Object.hasOwn(items, role)) continue;
|
||||
const item = new MenuItem({ role: role as any });
|
||||
expect(item.accelerator).to.equal(items[role]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('MenuItem.click', () => {
|
||||
@@ -480,7 +539,7 @@ describe('MenuItems', () => {
|
||||
|
||||
it('should display modifiers correctly for simple keys', () => {
|
||||
const menu = Menu.buildFromTemplate([
|
||||
{ label: 'text', accelerator: 'CmdOrCtrl+A' },
|
||||
{ label: 'text', accelerator: 'CommandOrControl+A' },
|
||||
{ label: 'text', accelerator: 'Shift+A' },
|
||||
{ label: 'text', accelerator: 'Alt+A' }
|
||||
]);
|
||||
@@ -492,7 +551,7 @@ describe('MenuItems', () => {
|
||||
|
||||
it('should display modifiers correctly for special keys', () => {
|
||||
const menu = Menu.buildFromTemplate([
|
||||
{ label: 'text', accelerator: 'CmdOrCtrl+Tab' },
|
||||
{ label: 'text', accelerator: 'CommandOrControl+Tab' },
|
||||
{ label: 'text', accelerator: 'Shift+Tab' },
|
||||
{ label: 'text', accelerator: 'Alt+Tab' }
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user