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:
2828 run: |
2929 ./Build/buildlinux
3030
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
3147 - name: Revert Changes in player.go
3248 run: |
3349 git checkout -- internal/player.go
@@ -43,8 +59,9 @@ jobs:
4359 path: |
4460 Build/curd
4561 Build/curd.exe
46 retention-days: 1 # Set retention period
47 if-no-files-found: error # Fail if files are not found
62 Build/macos/curd
63 retention-days: 1
64 if-no-files-found: error
4865
4966 - name: List Build Directory
5067 run: |
@@ -121,6 +138,7 @@ jobs:
121138 files: |
122139 Build/curd
123140 Build/curd.exe
141 Build/macos/curd
124142 Build/Output/CurdInstaller.exe
125143 env:
126144 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
55release_folder="releases/curd-$version"
66windows_folder="$release_folder/windows"
77linux_folder="$release_folder/linux"
8macos_folder="$release_folder/macos"
89installer_script="Build/curd-windows-build.iss"
910
1011# Ensure required directories exist
11mkdir -p "$windows_folder" "$linux_folder"
12mkdir -p "$windows_folder" "$linux_folder" "$macos_folder"
1213mkdir -p "$windows_folder/bin"
1314
1415# Uncompress mpv.exe.gz
@@ -34,6 +35,29 @@ else
3435 exit 1
3536fi
3637
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
3761# Build Windows binary
3862echo "Building Windows binary..."
3963bash Build/buildwindows
internal/config.go +67 −52
@@ -177,59 +177,74 @@ func createDefaultConfig(path string) error {
177177 return nil
178178}
179179
180func ChangeToken(config *CurdConfig, user *User) {
181 var err error
182 tokenPath := filepath.Join(os.ExpandEnv(config.StoragePath), "token")
183
184 if runtime.GOOS == "windows" {
185 // Create a temporary file for the token
186 tempFile, err := os.CreateTemp("", "curd-token-*.txt")
187 if err != nil {
188 Log("Error creating temp file: "+err.Error(), logFile)
189 ExitCurd(err)
190 }
191 tempPath := tempFile.Name()
192 tempFile.Close()
193
194 // Write instructions to the temp file
195 instructions := "Please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token\n" +
196 "Replace this text with your token and save the file.\n"
197 if err := os.WriteFile(tempPath, []byte(instructions), 0644); err != nil {
198 Log("Error writing instructions: "+err.Error(), logFile)
199 ExitCurd(err)
200 }
201
202 // Open notepad with the temp file
203 cmd := exec.Command("notepad.exe", tempPath)
204 if err := cmd.Run(); err != nil {
205 Log("Error opening notepad: "+err.Error(), logFile)
206 ExitCurd(err)
207 }
208
209 // Read the token from the file
210 content, err := os.ReadFile(tempPath)
211 if err != nil {
212 Log("Error reading token: "+err.Error(), logFile)
213 ExitCurd(err)
214 }
215
216 // Clean up the temp file
217 os.Remove(tempPath)
218
219 // Extract token (remove instructions and whitespace)
220 user.Token = strings.TrimSpace(string(content))
221 } else if config.RofiSelection {
222 user.Token, err = GetTokenFromRofi()
223 } else {
224 fmt.Println("Please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token")
225 fmt.Scanln(&user.Token)
226 }
180func getTokenFromTempFile(isWindowsPlatform bool) (string, error) {
181 // Create a temporary file for the token
182 tempFile, err := os.CreateTemp("", "curd-token-*.txt")
183 if err != nil {
184 return "", fmt.Errorf("error creating temp file: %v", err)
185 }
186 tempPath := tempFile.Name()
187 tempFile.Close()
188
189 // Write instructions to the temp file
190 instructions := "Please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token\n" +
191 "Replace this text with your token and save the file.\n"
192 if err := os.WriteFile(tempPath, []byte(instructions), 0644); err != nil {
193 return "", fmt.Errorf("error writing instructions: %v", err)
194 }
195
196 // Open the file with appropriate editor
197 var cmd *exec.Cmd
198 if isWindowsPlatform {
199 cmd = exec.Command("notepad.exe", tempPath)
200 } else {
201 editor := os.Getenv("EDITOR")
202 if editor == "" {
203 editor = "nano" // Default to nano if $EDITOR is not set
204 }
205 cmd = exec.Command(editor, tempPath)
206 cmd.Stdin = os.Stdin
207 cmd.Stdout = os.Stdout
208 cmd.Stderr = os.Stderr
209 }
210
211 if err := cmd.Run(); err != nil {
212 return "", fmt.Errorf("error opening editor: %v", err)
213 }
214
215 // Read the token from the file
216 content, err := os.ReadFile(tempPath)
217 if err != nil {
218 return "", fmt.Errorf("error reading token: %v", err)
219 }
220
221 // Clean up the temp file
222 os.Remove(tempPath)
223
224 // Extract token (remove instructions and whitespace)
225 return strings.TrimSpace(string(content)), nil
226}
227227
228 if err != nil {
229 Log("Error getting user input: "+err.Error(), logFile)
230 ExitCurd(err)
231 }
232 WriteTokenToFile(user.Token, tokenPath)
228func ChangeToken(config *CurdConfig, user *User) {
229 var err error
230 tokenPath := filepath.Join(os.ExpandEnv(config.StoragePath), "token")
231
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)
233248}
234249
235250// Load config file from disk into a map (key=value format)