Skip to content

Commit

Permalink
Merge pull request #32 from abjrcode/single-instance
Browse files Browse the repository at this point in the history
allow a single instance of the application
  • Loading branch information
abjrcode authored Dec 24, 2023
2 parents 82770ff + 9edc4ae commit f076da6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
15 changes: 6 additions & 9 deletions app_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"runtime"
"strings"

"github.com/abjrcode/swervo/internal/app"
Expand Down Expand Up @@ -46,22 +45,20 @@ func (c *AppController) init(ctx context.Context, errorHandler app.ErrorHandler)
c.errorHandler = errorHandler
c.mainMenu = appMenu

FileMenu := appMenu.AddSubmenu("File")
FileMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) {
fileMenu := appMenu.AddSubmenu("File")
fileMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) {
wailsRuntime.Quit(ctx)
})

if runtime.GOOS == "darwin" {
appMenu.Append(menu.EditMenu())
}

HelpMenu := appMenu.AddSubmenu("Help")
HelpMenu.AddText("About", keys.CmdOrCtrl("h"), func(_ *menu.CallbackData) {
helpMenu := appMenu.AddSubmenu("Help")
helpMenu.AddText("About", keys.CmdOrCtrl("h"), func(_ *menu.CallbackData) {
wailsRuntime.MessageDialog(ctx, wailsRuntime.MessageDialogOptions{
Title: "About",
Message: fmt.Sprintf("Swervo %s\nBuilt @ %s\nCommit SHA: %s\nBuild Link: %s", Version, BuildTimestamp, CommitSha, BuildLink),
})
})

wailsRuntime.MenuSetApplicationMenu(ctx, appMenu)
}

func (c *AppController) ShowErrorDialog(msg string) {
Expand Down
2 changes: 1 addition & 1 deletion internal/datastore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func New(appDataDir, dbFileName string) AppStore {
dbFilePath = strings.ReplaceAll(dbFilePath, "\\", "/")

runner.dbFilePath = dbFilePath
runner.dbConnectionString = fmt.Sprintf("file:%s", dbFilePath)
runner.dbConnectionString = fmt.Sprintf("file:%s?mode=rwc&_locking=exclusive", dbFilePath)

return runner
}
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ func main() {
Title: "Swervo",
Width: 1024,
Height: 768,
Menu: appController.mainMenu,
AssetServer: &assetserver.Options{
Assets: assets,
},
Expand All @@ -138,6 +137,9 @@ func main() {
awsIdcController,
awsCredentialsFileSinkController,
},
SingleInstanceLock: &options.SingleInstanceLock{
UniqueId: "swervo_473c7f9b-8028-4888-871d-53c669266f80",
},
}); err != nil {
errorHandler.Catch(nil, logger, errors.New("failed to launch Swervo"))
}
Expand Down

0 comments on commit f076da6

Please sign in to comment.