Commit 3b5b246800

3b5b246800f86276a498d9b7820a3dab977ea371

parent: 2b609e9bec

Unregistered key

chokerman <44473782+justchokingaround@users.noreply.github.com> · 2025-02-05 15:47 UTC
committer: <noreply@github.com>

mac: add builds and fix first token input (#34)

Layout: unified · split

.github/workflows/ci-cd.yml +20 −2
@@ -28,6 +28,22 @@ jobs:
28 run: | 28 run: |
29 ./Build/buildlinux 29 ./Build/buildlinux
30 30
31 - name: Build macOS Intel binary
32 run: |
33 ./Build/buildmac
34
35 - name: Build macOS ARM64 binary
36 run: |
37 ./Build/buildmac-arm64
38
39 - name: Create Universal macOS binary
40 run: |
41 mkdir -p Build/macos
42 mv curd Build/macos/curd-amd64
43 mv curd-arm64 Build/macos/curd-arm64
44 lipo -create Build/macos/curd-amd64 Build/macos/curd-arm64 -output Build/macos/curd
45 rm Build/macos/curd-amd64 Build/macos/curd-arm64
46
31 - name: Revert Changes in player.go 47 - name: Revert Changes in player.go
32 run: | 48 run: |
33 git checkout -- internal/player.go 49 git checkout -- internal/player.go
@@ -43,8 +59,9 @@ jobs:
43 path: | 59 path: |
44 Build/curd 60 Build/curd
45 Build/curd.exe 61 Build/curd.exe
46 retention-days: 1 # Set retention period 62 Build/macos/curd
47 if-no-files-found: error # Fail if files are not found 63 retention-days: 1
64 if-no-files-found: error
48 65
49 - name: List Build Directory 66 - name: List Build Directory
50 run: | 67 run: |
@@ -121,6 +138,7 @@ jobs:
121 files: | 138 files: |
122 Build/curd 139 Build/curd
123 Build/curd.exe 140 Build/curd.exe
141 Build/macos/curd
124 Build/Output/CurdInstaller.exe 142 Build/Output/CurdInstaller.exe
125 env: 143 env:
126 GITHUB_TOKEN: ${{ secrets.ACTIONS_PAT }} 144 GITHUB_TOKEN: ${{ secrets.ACTIONS_PAT }}
Build/buildmac added +1
@@ -0,0 +1 @@
1CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o curd -ldflags="-s -w" -trimpath cmd/curd/main.go\ No newline at end of file
Build/buildmac-arm64 added +1
@@ -0,0 +1 @@
1CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o curd -ldflags="-s -w" -trimpath cmd/curd/main.go\ No newline at end of file
Build/release +25 −1
@@ -5,10 +5,11 @@ read -p "Enter the version number: " version
5release_folder="releases/curd-$version" 5release_folder="releases/curd-$version"
6windows_folder="$release_folder/windows" 6windows_folder="$release_folder/windows"
7linux_folder="$release_folder/linux" 7linux_folder="$release_folder/linux"
8macos_folder="$release_folder/macos"
8installer_script="Build/curd-windows-build.iss" 9installer_script="Build/curd-windows-build.iss"
9 10
10# Ensure required directories exist 11# Ensure required directories exist
11mkdir -p "$windows_folder" "$linux_folder" 12mkdir -p "$windows_folder" "$linux_folder" "$macos_folder"
12mkdir -p "$windows_folder/bin" 13mkdir -p "$windows_folder/bin"
13 14
14# Uncompress mpv.exe.gz 15# Uncompress mpv.exe.gz
@@ -34,6 +35,29 @@ else
34 exit 1 35 exit 1
35fi 36fi
36 37
38# Build macOS binaries
39echo "Building macOS binaries..."
40bash Build/buildmac
41if [ -f "curd" ]; then
42 mv curd "$macos_folder/curd-amd64"
43else
44 echo "macOS Intel build failed. Please check Build/buildmac."
45 exit 1
46fi
47
48bash Build/buildmac-arm64
49if [ -f "curd" ]; then
50 mv curd "$macos_folder/curd-arm64"
51else
52 echo "macOS ARM build failed. Please check Build/buildmac-arm64."
53 exit 1
54fi
55
56# Create Universal binary for macOS
57echo "Creating macOS Universal binary..."
58lipo -create "$macos_folder/curd-amd64" "$macos_folder/curd-arm64" -output "$macos_folder/curd"
59rm "$macos_folder/curd-amd64" "$macos_folder/curd-arm64"
60
37# Build Windows binary 61# Build Windows binary
38echo "Building Windows binary..." 62echo "Building Windows binary..."
39bash Build/buildwindows 63bash Build/buildwindows
internal/config.go +67 −52
@@ -177,59 +177,74 @@ func createDefaultConfig(path string) error {
177 return nil 177 return nil
178} 178}
179 179
180func ChangeToken(config *CurdConfig, user *User) { 180func getTokenFromTempFile(isWindowsPlatform bool) (string, error) {
181 var err error 181 // Create a temporary file for the token
182 tokenPath := filepath.Join(os.ExpandEnv(config.StoragePath), "token") 182 tempFile, err := os.CreateTemp("", "curd-token-*.txt")
183 183 if err != nil {
184 if runtime.GOOS == "windows" { 184 return "", fmt.Errorf("error creating temp file: %v", err)
185 // Create a temporary file for the token 185 }
186 tempFile, err := os.CreateTemp("", "curd-token-*.txt") 186 tempPath := tempFile.Name()
187 if err != nil { 187 tempFile.Close()
188 Log("Error creating temp file: "+err.Error(), logFile) 188
189 ExitCurd(err) 189 // Write instructions to the temp file
190 } 190 instructions := "Please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token\n" +
191 tempPath := tempFile.Name() 191 "Replace this text with your token and save the file.\n"
192 tempFile.Close() 192 if err := os.WriteFile(tempPath, []byte(instructions), 0644); err != nil {
193 193 return "", fmt.Errorf("error writing instructions: %v", err)
194 // Write instructions to the temp file 194 }
195 instructions := "Please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token\n" + 195
196 "Replace this text with your token and save the file.\n" 196 // Open the file with appropriate editor
197 if err := os.WriteFile(tempPath, []byte(instructions), 0644); err != nil { 197 var cmd *exec.Cmd
198 Log("Error writing instructions: "+err.Error(), logFile) 198 if isWindowsPlatform {
199 ExitCurd(err) 199 cmd = exec.Command("notepad.exe", tempPath)
200 } 200 } else {
201 201 editor := os.Getenv("EDITOR")
202 // Open notepad with the temp file 202 if editor == "" {
203 cmd := exec.Command("notepad.exe", tempPath) 203 editor = "nano" // Default to nano if $EDITOR is not set
204 if err := cmd.Run(); err != nil { 204 }
205 Log("Error opening notepad: "+err.Error(), logFile) 205 cmd = exec.Command(editor, tempPath)
206 ExitCurd(err) 206 cmd.Stdin = os.Stdin
207 } 207 cmd.Stdout = os.Stdout
208 208 cmd.Stderr = os.Stderr
209 // Read the token from the file 209 }
210 content, err := os.ReadFile(tempPath) 210
211 if err != nil { 211 if err := cmd.Run(); err != nil {
212 Log("Error reading token: "+err.Error(), logFile) 212 return "", fmt.Errorf("error opening editor: %v", err)
213 ExitCurd(err) 213 }
214 } 214
215 215 // Read the token from the file
216 // Clean up the temp file 216 content, err := os.ReadFile(tempPath)
217 os.Remove(tempPath) 217 if err != nil {
218 218 return "", fmt.Errorf("error reading token: %v", err)
219 // Extract token (remove instructions and whitespace) 219 }
220 user.Token = strings.TrimSpace(string(content)) 220
221 } else if config.RofiSelection { 221 // Clean up the temp file
222 user.Token, err = GetTokenFromRofi() 222 os.Remove(tempPath)
223 } else { 223
224 fmt.Println("Please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token") 224 // Extract token (remove instructions and whitespace)
225 fmt.Scanln(&user.Token) 225 return strings.TrimSpace(string(content)), nil
226 } 226}
227 227
228 if err != nil { 228func ChangeToken(config *CurdConfig, user *User) {
229 Log("Error getting user input: "+err.Error(), logFile) 229 var err error
230 ExitCurd(err) 230 tokenPath := filepath.Join(os.ExpandEnv(config.StoragePath), "token")
231 } 231
232 WriteTokenToFile(user.Token, tokenPath) 232 switch {
233 case runtime.GOOS == "darwin" || runtime.GOOS == "windows":
234 user.Token, err = getTokenFromTempFile(runtime.GOOS == "windows")
235 case config.RofiSelection:
236 user.Token, err = GetTokenFromRofi()
237 default:
238 fmt.Println("Please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token")
239 fmt.Scanln(&user.Token)
240 }
241
242 if err != nil {
243 Log("Error getting user input: "+err.Error(), logFile)
244 ExitCurd(err)
245 }
246
247 WriteTokenToFile(user.Token, tokenPath)
233} 248}
234 249
235// Load config file from disk into a map (key=value format) 250// Load config file from disk into a map (key=value format)