-
Notifications
You must be signed in to change notification settings - Fork 303
Update macOS launcher to fix missing tray icon #1822
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
069bc62
Update macOS launcher to fix missing icon
mkrnr e908ace
Fix app termination on macOS
mkrnr f544520
Move launcher from NSTask to calling Python
mkrnr a9b625f
Hard-code PYTHONUSERBASE
mkrnr 6fb36d9
Add rpath for Python.framework
mkrnr 1d34ecb
Make Babel lowercase
mkrnr 3929231
Fix deprecation warnings
mkrnr 8dd5784
Add news entry
mkrnr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix missing menu bar icon on macOS 26. |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| #import <Cocoa/Cocoa.h> | ||
| #include <Python.h> | ||
| #include <libgen.h> | ||
| #include <limits.h> | ||
| #include <unistd.h> | ||
|
|
||
| int main(int argc, char *argv[]) { | ||
| @autoreleasepool { | ||
| char python_home[PATH_MAX]; | ||
| char app_dir_c[PATH_MAX]; | ||
| char *app_dir = realpath(argv[0], NULL); | ||
| app_dir = dirname(dirname(app_dir)); | ||
| strncpy(app_dir_c, app_dir, sizeof(app_dir_c) - 1); | ||
| app_dir_c[sizeof(app_dir_c) - 1] = '\0'; | ||
|
|
||
| snprintf(python_home, sizeof(python_home), "%s/Frameworks/Python.framework/Versions/Current", app_dir_c); | ||
|
|
||
| // Set PYTHONUSERBASE to enable user plugins | ||
| char *home = getenv("HOME"); | ||
| if (home) { | ||
| char python_user_base[PATH_MAX]; | ||
| snprintf(python_user_base, sizeof(python_user_base), "%s/Library/Application Support/plover/plugins/mac", home); | ||
| setenv("PYTHONUSERBASE", python_user_base, 1); | ||
| } | ||
|
|
||
| wchar_t *python_home_w = Py_DecodeLocale(python_home, NULL); | ||
| if (python_home_w == NULL) { | ||
| fprintf(stderr, "Fatal error: unable to decode python_home\n"); | ||
| return 1; | ||
| } | ||
|
|
||
| // Set program name | ||
| wchar_t* program = Py_DecodeLocale(argv[0], NULL); | ||
|
|
||
| PyConfig config; | ||
| PyConfig_InitPythonConfig(&config); | ||
| PyConfig_SetString(&config, &config.home, python_home_w); | ||
| PyConfig_SetString(&config, &config.program_name, program); | ||
| PyConfig_SetBytesArgv(&config, argc, argv); // This automatically populates sys.argv | ||
|
|
||
| Py_InitializeFromConfig(&config); | ||
| PyConfig_Clear(&config); | ||
| // ------------------------------ | ||
|
|
||
| // After this point, we are in a Python interpreter. | ||
|
|
||
| // Prepend the site-packages to sys.path | ||
| char site_packages[PATH_MAX]; | ||
| snprintf(site_packages, sizeof(site_packages), "%s/lib/python3.13/site-packages", python_home); | ||
| wchar_t *site_packages_w = Py_DecodeLocale(site_packages, NULL); | ||
| PyObject* sys_path = PySys_GetObject("path"); | ||
| PyList_Insert(sys_path, 0, PyUnicode_FromWideChar(site_packages_w, -1)); | ||
| PyMem_RawFree(site_packages_w); | ||
|
|
||
| // Run the main script | ||
| PyObject* pName = PyUnicode_FromString("plover.scripts.main"); | ||
| PyObject* pModule = PyImport_Import(pName); | ||
| Py_DECREF(pName); | ||
|
|
||
| if (pModule != NULL) { | ||
| PyObject* pFunc = PyObject_GetAttrString(pModule, "main"); | ||
| if (pFunc && PyCallable_Check(pFunc)) { | ||
|
|
||
| // Call main() - argv is already set in sys.argv! | ||
| PyObject* pResult = PyObject_CallObject(pFunc, NULL); | ||
|
|
||
| if (pResult == NULL) { | ||
| PyErr_Print(); | ||
| fprintf(stderr, "Call to main failed.\n"); | ||
| return 1; | ||
| } | ||
| Py_DECREF(pResult); | ||
|
|
||
| } else { | ||
| if (PyErr_Occurred()) PyErr_Print(); | ||
| fprintf(stderr, "Cannot find function \"main\"\n"); | ||
| } | ||
| Py_XDECREF(pFunc); | ||
| Py_DECREF(pModule); | ||
| } else { | ||
| PyErr_Print(); | ||
| fprintf(stderr, "Failed to load \"plover.scripts.main\"\n"); | ||
| return 1; | ||
| } | ||
|
|
||
| Py_Finalize(); | ||
| PyMem_RawFree(python_home_w); | ||
| PyMem_RawFree(program); | ||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [build-system] | ||
| requires = [ | ||
| "Babel", | ||
| "babel", | ||
| "PySide6>=6.9.0", | ||
| "setuptools>=79.0.0", | ||
| "wheel", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| Babel | ||
| babel | ||
| PySide6 | ||
| setuptools | ||
| wheel | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.