feat(url): optional browser field (yandex/chrome/firefox/edge)
Adds optional 'browser' field to url-action; runtime resolves it via config.BROWSER_PATHS (subprocess.Popen with the chosen exe). When omitted, falls back to webbrowser.open (system default). Constructor GUI gains a browser dropdown on URL action and on multi-step URL. Existing open_browser/youtube/google updated to use yandex by default since user prefers Yandex Browser.
This commit is contained in:
parent
d22a35c9c7
commit
a4171ec6b1
5 changed files with 65 additions and 12 deletions
|
|
@ -65,13 +65,20 @@ class ShellAction:
|
|||
return out
|
||||
|
||||
|
||||
KNOWN_BROWSERS = ("yandex", "chrome", "firefox", "edge")
|
||||
|
||||
|
||||
@dataclass
|
||||
class UrlAction:
|
||||
href: str
|
||||
browser: Optional[str] = None
|
||||
type: str = "url"
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {"type": "url", "href": self.href}
|
||||
out: dict = {"type": "url", "href": self.href}
|
||||
if self.browser:
|
||||
out["browser"] = self.browser
|
||||
return out
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -157,7 +164,10 @@ def action_from_dict(data: Any) -> Action:
|
|||
href = data.get("href")
|
||||
if not href or not isinstance(href, str):
|
||||
raise SchemaError("url action requires non-empty 'href' string")
|
||||
return UrlAction(href=href)
|
||||
browser = data.get("browser")
|
||||
if browser is not None and browser not in KNOWN_BROWSERS:
|
||||
raise SchemaError(f"url.browser must be one of {KNOWN_BROWSERS} or omitted")
|
||||
return UrlAction(href=href, browser=browser)
|
||||
if t == "keys":
|
||||
sequence = data.get("sequence")
|
||||
text = data.get("text")
|
||||
|
|
|
|||
|
|
@ -191,10 +191,25 @@
|
|||
<label>URL</label>
|
||||
<input type="text" id="url-href" placeholder="https://example.com">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Браузер</label>
|
||||
<select id="url-browser">
|
||||
<option value="">по умолчанию (системный)</option>
|
||||
<option value="yandex">Yandex Browser</option>
|
||||
<option value="chrome">Google Chrome</option>
|
||||
<option value="firefox">Mozilla Firefox</option>
|
||||
<option value="edge">Microsoft Edge</option>
|
||||
</select>
|
||||
</div>
|
||||
`;
|
||||
const inp = f.querySelector("#url-href");
|
||||
if (state.action) inp.value = state.action.href || "";
|
||||
const sel = f.querySelector("#url-browser");
|
||||
if (state.action) {
|
||||
inp.value = state.action.href || "";
|
||||
sel.value = state.action.browser || "";
|
||||
}
|
||||
inp.addEventListener("input", () => updateAction());
|
||||
sel.addEventListener("change", () => updateAction());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -481,8 +496,23 @@
|
|||
inp.type = "text";
|
||||
inp.value = step.href || "";
|
||||
inp.placeholder = "https://...";
|
||||
inp.addEventListener("input", () => onChange({ type: "url", href: inp.value }));
|
||||
const sel = document.createElement("select");
|
||||
sel.innerHTML = `
|
||||
<option value="">по умолчанию (системный)</option>
|
||||
<option value="yandex">Yandex Browser</option>
|
||||
<option value="chrome">Google Chrome</option>
|
||||
<option value="firefox">Mozilla Firefox</option>
|
||||
<option value="edge">Microsoft Edge</option>`;
|
||||
sel.value = step.browser || "";
|
||||
const apply = () => {
|
||||
const next = { type: "url", href: inp.value };
|
||||
if (sel.value) next.browser = sel.value;
|
||||
onChange(next);
|
||||
};
|
||||
inp.addEventListener("input", apply);
|
||||
sel.addEventListener("change", apply);
|
||||
body.appendChild(wrapField("URL", inp));
|
||||
body.appendChild(wrapField("Браузер", sel));
|
||||
} else if (t === "keys") {
|
||||
const inp = document.createElement("input");
|
||||
inp.type = "text";
|
||||
|
|
@ -569,7 +599,10 @@
|
|||
if (delay && delay.value) a.delay_ms = parseInt(delay.value, 10);
|
||||
state.action = a;
|
||||
} else if (t === "url") {
|
||||
state.action = { type: "url", href: (document.getElementById("url-href")||{}).value || "" };
|
||||
const a = { type: "url", href: (document.getElementById("url-href")||{}).value || "" };
|
||||
const b = (document.getElementById("url-browser")||{}).value;
|
||||
if (b) a.browser = b;
|
||||
state.action = a;
|
||||
} else if (t === "keys") {
|
||||
const mode = (document.getElementById("keys-mode")||{}).value;
|
||||
if (mode === "text") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue