-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle native quit and file-open events on macOS
- Loading branch information
Showing
5 changed files
with
39 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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,28 @@ | ||
try: | ||
import gi | ||
|
||
gi.require_version("GtkosxApplication", "1.0") | ||
except ValueError: | ||
macos_init = None | ||
else: | ||
from gi.repository import Gio, GtkosxApplication | ||
|
||
macos_app = GtkosxApplication.Application.get() | ||
|
||
def open_file(macos_app, path, gtk_app): | ||
if path == __file__: | ||
return False | ||
|
||
gtk_app.open([Gio.File.new_for_path(path)], "") | ||
|
||
return True | ||
|
||
def block_termination(macos_app, application): | ||
quit = application.quit() | ||
return not quit | ||
|
||
def macos_init(application, gtk_app): | ||
macos_app.connect("NSApplicationOpenFile", open_file, gtk_app) | ||
macos_app.connect( | ||
"NSApplicationBlockTermination", block_termination, application | ||
) |
This file contains 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 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