Skip to content

Commit

Permalink
fix window layout level problem(can not see keyboard)
Browse files Browse the repository at this point in the history
  • Loading branch information
weykon committed Dec 31, 2022
1 parent fa912f8 commit 834e85c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions NewMan/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
let toggleHotKey = HotKey(key: .space, modifiers: [.option])
var refreshHotKey : HotKey?
var escHotKey: HotKey?

func applicationDidFinishLaunching(_ aNotification: Notification) {

Expand All @@ -27,6 +28,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
}
popover.contentViewController = PopoverViewController.freshController()

eventMonitor = EventMonitor(mask: [.leftMouseDown, .rightMouseDown]) { [weak self] event in
if let strongSelf = self, strongSelf.popover.isShown {
strongSelf.closePopover(event!)
Expand Down Expand Up @@ -61,30 +63,39 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

// 设置应用内快捷键,启用
func onListenRefreshHotkey () {
func onListenOpeningHotkey () {
refreshHotKey = HotKey(key: .r, modifiers: [.command])
refreshHotKey?.keyDownHandler = {
let popoverViewController = self.popover.contentViewController as! PopoverViewController
popoverViewController.WebView?.reload()
}
escHotKey = HotKey(key: .escape,modifiers:[])
escHotKey?.keyDownHandler = {
self.closePopover(self.popover)
}
}
func unregisterRefreshHotkey(){
func unregisterClosingHotkey(){
refreshHotKey?.keyDownHandler = nil
refreshHotKey?.keyUpHandler = nil
refreshHotKey = nil
escHotKey?.keyDownHandler = nil
escHotKey?.keyUpHandler = nil
escHotKey = nil
}
// 显示Popover
@objc func showPopover(_ sender: AnyObject) {
if let button = statusItem.button {
popover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
onListenRefreshHotkey()
onListenOpeningHotkey()
// 降低显示层级
popover.contentViewController?.view.window?.level=NSWindow.Level.submenu;
}
eventMonitor?.start()
}
// 隐藏Popover
@objc func closePopover(_ sender: AnyObject) {
popover.performClose(sender)
unregisterRefreshHotkey()
unregisterClosingHotkey()
eventMonitor?.stop()
}
// 接管togglePopover
Expand Down
2 changes: 1 addition & 1 deletion NewMan/PopoverViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PopoverViewController: NSViewController {
// Do view setup here.

let url = URL(string: "https://chat.openai.com/chat")!
WebView.load(URLRequest(url: url))
WebView.load(URLRequest(url: url))
}


Expand Down

0 comments on commit 834e85c

Please sign in to comment.