Skip to content

Commit

Permalink
Fix active player option handling (fixes #40)
Browse files Browse the repository at this point in the history
Leonardo Baldin committed Dec 25, 2024
1 parent 4934ce2 commit 250c398
Showing 6 changed files with 22 additions and 17 deletions.
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SRC := config.go ipc.go options.go $(wildcard cmd/open-in-mpv/*)
EXT_SRC := $(wildcard extension/Chrome/*) extension/Firefox/manifest.json
SCRIPTS_DIR := scripts
PREFIX := /usr/bin

TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
@@ -55,7 +56,7 @@ $(BUILD_DIR)/mac/open-in-mpv.app: $(SRC) scripts/Info.plist $(BUILD_DIR)
cp $(SCRIPTS_DIR)/Info.plist $@/Contents

$(BUILD_DIR)/mac.tar: $(BUILD_DIR)/mac/open-in-mpv.app
tar cf $@ -C $(dir $@)/mac open-in-mpv.app
tar cf $@ -C $(dir $@)mac open-in-mpv.app

$(BUILD_DIR)/windows/open-in-mpv.exe: $(SRC) $(BUILD_DIR)
@echo -e "\n# Building for Windows"
@@ -65,14 +66,15 @@ $(BUILD_DIR)/windows/open-in-mpv.exe: $(SRC) $(BUILD_DIR)
$(BUILD_DIR)/windows.tar: $(BUILD_DIR)/windows/open-in-mpv.exe
tar cf $@ -C $(dir $@)windows $(notdir $(wildcard $(BUILD_DIR)/windows/*))

$(BUILD_DIR)/firefox.zip: $(EXT_SRC)
@mkdir -p build
$(BUILD_DIR)/firefox.zip: $(BUILD_DIR) $(EXT_SRC)
sed -i 's/"version": .*"/"version": '\"$(VERSION)\"'/g' extension/Chrome/manifest.json
cp extension/Chrome/{*.html,*.js,*.png,*.css} extension/Firefox
sed -i 's/"version": .*"/"version": '\"$(VERSION)\"'/g' extension/Firefox/manifest.json
zip -j $@ extension/Firefox/*
@rm extension/Firefox/{*.html,*.js,*.png,*.css}

install: $(BUILD_DIR)/linux/open-in-mpv
cp $(BUILD_DIR)/linux/open-in-mpv /usr/bin
cp $(BUILD_DIR)/linux/open-in-mpv $(PREFIX)

install-protocol:
$(SCRIPTS_DIR)/install-protocol.sh
1 change: 1 addition & 0 deletions extension/Chrome/background.js
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ chrome.action.onClicked.addListener(() => {
getOptions((options) => {
openInMPV(tab.id, tab.url, {
mode: options.iconActionOption,
...options,
});
});
});
2 changes: 1 addition & 1 deletion extension/Chrome/common.js
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ export function openInMPV(tabId, url, options = {}) {
if (options.useCustomFlags && options.customFlags !== "")
params.push(`flags=${encodeURIComponent(options.customFlags)}`)

// TODO: test, xpinstall.signatures.required to false
console.log("Opening URL:", { baseURL, params })
chrome.scripting.executeScript({
target: { tabId },
func: openLink,
2 changes: 1 addition & 1 deletion extension/Chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "Open In MPV",
"description": "Open videos and audio files in mpv.",
"version": "2.1.0",
"version": "2.4.1",
"options_page": "options.html",
"background": {
"service_worker": "background.js",
22 changes: 12 additions & 10 deletions extension/Chrome/popup.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { openInMPV } from "./common.js";
import { getOptions, openInMPV } from "./common.js";

Array.prototype.forEach.call(document.getElementsByClassName("menu-item"), (item) => {
const mode = item.id.split("-")[1];
item.addEventListener("click", () => {
chrome.tabs.query({ currentWindow: true, active: true }, (tabs) => {
if (tabs.length === 0) { return; }
const tab = tabs[0];
if (tab.id === chrome.tabs.TAB_ID_NONE) { return; }
console.log(mode)
openInMPV(tab.id, tab.url, {
mode,
newWindow: mode === "newWindow",
getOptions((options) => {
chrome.tabs.query({ currentWindow: true, active: true }, (tabs) => {
if (tabs.length === 0) { return; }
const tab = tabs[0];
if (tab.id === chrome.tabs.TAB_ID_NONE) { return; }
openInMPV(tab.id, tab.url, {
mode,
newWindow: mode === "newWindow",
...options,
});
});
});
})
});
});
2 changes: 1 addition & 1 deletion extension/Firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
},
"name": "Open In mpv",
"description": "Open videos and audio files in mpv.",
"version": "2.1.0",
"version": "2.4.1",
"options_ui": {
"page": "options.html"
},

0 comments on commit 250c398

Please sign in to comment.