Skip to content

Commit

Permalink
Implement "window hacks" for cocoa.
Browse files Browse the repository at this point in the history
This unhides the traffic light buttons that pywebview hides when frameless.
  • Loading branch information
Fizzadar committed Dec 2, 2020
1 parent 2eefbd4 commit c8e0772
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 23 additions & 1 deletion kanmail/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import webview

from kanmail.log import logger
from kanmail.settings.constants import FRAMELESS, IS_APP, SERVER_PORT
from kanmail.settings.constants import DEBUG, FRAMELESS, IS_APP, SERVER_PORT

ID_TO_WINDOW = {} # internal ID -> window object
UNIQUE_NAME_TO_ID = {} # name -> internal ID for unique windows
Expand Down Expand Up @@ -105,3 +105,25 @@ def get_main_window_size_position() -> Dict[str, int]:
'width': window.width,
'height': window.height,
}


def init_window_hacks() -> None:
try:
import AppKit
from webview.platforms import cocoa
except ImportError:
pass
else:
# Normally set by webview.start but importing cocoa before breaks that
cocoa._debug = DEBUG

class CustomBrowserView(cocoa.BrowserView):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.window.standardWindowButton_(AppKit.NSWindowCloseButton).setHidden_(False)
self.window.standardWindowButton_(AppKit.NSWindowZoomButton).setHidden_(False)
self.window.standardWindowButton_(
AppKit.NSWindowMiniaturizeButton,
).setHidden_(False)

cocoa.BrowserView = CustomBrowserView
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SERVER_PORT,
)
from kanmail.version import get_version
from kanmail.window import create_window, destroy_main_window
from kanmail.window import create_window, destroy_main_window, init_window_hacks


def run_cache_cleanup_later():
Expand Down Expand Up @@ -78,6 +78,8 @@ def wrapper(thread_name):
def main():
logger.info(f'\n#\n# Booting Kanmail {get_version()}\n#')

init_window_hacks()

server_thread = Thread(name='Server', target=run_server)
server_thread.daemon = True
server_thread.start()
Expand Down

0 comments on commit c8e0772

Please sign in to comment.