[v3 linux] implement single_instance plugin

This commit is contained in:
Travis McLane 2023-09-28 15:53:28 -05:00
commit 8e2527ad35
4 changed files with 26 additions and 12 deletions

View file

@ -269,7 +269,7 @@ func hideAllWindows(application pointer) {
func showAllWindows(application pointer) {
for _, window := range getWindows(application) {
C.gtk_widget_show_all((*C.GtkWidget)(window))
C.gtk_window_present((*C.GtkWindow)(window))
}
}

View file

@ -1,6 +1,6 @@
# single-instance Plugin
This example plugin provides a way to generate hashes of strings.
This plugin provides a way to prevent multiple launches of your application.
## Installation
@ -28,4 +28,4 @@ Please do not contact the Wails team for support.
## Credit
This plugin contains modified code from the awesome [go-singleinstance](https://github.com/allan-simon/go-singleinstance) module (c) 2015 Allan Simon.
Original license file has been renamed `go-singleinstance.LICENSE` and is available [here](./singleinstance_LICENSE).
Original license file has been renamed `go-singleinstance.LICENSE` and is available [here](./singleinstance_LICENSE).

View file

@ -2,9 +2,10 @@ package single_instance
import (
"fmt"
"github.com/wailsapp/wails/v3/pkg/application"
"os"
"path/filepath"
"github.com/wailsapp/wails/v3/pkg/application"
)
type Config struct {

View file

@ -2,16 +2,29 @@
package single_instance
/*
#cgo CFLAGS:
#cgo LDFLAGS:
import (
"fmt"
"os"
"os/signal"
"syscall"
*/
import "C"
import "fmt"
"github.com/wailsapp/wails/v3/pkg/application"
)
func init() {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc,
syscall.SIGUSR2,
)
go func() {
for {
s := <-sigc
application.Get().Show()
}
}()
}
func (p *Plugin) activeInstance(pid int) error {
// C.activateApplicationWithProcessID(C.int(pid))
fmt.Println("[linux] activateInstance - not implemented: ", pid)
syscall.Kill(pid, syscall.SIGUSR2)
return nil
}