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

[WIP]ウィンドウ情報の取得をポーリング方式からイベント駆動方式にする #44

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
18 changes: 14 additions & 4 deletions nativeSrc/taskbar.helper/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,29 @@ class WindowObserver {
// ウィンドウの変更を監視
func observeWindowChanges() {
let notificationCenter = NSWorkspace.shared.notificationCenter

// アクティブになるイベントの監視
notificationCenter.addObserver(
self,
selector: #selector(windowDidChange(notification:)),
name: NSWorkspace.didActivateApplicationNotification,
object: nil
)

// アプリケーションが起動されたイベントを監視
// これがないと新規で起動したアプリケーションのウィンドウ情報が取得できない
notificationCenter.addObserver(
self,
selector: #selector(windowDidChange(notification:)),
name: NSWorkspace.didLaunchApplicationNotification,
object: nil
)
}

@objc func windowDidChange(notification: NSNotification) {
// 0.1秒待機
// アプリを起動した直後にウィンドウ情報を取得すると、ウィンドウ情報が取得できないため
usleep(100000)
mesichicken marked this conversation as resolved.
Show resolved Hide resolved
if let data = getWindowInfoListData() {
let stdOut = FileHandle.standardOutput
stdOut.write(data)
Expand All @@ -123,10 +137,6 @@ case "grant":
// スクリーンキャプチャのアクセス要求
CGRequestScreenCaptureAccess()
case "list":
if let data = getWindowInfoListData() {
let stdOut = FileHandle.standardOutput
stdOut.write(data)
}

// ウィンドウの変更を監視
WindowObserver.shared.observeWindowChanges()
Expand Down