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

Add NSAppDelegate endpoint required by Sonoma. #2182

Merged
merged 4 commits into from
Feb 20, 2024

Conversation

freakboy3742
Copy link
Member

@freakboy3742 freakboy3742 commented Nov 2, 2023

Reported by Casimir1965 on Discord.

When running under macOS Sonoma, Toga apps generate the following message:

2023-11-02 11:10:34.900 Python[83553:21023244] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.

This PR adds the suggested method.

Fixes #2188.


To test this: if you install the branch from this PR:

$ pip install "git+https://github.com/freakboy3742/toga@sonoma#subdirectory=core" "git+https://github.com/freakboy3742/toga@sonoma#subdirectory=cocoa" "git+https://github.com/freakboy3742/toga@sonoma#subdirectory=toga" "git+https://github.com/freakboy3742/toga@sonoma#subdirectory=demo"
$ toga-demo

The warning should not be raised any more.

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

@go8ose
Copy link

go8ose commented Nov 2, 2023

Hi Russell,

I've tried to replicate the fault and the fix. But I was not able to replicate the fault. I'm on Sonama 14.0, with a MacBook Air M2. I've used python 3.11. When I run toga-demo after pip install toga-demo I only see:

(toga_pr_2182) geoffc@home-pr-cro-laptop-01 tmp % toga-demo
WARNING: Can't find icon resources/toga-demo; falling back to default icon
WARNING: Using empty string for missing value in data. Define a 'missing_value' on the table to silence this message
[Cocoa] Not implemented: ScrollContainer.set_on_scroll()
WARNING: Can't find icon resources/brutus; falling back to default icon

For reference, here's the python packages installed at that time:

(toga_pr_2182) geoffc@home-pr-cro-laptop-01 tmp % pip freeze
rubicon-objc==0.4.7
toga==0.3.1
toga-cocoa==0.3.1
toga-core==0.3.1
toga-demo==0.3.1
travertino==0.3.0

@freakboy3742
Copy link
Member Author

Thanks for that testing @go8ose - I guess there's something deeper going on here.

@freakboy3742
Copy link
Member Author

Based on some reading, it's possible that the issue only manifests with Briefcase deployed apps. I've moved the bug discussion to #2188. (cc @go8ose).

@glyph
Copy link

glyph commented Nov 3, 2023

@freakboy3742 Since I only saw one test here, I just replicated @go8ose's results; same behavior exactly.

@freakboy3742
Copy link
Member Author

@glyph Can I ask you to try running a Briefcase test?

In a clean venv:

pip install briefcase
briefcase new --no-input
cd helloworld
briefcase run

If that generates the error, update the pyproject.toml that has been generated to replace the "toga-cocoa~=0.3.1" dependency with:

"git+https://github.com/freakboy3742/toga@sonoma#subdirectory=core",
"git+https://github.com/freakboy3742/toga@sonoma#subdirectory=cocoa",

and then run briefcase run -r

@glyph
Copy link

glyph commented Nov 3, 2023

Hmm. The full output of briefcase run is this:

[helloworld] Starting app...
===========================================================================
Configuring isolated Python...
Pre-initializing Python runtime...
PythonHome: /Users/glyph/helloworld/build/helloworld/macos/app/Hello World.app/Contents/Resources/support/python-stdlib
PYTHONPATH:
- /Users/glyph/helloworld/build/helloworld/macos/app/Hello World.app/Contents/Resources/support/python311.zip
- /Users/glyph/helloworld/build/helloworld/macos/app/Hello World.app/Contents/Resources/support/python-stdlib
- /Users/glyph/helloworld/build/helloworld/macos/app/Hello World.app/Contents/Resources/support/python-stdlib/lib-dynload
- /Users/glyph/helloworld/build/helloworld/macos/app/Hello World.app/Contents/Resources/app_packages
- /Users/glyph/helloworld/build/helloworld/macos/app/Hello World.app/Contents/Resources/app
Configure argc/argv...
Initializing Python runtime...
Installing Python NSLog handler...
Running app module: helloworld
---------------------------------------------------------------------------

@freakboy3742
Copy link
Member Author

Hrm - ok - thanks; definitely looks like there's something else going on. I'll have to wait until the original reporter comes back online to see what else they're doing that could be the cause.

@glyph
Copy link

glyph commented Nov 3, 2023

