Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
Add support for flatpak versions of MPV and VLC (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkgranli authored Oct 13, 2021
1 parent 09b0db7 commit afb883f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
30 changes: 18 additions & 12 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ type Store struct {
type commandAndArgs []string

type Command struct {
Title string `json:"title"`
Command commandAndArgs `json:"command"`
Proxy bool `json:"proxy"`
registry string
registry32 string
Title string `json:"title"`
Command commandAndArgs `json:"command"`
Proxy bool `json:"proxy"`
registry string
registry32 string
flatpakAppID string
}

type MultiCommand struct {
Expand Down Expand Up @@ -83,15 +84,17 @@ func NewStore(customCommands []Command, multiCommands []MultiCommand, lang strin

commands := []Command{
{
Title: "Play with MPV",
Command: []string{"mpv", "$url", "--alang=" + lang, "--quiet", "--title=$title"},
Proxy: true,
Title: "Play with MPV",
Command: []string{"mpv", "$url", "--alang=" + lang, "--quiet", "--title=$title"},
Proxy: true,
flatpakAppID: "io.mpv.Mpv",
},
{
Title: "Play with VLC",
registry: "SOFTWARE\\WOW6432Node\\VideoLAN\\VLC",
registry32: "SOFTWARE\\VideoLAN\\VLC",
Command: []string{"vlc", "$url", "--meta-title=$title", "--audio-language=" + lang},
Title: "Play with VLC",
registry: "SOFTWARE\\WOW6432Node\\VideoLAN\\VLC",
registry32: "SOFTWARE\\VideoLAN\\VLC",
Command: []string{"vlc", "$url", "--meta-title=$title", "--audio-language=" + lang},
flatpakAppID: "org.videolan.VLC",
},
{
Title: "Play with IINA",
Expand All @@ -106,6 +109,8 @@ func NewStore(customCommands []Command, multiCommands []MultiCommand, lang strin
store.Commands = append(store.Commands, c)
} else if c, found := checkRegistry(c); found {
store.Commands = append(store.Commands, c)
} else if c, found := checkFlatpak(c); found {
store.Commands = append(store.Commands, c)
}
}

Expand Down Expand Up @@ -198,6 +203,7 @@ func (s *Store) RunCommand(cc CommandContext) error {
tmpCommand[i] = strings.ReplaceAll(tmpCommand[i], "$hour", cc.MetaData.Date.Format("15"))
tmpCommand[i] = strings.ReplaceAll(tmpCommand[i], "$minute", cc.MetaData.Date.Format("04"))
}

return s.runCmd(exec.Command(tmpCommand[0], tmpCommand[1:]...), proxyEnabled, cancel)
}

Expand Down
5 changes: 5 additions & 0 deletions internal/cmd/registry.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package cmd
Expand Down Expand Up @@ -31,3 +32,7 @@ func checkRegistry(c Command) (Command, bool) {

return c, true
}

func checkFlatpak(c Command) (Command, bool) {
return c, false
}
27 changes: 27 additions & 0 deletions internal/cmd/registry_unix.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
//go:build !windows
// +build !windows

package cmd

import "os/exec"

func checkRegistry(c Command) (Command, bool) {
_ = c.registry
_ = c.registry32
return c, false
}

func checkFlatpak(c Command) (Command, bool) {
if c.flatpakAppID == "" {
// command is not flatpak
return c, false
}

_, err := exec.LookPath("flatpak")
if err != nil {
// flatpak not installed
return c, false
}

err = exec.Command("flatpak", "info", c.flatpakAppID).Run()
if err != nil {
// package not installed
return c, false
}

c.Command[0] = c.flatpakAppID
c.Command = append([]string{"flatpak", "run"}, c.Command...)

return c, true
}

0 comments on commit afb883f

Please sign in to comment.