Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added integrations/flow-launcher/Images/app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions integrations/flow-launcher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Flow Launcher Plugin for WindowTabs

Control [WindowTabs](https://windowtabs.app) directly from Flow Launcher: restore saved workspaces and run any WindowTabs command without leaving your keyboard.

## Usage

- `wt` — List saved workspaces and common commands.
- `wt <query>` — Search workspaces and WindowTabs commands by name or id.
- `wt ws <name>` — Filter workspaces only.
- `wt cmd <id> [choice]` — Run a command with an optional choice (for example `wt cmd tab-color Blue`).

The plugin talks directly to a running WindowTabs instance over its local named pipe (`BemoSoftware.WindowTabs.<SessionId>`) and falls back to `WindowTabs.exe` CLI when WindowTabs is not running.

## Local testing on Windows

1. Copy this folder to `%APPDATA%\FlowLauncher\Plugins\Flow.Launcher.Plugin.WindowTabs-1.0.0\`.
2. Restart Flow Launcher (or run `Restart Flow Launcher` from Flow Launcher).
3. Type `wt` to test.

## Publishing to the Flow Launcher Plugin Store

1. Host this folder in a dedicated GitHub repository (for example `leafOfTree/Flow.Launcher.Plugin.WindowTabs`) and attach a release `.zip` containing `plugin.json`, `main.py`, `wt_client.py`, `SettingsTemplate.yaml`, and `Images\app.png`.
2. Open a Pull Request to [Flow-Launcher/Flow.Launcher.PluginsManifest](https://github.com/Flow-Launcher/Flow.Launcher.PluginsManifest) adding `plugins/WindowTabs-8F3A4B6C9D124E8BA7C32D5E6F1A9B04.json`.
13 changes: 13 additions & 0 deletions integrations/flow-launcher/SettingsTemplate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body:
- type: input
attributes:
name: executable_path
label: WindowTabs.exe path (optional)
description: Leave blank to auto-detect from PATH, startup entry, or default folders.
defaultValue: ""
- type: input
attributes:
name: command_delay_ms
label: Focus delay before running commands (ms)
description: Brief pause after Flow Launcher hides so commands act on your previous window.
defaultValue: "120"
204 changes: 204 additions & 0 deletions integrations/flow-launcher/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import json
import os
import sys
import webbrowser

import wt_client

ICON = "Images\\app.png"
WEBSITE = "https://windowtabs.app"
PINNED_COMMANDS = [
"command-palette",
"search-tabs",
"edit-groups",
"split-next",
"save-workspace",
"settings",
]


def _load_settings(request: dict) -> dict:
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "settings.json")
try:
with open(path, "r", encoding="utf-8") as f:
local = json.load(f)
except (OSError, json.JSONDecodeError):
local = {}
supplied = request.get("settings")
return {
**(local if isinstance(local, dict) else {}),
**(supplied if isinstance(supplied, dict) else {}),
}


def _find_executable(settings: dict) -> str | None:
configured = settings.get("executable_path")
return wt_client.find_executable(configured if isinstance(configured, str) else "")


def _command_delay(settings: dict) -> int:
try:
return max(0, int(settings.get("command_delay_ms", 120)))
except (TypeError, ValueError, OverflowError):
return 120


def _score(query: str, text: str) -> int:
q = query.lower()
t = text.lower()
if t == q:
return 100
if t.startswith(q):
return 80
if q in t:
return 60
words = q.split()
if words and all(w in t for w in words):
return 45
return 0


def _workspace_item(name: str, score: int = 70) -> dict:
return {
"Title": name,
"SubTitle": f"Restore workspace: {name}",
"IcoPath": ICON,
"Score": score,
"JsonRPCAction": {
"method": "restore_workspace",
"parameters": [name],
},
}


def _command_item(cmd_id: str, caption: str, choice: str = "", score: int = 50) -> dict:
title = f"{caption} ({choice})" if choice else caption
subtitle = f"WindowTabs command: --command {cmd_id}" + (f" {choice}" if choice else "")
return {
"Title": title,
"SubTitle": subtitle,
"IcoPath": ICON,
"Score": score,
"JsonRPCAction": {
"method": "run_command",
"parameters": [cmd_id, choice],
},
}


def _download_item() -> dict:
return {
"Title": "WindowTabs not found — Download from windowtabs.app",
"SubTitle": "Open https://windowtabs.app or set WindowTabs.exe path in plugin settings",
"IcoPath": ICON,
"Score": 100,
"JsonRPCAction": {
"method": "open_url",
"parameters": [WEBSITE],
},
}


def handle_query(raw_query: str, exe: str | None) -> list[dict]:
workspaces = wt_client.list_workspaces(exe)
commands = wt_client.list_commands(exe)

if not workspaces and not commands:
if exe:
return [
{
"Title": "Start WindowTabs",
"SubTitle": exe,
"IcoPath": ICON,
"Score": 100,
"JsonRPCAction": {"method": "launch_app", "parameters": [exe]},
}
]
return [_download_item()]

query = raw_query.strip()
results: list[dict] = []

# Prefix: "ws <filter>" lists workspaces only.
if query.lower().startswith("ws ") or query.lower() == "ws":
sub = query[2:].strip()
for ws in workspaces:
s = 80 if not sub else _score(sub, ws)
if s > 0:
results.append(_workspace_item(ws, s))
return results

# Prefix: "cmd <id> [choice]" passes an explicit command and optional choice.
if query.lower().startswith("cmd "):
rest = query[4:].strip().split(None, 1)
if rest:
wanted = rest[0]
choice = rest[1].strip() if len(rest) > 1 else ""
for cmd_id, caption in commands:
s = _score(wanted, cmd_id)
if s > 0:
results.append(_command_item(cmd_id, caption, choice, s))
return results

# Empty query: show workspaces first, then frequently used commands.
if not query:
for ws in workspaces:
results.append(_workspace_item(ws, 90))
by_id = {cmd_id: caption for cmd_id, caption in commands}
for cmd_id in PINNED_COMMANDS:
if cmd_id in by_id:
results.append(_command_item(cmd_id, by_id[cmd_id], score=60))
if not results:
for cmd_id, caption in commands[:10]:
results.append(_command_item(cmd_id, caption, score=50))
return results

# General query: search both workspaces and commands.
for ws in workspaces:
s = _score(query, ws)
if s > 0:
results.append(_workspace_item(ws, s + 15))
for cmd_id, caption in commands:
s = max(_score(query, caption), _score(query, cmd_id))
if s > 0:
results.append(_command_item(cmd_id, caption, score=s))
results.sort(key=lambda item: item.get("Score", 0), reverse=True)
return results[:25]


def main() -> None:
request = json.loads(sys.argv[1]) if len(sys.argv) > 1 else {}
method = request.get("method", "query")
params = request.get("parameters", [])
if method == "query":
settings = _load_settings(request)
exe = _find_executable(settings)
delay_ms = _command_delay(settings)
results = handle_query(params[0] if params else "", exe)
# Flow supplies settings to queries, but forwards result actions as returned.
for result in results:
action = result["JsonRPCAction"]
if action["method"] == "restore_workspace":
action["parameters"].append(exe or "")
elif action["method"] == "run_command":
action["parameters"].extend([exe or "", delay_ms])
print(json.dumps({"result": results}))
elif method == "restore_workspace" and params:
exe = (params[1] or None) if len(params) > 1 else _find_executable(_load_settings(request))
wt_client.restore_workspace(exe, params[0])
elif method == "run_command" and params:
choice = params[1] if len(params) > 1 else ""
if len(params) > 3:
exe, delay_ms = params[2] or None, params[3]
else:
settings = _load_settings(request)
exe, delay_ms = _find_executable(settings), _command_delay(settings)
wt_client.run_command(exe, params[0], choice, delay_ms)
elif method == "launch_app" and params:
wt_client.launch_app(params[0])
elif method == "open_url" and params:
webbrowser.open(params[0])


if __name__ == "__main__":
main()
12 changes: 12 additions & 0 deletions integrations/flow-launcher/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"ID": "8F3A4B6C9D124E8BA7C32D5E6F1A9B04",
"ActionKeyword": "wt",
"Name": "WindowTabs",
"Description": "Switch workspaces and run WindowTabs commands",
"Author": "leafOfTree",
"Version": "1.0.0",
"Language": "python",
"Website": "https://windowtabs.app",
"IcoPath": "Images\\app.png",
"ExecuteFileName": "main.py"
}
89 changes: 89 additions & 0 deletions integrations/flow-launcher/tests/test_flow_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import contextlib
import io
import json
import pathlib
import sys
import tempfile
import unittest
from unittest.mock import patch

sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
import main as flow


class FlowSettingsTests(unittest.TestCase):
def setUp(self):
directory = tempfile.TemporaryDirectory()
self.addCleanup(directory.cleanup)
self.directory = pathlib.Path(directory.name)
module_path = patch.object(flow, "__file__", str(self.directory / "main.py"))
module_path.start()
self.addCleanup(module_path.stop)

def invoke(self, request):
output = io.StringIO()
with patch.object(sys, "argv", ["main.py", json.dumps(request)]):
with contextlib.redirect_stdout(output):
flow.main()
return json.loads(output.getvalue()) if output.getvalue() else None

def test_flow_settings_survive_separate_result_actions(self):
exe = r"C:\Portable Apps\WindowTabs.exe"
(self.directory / "settings.json").write_text(
json.dumps({"executable_path": "old.exe", "command_delay_ms": 50}),
encoding="utf-8",
)
with (
patch.object(flow.wt_client, "find_executable", return_value=exe) as find,
patch.object(flow.wt_client, "list_workspaces", return_value=["项目 A"]) as workspaces,
patch.object(flow.wt_client, "list_commands", return_value=[("next-tab", "Next tab")]) as commands,
patch.object(flow.wt_client, "restore_workspace") as restore,
patch.object(flow.wt_client, "run_command") as run,
):
result = self.invoke({
"method": "query",
"parameters": ["a"],
"settings": {"executable_path": exe, "command_delay_ms": "350"},
})["result"]
actions = {row["JsonRPCAction"]["method"]: row["JsonRPCAction"] for row in result}
self.assertEqual(actions["restore_workspace"]["parameters"], ["项目 A", exe])
self.invoke(actions["restore_workspace"])
self.invoke(actions["run_command"])
find.assert_called_once_with(exe)
workspaces.assert_called_once_with(exe)
commands.assert_called_once_with(exe)
restore.assert_called_once_with(exe, "项目 A")
run.assert_called_once_with(exe, "next-tab", "", 350)

def test_legacy_action_keeps_local_settings(self):
(self.directory / "settings.json").write_text(
json.dumps({"executable_path": "local.exe", "command_delay_ms": 0}),
encoding="utf-8",
)
with (
patch.object(flow.wt_client, "find_executable", return_value="local.exe") as find,
patch.object(flow.wt_client, "run_command") as run,
):
self.invoke({"method": "run_command", "parameters": ["next-tab", ""]})
find.assert_called_once_with("local.exe")
run.assert_called_once_with("local.exe", "next-tab", "", 0)

def test_invalid_flow_delay_uses_default(self):
with (
patch.object(flow.wt_client, "find_executable", return_value=None) as find,
patch.object(flow.wt_client, "list_workspaces", return_value=[]),
patch.object(flow.wt_client, "list_commands", return_value=[("next-tab", "Next tab")]),
patch.object(flow.wt_client, "run_command") as run,
):
result = self.invoke({
"method": "query",
"parameters": ["cmd next-tab"],
"settings": {"executable_path": None, "command_delay_ms": "invalid"},
})["result"]
self.invoke(result[0]["JsonRPCAction"])
find.assert_called_once_with("")
run.assert_called_once_with(None, "next-tab", "", 120)


if __name__ == "__main__":
unittest.main()
49 changes: 49 additions & 0 deletions integrations/flow-launcher/tests/test_wt_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import ctypes
import pathlib
import subprocess
import sys
import unittest
from unittest.mock import patch

sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
import wt_client as wt


class ClientTests(unittest.TestCase):
@unittest.skipUnless(sys.platform == "win32", "Win32 ABI")
def test_handle_types(self):
from ctypes import wintypes as W
k = wt._kernel32()
self.assertIs(k.CreateFileW.restype, W.HANDLE)
for fn in (k.ReadFile, k.WriteFile, k.CloseHandle):
self.assertIs(fn.argtypes[0], W.HANDLE)
self.assertEqual(wt.INVALID_HANDLE_VALUE, ctypes.c_void_p(-1).value)

def test_listing(self):
names = ["项目 A", "仕事用", "업무 공간", "مشروع", "Cafe\u0301", " 🚀 "]
for reply in [(True, "\n".join(names)), (True, ""), (False, "error")]:
with patch.object(wt, "send_pipe", return_value=reply), patch.object(wt, "_run_cli") as cli:
self.assertEqual(wt.list_workspaces("wt.exe"), names if reply[0] and reply[1] else [])
cli.assert_not_called()
with patch.object(wt, "send_pipe", return_value=None), patch.object(wt, "_run_cli", return_value="\r\n".join(names)) as cli:
self.assertEqual(wt.list_workspaces("wt.exe"), names)
cli.assert_called_once_with("wt.exe", ["--workspaces"])

def test_cli_failure(self):
with patch.object(wt, "send_pipe", return_value=None), patch.object(wt, "_run_cli", side_effect=subprocess.CalledProcessError(1, "wt")):
self.assertEqual(wt.list_workspaces("wt.exe"), [])

def test_no_replay(self):
with patch.object(wt, "send_pipe", return_value=(False, "reply lost")), patch.object(wt.subprocess, "Popen") as spawn:
wt.restore_workspace("wt.exe", "项目 🚀")
wt.run_command("wt.exe", "next-tab", delay_ms=0)
spawn.assert_not_called()

def test_missing_pipe_restore(self):
with patch.object(wt, "send_pipe", return_value=None), patch.object(wt.subprocess, "Popen") as spawn:
wt.restore_workspace("wt.exe", "项目 🚀")
self.assertEqual(spawn.call_args.args[0], ["wt.exe", "--workspace", "项目 🚀"])


if __name__ == "__main__":
unittest.main()
Loading
Loading