Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Recent api not working on macOS #40611

Open
3 tasks done
create3000 opened this issue Nov 24, 2023 · 9 comments
Open
3 tasks done

[Bug]: Recent api not working on macOS #40611

create3000 opened this issue Nov 24, 2023 · 9 comments
Labels
27-x-y bug 🪲 has-repro-repo Issue can be reproduced by cloning a git repo platform/macOS

Comments

@create3000
Copy link

Preflight Checklist

Electron Version

27.1.2

What operating system are you using?

macOS

Operating System Version

Sonoma

What arch are you using?

x64

Last Known Working Electron version

don't know

Expected Behavior

Recent files added with app.addRecentDocument should appear in recentDocuments menu item and in dock app icon menu.

Actual Behavior

Although I use app.addRecentDocument there do not appear any files in recentDocuments menu item, neither in packaged version of app nor in development mode.

Testcase Gist URL

No response

Additional Information

No response

@codebytere codebytere added platform/macOS blocked/need-repro Needs a test case to reproduce the bug 27-x-y labels Nov 26, 2023
@electron-issue-triage
Copy link

Hello @create3000. Thanks for reporting this and helping to make Electron better!

Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.

Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

Now adding the blocked/need-repro Needs a test case to reproduce the bug label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.

@create3000
Copy link
Author

I created a test project at https://github.com/create3000/electron-recent-documents-api that uses the example code from https://www.electronjs.org/docs/latest/tutorial/recent-documents#example.

To start the program type npm start in a terminal.

I tested it also on Windows, but had no luck. I further found out that a recent file is added on macOS under Apple > Recent Objects, but not in the Application menu and not in the Dock menu.

@electron-issue-triage electron-issue-triage bot removed the blocked/need-repro Needs a test case to reproduce the bug label Dec 3, 2023
@caldwell
Copy link

caldwell commented Dec 4, 2023

I also just ran into this bug. I checked against some other Electron versions and it appears to be broken in 27.0.0+ (including 28.0.0-beta.11). It works for me in Electron 26.6.2. I am on macOS 14.0 (Sonoma) with an M1 processor.

@jkleinsc jkleinsc added the has-repro-repo Issue can be reproduced by cloning a git repo label Jan 10, 2024
@nsfmc
Copy link

nsfmc commented Feb 25, 2024

i'm able to reproduce this on electron@29.0.0 but as noted, it works fine in the 26.x release.

The menu bar's recents remain dimmed and inactive, showing no submenu. however, right clicking on the app icon does show the recent items there. i looked at the code, namely Browser::AddRecentDocument and all i can guess is that base::apple::FilePathToNSString(path); might behave differently than base::mac::FilePathToNSString(path); https://github.com/electron/electron/blame/995f3dc120281a5e364ff1624ea77ee58ce89947/shell/browser/browser_mac.mm#L163

still, i find that somewhat unlikely given that right clicking on the dock icon does show recent documents, which i assume are populated from the noteNewRecentDocumentURL call and the code for replaceSubmenuShowingRecentDocuments

- (void)replaceSubmenuShowingRecentDocuments:(NSMenuItem*)item {
hasn't been touched in years. i'll look into this more, i haven't tried building electron yet, but those are the places i would probably poke around first.

@liamcain
Copy link

liamcain commented Mar 1, 2024

Also running this issue on electron@28. The recentDocuments are populated correctly in the dock, but the Application Menu "Open Recent" always remains disabled.

@nsfmc
Copy link

nsfmc commented Mar 2, 2024

to add more color to this: in electron 29.1.0, when starting a non-prod electron project, items added are registered and available to the dock, but they're not visible as a submenu of the menu bar's "open recent" item.

When i package the app, however, even in electron 26, while the open recents menu is active, it is entirely populated with empty/nil items.

image

i get nothing in either case, i do however see a handful of SharedFileList errors that look like this Failed to resolve bookmark 0 for item DC13CF0A-3DEF-4BB2-9440-EB6226BE679B with error: Error Domain=NSOSStatusErrorDomain Code=-43 "fnfErr: File not found" UserInfo={NSLocalizedDescription=BOOKMARK_DATA_AND_URL_ARE_NULL}

image

if i run the app using yarn start in dev mode in electron 26 (and not higher), i do see the recents populated correctly

image

as well as in the dock

image

i'm running under Sonoma 14.2.1 (23C71), so i'm guessing this entire combination of things has to do with how electron receives the shared file list in newer static builds. pretty confusing but i'll keep poking

@KevinHughes
Copy link

KevinHughes commented Apr 12, 2024

This is also not working for me in electron 29.3 running macOS Sonoma 14.4.1, either in production or in debug mode. The "Open Recent" menu stays disabled while recent documents appear in the app's Dock menu.

@pedroabreu
Copy link

I'm seeing the same issue on v27+ and managed to narrow it down to a specific nightly version. v27.0.0-nightly.20230718 is the last working version so v27.0.0-nightly.20230719 is the first release with the issue present.

Here's the compare between the two releases v27.0.0-nightly.20230718...v27.0.0-nightly.20230719

As for reproduction, on electron fiddle, add this snippet inside the 'app.whenReady'

app.whenReady().then(() => {
  const template = [
  {
    label: "asdasd",
  "submenu":[
    {
      "label":"Open Recent",
      "role":"recentdocuments",
      "submenu":[
        {
          "label":"Clear Recent",
          "role":"clearrecentdocuments"
        }
      ]
    }
  ]
}
]
const menu = Menu.buildFromTemplate(template)

  Menu.setApplicationMenu(menu)
  createWindow()

I see some changes in the electron_menu_controller.mm related to recentDocuments but this is as far as I've got.

@pedroabreu
Copy link

This might be fixed in v29, see #41978

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
27-x-y bug 🪲 has-repro-repo Issue can be reproduced by cloning a git repo platform/macOS
Projects
No open projects
Status: No status
Development

No branches or pull requests

8 participants