Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
initial fix for notification icon on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
achhabra2 committed Jan 6, 2022
1 parent 8208db2 commit f1c53e0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
57 changes: 46 additions & 11 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
_ "embed"
"errors"
"fmt"
"io"
Expand All @@ -24,17 +25,21 @@ import (
"github.com/klauspost/compress/zip"
)

//go:embed build/windows/icons/icon_150.png
var notificationIcon []byte

// App application struct
type App struct {
ctx context.Context
c *transport.Client
selectedFiles []string
receivedFile string
wormholeCtx *context.Context
wormholeCancel *context.CancelFunc
LogPath string
UserPrefs settings.UserSettings
IsTransferring bool
ctx context.Context
c *transport.Client
selectedFiles []string
receivedFile string
wormholeCtx *context.Context
wormholeCancel *context.CancelFunc
LogPath string
UserPrefs settings.UserSettings
IsTransferring bool
NotificationIconPath string
}

// NewApp creates a new App application struct
Expand Down Expand Up @@ -68,6 +73,7 @@ func (b *App) domReady(ctx context.Context) {
} else {
runtime.LogInfo(b.ctx, "Skipping Update Check")
}
b.VerifyNotificationIcon()
}

// shutdown is called at application termination
Expand Down Expand Up @@ -135,7 +141,7 @@ func (b *App) SendFile(filePath string) {
runtime.LogInfo(b.ctx, "Send Success")
runtime.EventsEmit(b.ctx, "send:status", "completed")
if b.c.Notifications {
beeep.Notify("RiftShare", "Send Complete", "appicon.png")
beeep.Notify("RiftShare", "Send Complete", b.NotificationIconPath)
}
}

Expand Down Expand Up @@ -216,7 +222,7 @@ func (b *App) ReceiveFile(code string) {
}
runtime.EventsEmit(b.ctx, "receive:status", "completed")
if b.c.Notifications {
beeep.Notify("RiftShare", "Receive Complete", "appicon.png")
beeep.Notify("RiftShare", "Receive Complete", b.NotificationIconPath)
}
}()
}
Expand Down Expand Up @@ -384,6 +390,9 @@ func (b *App) SetNotificationsParam(val bool) bool {
b.c.Notifications = val
b.UserPrefs.Notifications = val
b.PersistUserSettings()
if val {
b.VerifyNotificationIcon()
}
return b.c.Notifications
}

Expand Down Expand Up @@ -434,3 +443,29 @@ func (b *App) AppInstalledFromPackageManager() bool {
return false
}
}

func (b *App) VerifyNotificationIcon() string {
if goruntime.GOOS == "windows" {
if b.UserPrefs.Notifications {
settingsDir, ferr := settings.GetSettingsDirectory()
if ferr != nil {
runtime.LogError(b.ctx, "Could not open settings directory")
return ""
}
notificationIconPath := filepath.Join(settingsDir, "notificationIcon.png")
if _, err := os.Stat(notificationIconPath); os.IsNotExist(err) {
runtime.LogInfo(b.ctx, "No notification icon found, creating..")
err = os.WriteFile(notificationIconPath, notificationIcon, 0666)
if err != nil {
runtime.LogError(b.ctx, "Could not write icon file")
return ""
}
return notificationIconPath
} else {
runtime.LogInfo(b.ctx, "Notification icon found, skipping")
return notificationIconPath
}
}
}
return ""
}
2 changes: 1 addition & 1 deletion frontend/dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/dist/bundle.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/wailsjs/go/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface go {
ShowErrorDialog(arg1:string):Promise<void>
UpdateCheckUI():Promise<void>
UpdateSendProgress(arg1:number,arg2:number):Promise<void>
VerifyNotificationIcon():Promise<string>
},
}

Expand Down
7 changes: 7 additions & 0 deletions frontend/wailsjs/go/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ const go = {
"UpdateSendProgress": (arg1, arg2) => {
return window.go.main.App.UpdateSendProgress(arg1, arg2);
},
/**
* VerifyNotificationIcon
* @returns {Promise<string>} - Go Type: string
*/
"VerifyNotificationIcon": () => {
return window.go.main.App.VerifyNotificationIcon();
},
},
},

Expand Down

0 comments on commit f1c53e0

Please sign in to comment.