From ac4efed3d13507dc179321c3bc89c78bf606b881 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 26 Jan 2026 14:29:56 +0100 Subject: [PATCH] fix: second argument to `shell.writeShortcutLink` is optional (#49501) fix: second argument to shell.writeShortcutLink is optional Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- shell/common/api/electron_api_shell.cc | 19 ++++++++++++++----- spec/api-shell-spec.ts | 10 ++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/shell/common/api/electron_api_shell.cc b/shell/common/api/electron_api_shell.cc index fc9d014a14..39c78a2f47 100644 --- a/shell/common/api/electron_api_shell.cc +++ b/shell/common/api/electron_api_shell.cc @@ -112,11 +112,20 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path, gin::Arguments* const args) { base::win::ShortcutOperation operation = base::win::ShortcutOperation::kCreateAlways; - args->GetNext(&operation); - auto options = gin::Dictionary::CreateEmpty(args->isolate()); - if (!args->GetNext(&options)) { - args->ThrowError(); - return false; + gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate()); + + v8::Local peek = args->PeekNext(); + if (peek->IsObject()) { + if (!args->GetNext(&options)) { + args->ThrowError(); + return false; + } + } else { + args->GetNext(&operation); + if (!args->GetNext(&options)) { + args->ThrowError(); + return false; + } } base::win::ShortcutProperties properties; diff --git a/spec/api-shell-spec.ts b/spec/api-shell-spec.ts index eef14040b0..ada7518cd6 100644 --- a/spec/api-shell-spec.ts +++ b/spec/api-shell-spec.ts @@ -172,6 +172,16 @@ describe('shell module', () => { expect(fs.existsSync(tmpShortcut)).to.be.true(); }); + it('writes the shortcut with omitted operation (defaults to create)', () => { + expect(shell.writeShortcutLink(tmpShortcut, shortcutOptions)).to.be.true(); + expect(fs.existsSync(tmpShortcut)).to.be.true(); + expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(shortcutOptions); + + const newOptions = { ...shortcutOptions, description: 'new description' }; + expect(shell.writeShortcutLink(tmpShortcut, newOptions)).to.be.true(); + expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(newOptions); + }); + it('correctly sets the fields', () => { expect(shell.writeShortcutLink(tmpShortcut, shortcutOptions)).to.be.true(); expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(shortcutOptions);