LoginSignup
2
2

More than 5 years have passed since last update.

フォーカス時かつトレイクリックができない

Posted at

できなかった宣言

やりたかったこと

トレイアイコンクリック時の動作をウインドウの状態で変化させたい
(良し悪しは別にして)

ウインドウ状態 トレイクリック時
非フォーカス フォーカス
フォーカス トレイに最小化(非表示)
トレイに最小化 フォーカス(表示)

環境

  • Electron 0.37.2
  • Windows 7

書いてみたコード


    var Tray = require('tray');
    var tray = new Tray('アイコン');

    tray.on('click', function() {
        if (mainWindow.isFocused()) {
            mainWindow.hide()
        } else if (mainWindow.isVisible()) {
            mainWindow.focus()
        } else {
            mainWindow.show()
        }

    })

    mainWindow = new BrowserWindow({hogehoge});

結果

当たり前だが、トレイクリック時点でウインドウのフォーカスがはずれていると思われる。
状態は表示かつ非フォーカスになるので、トレイクリックの結果は常にフォーカスになる。

もっとjs側でフラグ管理とかしないといけないのだろう。
さして必須ではないので今は

        if (mainWindow.isVisible()) {
            mainWindow.hide()
        } else {
            mainWindow.show()
        }

にしている。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2