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

Fix document mode on macOS #2866

Merged
merged 6 commits into from
Sep 23, 2024

Conversation

proneon267
Copy link
Contributor

Apps that specify both document_types and a main_window no longer display the "Document Selection" dialog on startup in macOS.

Fixes #2860

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's on the right track; a note inline about the specifics of the implementation.

and len(self.windows) == 0
and self.documents.types != []
):
asyncio.create_task(self.documents.request_open())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the right general idea, but:

  1. It's the wrong place for the code. This should be part of the create_initial_window method.
  2. This logic should only be triggered on macOS (or, more strictly, on platforms where CLOSE_ON_LAST_WINDOW=True). On other platforms (Windows, GTK), we need to open a default document, not invoke request_open.
  3. There's also an interaction with command line handling. At present, Cocoa uses HANDLES_COMMAND_LINE to shortcut the _create_initial_window handling; I think this means that HANDLES_COMMAND_LINE should only used to shortcut the argv handling.

changes/2860.bugfix.rst Outdated Show resolved Hide resolved
proneon267 and others added 2 commits September 23, 2024 06:42
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
@proneon267
Copy link
Contributor Author

I have modified create_initial_window() to correct the bug and added a new core test.

The linux-wayland focus related test failures are unrelated to this PR and cannot be reproduced on my local machine. I thought maybe they are related to document based apps, but testing on my local machine, there is no unexpected dialog being shown during the test that would disrupt the widget focus during the tests.

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring of create_initial_window was really close, but not quite there. There's two very distinct things happening in that method - handling the command line arguments; and ensuring that there is an open window. Your version combined the two; I've split them into two separate parts.

The Wayland test failure is a transient thing that has started in the last couple of days (#2871); we're still trying to work out what is going on there.

Thanks for the patch!

@proneon267
Copy link
Contributor Author

Thanks for the quick response. Also, could you tell me why in the initial commit of the PR, the tests complained about asyncio.create_task(self.documents.request_open()) not being awaited. I had thought create_task didn't needed to be awaited.

@freakboy3742
Copy link
Member

Thanks for the quick response. Also, could you tell me why in the initial commit of the PR, the tests complained about asyncio.create_task(self.documents.request_open()) not being awaited. I had thought create_task didn't needed to be awaited.

create_task does exactly what it says on the tin - it creates a task, and queues it for execution. The task still needs to be executed, however - and executing an async task is effectively "awaiting" the task.

@freakboy3742 freakboy3742 merged commit efea361 into beeware:main Sep 23, 2024
38 checks passed
@proneon267 proneon267 deleted the macos_fix_document_mode branch September 23, 2024 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Latest main branch breaks testbed test_app.py::test_current_window test on macOS
2 participants