-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclipboardUtils.go
104 lines (74 loc) · 2.91 KB
/
clipboardUtils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"github.com/atotto/clipboard"
"time"
)
// eraseClipboard clears the contents of the clipboard if the erase parameter is true.
// The function takes two input parameters:
//
// erase - a boolean value indicating whether the clipboard should be cleared
// err - an error value that will be updated during the clearing process
//
// The function returns two boolean values:
//
// success - indicating whether the clipboard was cleared successfully
// hasError - indicating whether an error occurred during the clearing process
func eraseClipboard(erase bool, err error) (success bool, hasError bool) {
// If the value of the erase parameter is true
if erase {
fmt.Println("Waiting for 60 seconds before clearing the clipboard.")
// Start the progress bar goroutine
progressBarStartStopChannel := make(chan bool)
if OS == "darwin" || OS == "linux" || OS == "unix" {
go progressBarUnix(progressBarStartStopChannel)
} else if OS == "windows" {
go progressBarWindows(progressBarStartStopChannel)
}
time.Sleep(60 * time.Second)
// Clear the contents of the clipboard
err = clipboard.WriteAll("")
// Send a value to the channel to stop the progress bar
progressBarStartStopChannel <- true
if err != nil {
fmt.Println("Error: Unable to clear the clipboard:", err)
// If there is an error during the clearing process, the function returns false
// and true to indicate that the operation was not successful and that an error
// occurred.
return false, true
}
fmt.Println("Clipboard has been cleared.")
}
// If the erase parameter is false, the function simply returns
// false and false, indicating that no action was taken.
return false, false
}
// copyToClipboard copies the selected password to the system clipboard and
// optionally erases the clipboard contents based on the value of the erase parameter.
// The function takes two input parameters:
//
// erase - a pointer to a boolean value indicating whether the clipboard should be cleared
// arrayPasswords - a string array containing the available passwords to choose from
//
// The function returns a boolean value indicating whether an error occurred during the process:
// - if an error occurs, the function returns true.
// - if the operation is successful, the function returns false.
func copyToClipboard(erase *bool, arrayPasswords []string) (copyErroredOut bool) {
//fmt.Printf("Selected password number is: %d\n", selectedPasswordNumber)
//
//fmt.Printf("Array is: %s\n", arrayPasswords)
// Copy the selected password to the clipboard
err := clipboard.WriteAll(arrayPasswords[selectedPasswordNumber])
if err != nil {
fmt.Println("Error: copying password to clipboard:", err)
return true
}
fmt.Println("Input has been copied to clipboard.")
if *erase {
clipboardData, clipboardCleared := eraseClipboard(true, err)
if clipboardCleared {
return clipboardData
}
}
return false
}