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

Is Preferences window supposed to stay open on Python Launcher? #113718

Open
justcheking opened this issue Jan 4, 2024 · 4 comments
Open

Is Preferences window supposed to stay open on Python Launcher? #113718

justcheking opened this issue Jan 4, 2024 · 4 comments
Labels
OS-mac type-bug An unexpected behavior, bug, or error

Comments

@justcheking
Copy link

justcheking commented Jan 4, 2024

Bug report

Bug description:

possible bug...?

The preferences window remains open when you double-click a ".py" file in Finder on MacOS. This is with no options selected in preferences (such as run in terminal window).

I would have expected a flag for silent operation or for the window to automatically close instead of hovering in the middle of the screen.

CPython versions tested on:

3.13

Operating systems tested on:

macOS

@justcheking justcheking added the type-bug An unexpected behavior, bug, or error label Jan 4, 2024
@ned-deily
Copy link
Member

Thanks for your query. I believe that behavior is by design. It allows the user to have some control over the behavior of the execution of the Python file. Despite that, there are security concerns with the Python Launcher app provided for macOS, as noted in #49512, for example. Not opening the preferences window could make it easier for stealth execution of "bad actor" scripts. The Launcher app itself is very old and is need of a redesign. Until that happens, I don't there will be any change in the current behavior.

@ronaldoussoren
Copy link
Contributor

AFAIK this behaviour is not intentional, but Python Launcher depends on the order of system events during startup and those (appearently) have changed.

See the code below that suggests that the launcher should stop immediately when opening an event.

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
// Test that the file mappings are correct
[self testFileTypeBinding];
// If we were opened because of a file drag or double-click
// we've set initial_action_done in shouldShowUI
// Otherwise we open a preferences dialog.
if (!initial_action_done) {
initial_action_done = YES;
[self showPreferences: self];
}
}
- (BOOL)shouldShowUI
{
// if this call comes before applicationDidFinishLaunching: we
// should terminate immediately after starting the script.
if (!initial_action_done)
should_terminate = YES;
initial_action_done = YES;
if( GetCurrentKeyModifiers() & optionKey )
return YES;
return NO;
}

As Ned writes the code is old and needs some love.

@ronaldoussoren
Copy link
Contributor

A very rough patch that gives slightly better behaviour:

diff --git a/Mac/PythonLauncher/MyAppDelegate.m b/Mac/PythonLauncher/MyAppDelegate.m
index 9cc2aa0ad9..51934d4e0e 100644
--- a/Mac/PythonLauncher/MyAppDelegate.m
+++ b/Mac/PythonLauncher/MyAppDelegate.m
@@ -25,10 +25,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
     // If we were opened because of a file drag or double-click
     // we've set initial_action_done in shouldShowUI
     // Otherwise we open a preferences dialog.
+#if 0
     if (!initial_action_done) {
         initial_action_done = YES;
         [self showPreferences: self];
     }
+#endif
 }
 
 - (BOOL)shouldShowUI
@@ -50,6 +52,10 @@ - (BOOL)shouldTerminate
 
 - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
 {
+    if (!initial_action_done) {
+        initial_action_done = YES;
+        [self showPreferences: self];
+    }
     return NO;
 }

With the patch:

  • open -a "/path/to/Python Launcher.app" some-script.py: Launches the script, and immediately exits the launcher
  • open -a "/path/to/Python Launcher.app": Show the preferences window

This still relies on an unspecified order of events, but should be safer: The new code hooks into the document-based app code to show the preference pane when AppKit tries to decide if it should show a new "Untitled" document (which means there weren't file-open events).

There's no PR yet because I haven't properly tested yet (including tests with an installed copy of the launcher and through the Finder), and because I want to look into what happens when you try to open more than one script at once.

I'll likely add a Read Me as well that fully documents how to app is supposed to work, and how to test it (manually).

@justcheking
Copy link
Author

Sounds much cleaner. When there is a build with this mod I can test on Ventura and Sonoma, Intel and Apple Silicon.
I don't have all the tools and libs available or I would build it myself and test.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-mac type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants