2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Tauriでフローティングウィンドウを作る——どのアプリからでもCmd+Shift+Hで呼び出せるAIアシスタント

2
Posted at

参考になったら ❤️ もらえると励みになります!

8年前のMacBook Air(Intel)で全テスト済み。

HiyokoHelperは360×440pxのフローティングウィンドウだ。いつでもアクセスでき、邪魔にならない。どのアプリからでも Cmd+Shift+H で前面に呼び出せる。


ウィンドウ設定

{
  "app": {
    "windows": [{
      "label": "main",
      "width": 360,
      "height": 440,
      "resizable": false,
      "decorations": false,
      "alwaysOnTop": true,
      "transparent": true,
      "visible": false
    }],
    "macOS": {
      "activationPolicy": "accessory"
    }
  }
}
  • decorations: false — カスタムタイトルバー
  • alwaysOnTop: true — 全ての上に浮かぶ
  • activationPolicy: accessory — Dockなし、Cmd+Tabなし
  • visible: false — 起動時は非表示

どのアプリからでも呼び出せるグローバルショートカット

let shortcut: Shortcut = "CmdOrCtrl+Shift+H".parse()?;

app.global_shortcut().on_shortcut(shortcut, |app, _, _| {
    if let Some(window) = app.get_webview_window("main") {
        if window.is_visible().unwrap_or(false) {
            window.hide().unwrap();
        } else {
            window.show().unwrap();
            window.set_focus().unwrap();
        }
    }
})?;

VS Code、Terminal、Finder——どのアプリからでも動く。


ネイティブタイトルバーなしでドラッグ可能にする

.title-bar { -webkit-app-region: drag; }
.title-bar button { -webkit-app-region: no-drag; }

タイトルバー部分でドラッグできる。内側のボタンはクリックできる。


閉じるボタンは終了ではなく非表示

#[tauri::command]
pub fn hide_window(window: tauri::Window) {
    window.hide().unwrap();
    // プロセスは生き続ける
    // クリップボードモニターも動き続ける
    // ショートカットも引き続き使える
}

ログイン時に自動起動

tauri::Builder::default()
    .plugin(tauri_plugin_autostart::init(
        MacosLauncher::LaunchAgent,
        Some(vec!["--minimized"]),
    ))

ログイン時に非表示で起動する。画面に一度も現れることなく、Cmd+Shift+H の準備が整っている。


HiyokoHelper (OSS) | X → @hiyoyok

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?