Skip to content

Commit

Permalink
Life update: Platform specific code only compilies for specific platf…
Browse files Browse the repository at this point in the history
…orm.
  • Loading branch information
Wraient committed Jan 22, 2025
1 parent a47582d commit 21362d4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 38 deletions.
27 changes: 0 additions & 27 deletions Build/release
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
#!/bin/bash

# Function to comment/uncomment lines in internal/player.go
function toggle_winio_import() {
local action="$1"
local file="internal/player.go"

if [ "$action" == "comment" ]; then
# Comment out the go-winio import line
sed -i 's|^\(\s*"github.com/Microsoft/go-winio"\)|// \1|' "$file"
# Comment out the usage of winio.DialPipe
sed -i 's|^\(.*conn, err = winio.DialPipe.*\)|// \1|' "$file"
elif [ "$action" == "uncomment" ]; then
# Uncomment the go-winio import line
sed -i 's|// \(\s*"github.com/Microsoft/go-winio"\)|\1|' "$file"
# Uncomment the usage of winio.DialPipe
sed -i 's|^// \(.*conn, err = winio.DialPipe.*\)|\1|' "$file"
fi
}


# Ask for version number
read -p "Enter the version number: " version
release_folder="releases/curd-$version"
Expand All @@ -36,10 +17,6 @@ sed -i "s/^AppVersion=.*/AppVersion=$version/" "$installer_script"
sed -i "s|Source: \".*curd.exe\"|Source: \"Z:$windows_folder/curd.exe\"|" "$installer_script"
# sed -i "s|Source: \".*mpv.exe\"|Source: \"Z:$windows_folder/mpv.exe\"|" "$installer_script"

# Comment out winio-related lines for Linux build
echo "Commenting out go-winio lines for Linux build..."
toggle_winio_import "comment"

# Build Linux binary
echo "Building Linux binary..."
bash Build/buildlinux
Expand All @@ -52,10 +29,6 @@ else
exit 1
fi

# Uncomment winio-related lines after Linux build
echo "Uncommenting go-winio lines..."
toggle_winio_import "uncomment"

# Build Windows binary
echo "Building Windows binary..."
bash Build/buildwindows
Expand Down
12 changes: 1 addition & 11 deletions internal/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import (
"crypto/rand"
"encoding/json"
"fmt"
"net"
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/Microsoft/go-winio"
)
var logFile = "debug.log"

Expand Down Expand Up @@ -94,15 +92,7 @@ func joinArgs(args []string) string {
}

func MPVSendCommand(ipcSocketPath string, command []interface{}) (interface{}, error) {
var conn net.Conn
var err error

if runtime.GOOS == "windows" {
// Use named pipe for Windows
conn, err = winio.DialPipe(ipcSocketPath, nil)
} else {
conn, err = net.Dial("unix", ipcSocketPath)
}
conn, err := connectToPipe(ipcSocketPath)
if err != nil {
return nil, err
}
Expand Down
16 changes: 16 additions & 0 deletions internal/unix_ipc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build !windows
// +build !windows

package internal

import (
"net"
)

func connectToPipe(ipcSocketPath string) (net.Conn, error) {
conn, err := net.Dial("unix", ipcSocketPath)
if err != nil {
return nil, err
}
return conn, nil
}
18 changes: 18 additions & 0 deletions internal/windows_ipc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build windows
// +build windows

package internal

import (
"net"

"github.com/Microsoft/go-winio"
)

func connectToPipe(ipcSocketPath string) (net.Conn, error) {
conn, err := winio.DialPipe(ipcSocketPath, nil)
if err != nil {
return nil, err
}
return conn, nil
}

0 comments on commit 21362d4

Please sign in to comment.