Tested with python 3.10, 3.11, 3.12 from python.org and 3.11 from homebrew just for good measure. Same behavior on all of them. How strange!

@selasley
Copy link

selasley commented Nov 5, 2023

I get the warning about "Secure coding is not enabled" with toga 0.4.0, python3.12 from python.org, Sonoma 14.1 on a M2 Mac Studio. The briefcase 0.3.16 helloworld app ran with no warnings

$ toga-demo
WARNING: Can't find icon resources/toga-demo; falling back to default icon
WARNING: Can't find icon resources/brutus; falling back to default icon
2023-11-04 23:20:10.684 Python[23246:5309149] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.
button press
still running... (iteration 0)
still running... (iteration 1)

toga-demo runs without the Secure warning with toga-0.3.2.dev1473+g7e489b01 toga-cocoa-0.3.2.dev1473+g7e489b01 toga-core-0.3.2.dev1473+g7e489b01

$ toga-demo
WARNING: Can't find icon resources/toga-demo; falling back to default icon
WARNING: Can't find icon resources/brutus; falling back to default icon
button press
still running... (iteration 0)
still running... (iteration 1)

@freakboy3742
Copy link
Member Author

@glyph Can I ask you run the Briefcase test again - I'm wondering if the issue might be with a change that has been introduced to Toga since the release of 0.3.1. Now that we have released 0.4.0, Briefcase should use that version by default, which might make the problem manifest (maybe?).

@freakboy3742
Copy link
Member Author

@selasley Thanks for that testing. Now we just need to work out why you're able to reproduce this, but nobody else can (including, apparently, the original reporter...)

@glyph
Copy link

glyph commented Nov 6, 2023

@glyph Can I ask you run the Briefcase test again - I'm wondering if the issue might be with a change that has been introduced to Toga since the release of 0.3.1. Now that we have released 0.4.0, Briefcase should use that version by default, which might make the problem manifest (maybe?).

@freakboy3742 Re-ran the test. Same output (i.e.: nothing), sorry!

@selasley
Copy link

selasley commented Nov 6, 2023

I rebooted the Mac, created a new venv, pip installed toga and tog-demo 0.4.0. Running toga-demo now only displays the "Can't find" warnings

$ toga-demo
WARNING: Can't find icon resources/toga-demo; falling back to default icon
WARNING: Can't find icon resources/brutus; falling back to default icon
button press
still running... (iteration 0)
still running... (iteration 1)

I tried the same steps on a UTM virtual Sonoma. This was the first time a toga app was run in the VM. Only the "Can't find" warnings appeared. I don't know what was different when running toga-demo displayed the "Secure config" warning

@selasley
Copy link

selasley commented Nov 6, 2023

Set up a python3.12 venv remotely on a M1 Mac with toga and toga-demo 0.4.0. The "Secure config" warning only appeared the first time toga-demo was run

$ source /tmp/togaenv/bin/activate
(togaenv) $ toga-demo
WARNING: Can't find icon resources/toga-demo; falling back to default icon
WARNING: Can't find icon resources/brutus; falling back to default icon
2023-11-05 22:02:32.513 Python[98189:17820113] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.
button press
still running... (iteration 0)
still running... (iteration 1)
still running... (iteration 2)
still running... (iteration 3)
still running... (iteration 4)
still running... (iteration 5)
still running... (iteration 6)
still running... (iteration 7)
still running... (iteration 8)
still running... (iteration 9)
(togaenv) $
(togaenv) $
(togaenv) $ toga-demo
WARNING: Can't find icon resources/toga-demo; falling back to default icon
WARNING: Can't find icon resources/brutus; falling back to default icon
(togaenv) $

@glyph
Copy link

glyph commented Nov 6, 2023

Just a hunch here, but LaunchServices learns stuff about apps via the bundle id; does varying the bundle ID to make a "new" app each time reproduce it with any reliability?

@freakboy3742
Copy link
Member Author

I've finally got access to a Sonoma test machine, and I can confirm this fixes the problem for me; so let's merge it!

@mhsmith mhsmith merged commit a5782ba into beeware:main Feb 20, 2024
35 checks passed
@freakboy3742 freakboy3742 deleted the sonoma branch February 20, 2024 22:17
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.

Toga apps generate warning on macOS 14 (Sonoma)
5 participants