gen2brain / beeep Goto Github PK
View Code? Open in Web Editor NEWGo cross-platform library for sending desktop notifications, alerts and beeps
License: BSD 2-Clause "Simplified" License
Go cross-platform library for sending desktop notifications, alerts and beeps
License: BSD 2-Clause "Simplified" License
Hello @gen2brain ,
First of all, I'm glad that I have the chance to welcome this library to the Go Community by opening the first issue here! You did a very good job, it's quite simple library but structured very well and you can extend it even more.
I was thinking instead of using the message box, if windows 8 or windows 10 then use the toast notification (right-side notification box, just like more window apps do it) because message box is good for showing errors and things like that but I think showing "information" as notification is the best option to go.
There is a way so that when the user gets a notification, they can click it and it will open an application, passing in a route path and it will take them directly to the data that corresponds to the Notification.
Simple example being email.
You get a Notification of " my Amazon order will arrive today", and you click it and it opens the Email app and take you to the exact email.
I saw a golang library that did just this, and it would be an awesome compliment to this library but cant fo the life of me find it on github :)
hi!
trying to use a basic err := beeep.Notify("Title", "Message body", "assets/icon128.png")
I go t the following panic : panic: exec: "msg": executable file not found in %PATH%
I dug a little and found that getWindowsVersionString()
returns unknown on my computer
package main
import (
"bytes"
"fmt"
"os/exec"
"strings"
)
func main() {
cmd := exec.Command("cmd", "ver")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
panic(err)
}
fmt.Println(out.String())
s := strings.Replace(out.String(), "\r\n", "", -1)
p1 := strings.Index(s, "[Version")
p2 := strings.Index(s, "]")
var ver string
if p1 == -1 || p2 == -1 {
ver = "unknown"
} else {
ver = s[p1+9 : p2]
}
fmt.Printf("%v\n", ver)
}
outputs
go run .\main.go
Microsoft Windows [version 10.0.16299.192]
(c) 2017 Microsoft Corporation. Tous droits r�serv�s.
unknown
seems to me that it comes from the lower case "version" instead of the expected "Version"
Can we add support for FreeBSD and perhaps other *BSD(s)?
As reported here this library doesn't work on FreeBSD due to some missing implemtnation?
Let's fix this!
I can see an simple explanation here https://github.com/gen2brain/beeep#macos but what to write on the beeep.Alert(title, message, "??")
method ?
You are using assets
directory but I don't have any assets
in my bundle, which is work fine by the way (Application icon, system tray).
➜ tree Twitch\ Clip.app
drwxr-xr-x - quentin 9 May 20:38 Twitch Clip.app
drwxr-xr-x - quentin 9 May 20:38 └── Contents
.rw-r--r-- 456 quentin 9 May 20:38 ├── Info.plist
drwxr-xr-x - quentin 9 May 21:04 ├── MacOS
.rwxr-xr-x 9.8M quentin 9 May 21:04 │ └── twitch-clip
drwxr-xr-x - quentin 9 May 20:38 └── Resources
.rw-r--r-- 91k quentin 9 May 20:38 ├── icon.icns
.rw-r--r-- 17k quentin 9 May 20:38 └── logo.png
I only have the AppleScript icon.
For icons to show up when using Alert() or Notify(), you will need to bundle your application with a app icon.
Any example on how to do this? I can't seem to find good information on Google.
Thank you for your hard work!
func Notify(title, message, appIcon string) error {
...
cmd := exec.Command(osa, "-e", `display notification "`+message+`" with title "`+title+`"`)
func Alert(title, message, appIcon string) error {
...
cmd := exec.Command(osa, "-e", `tell application "System Events" to display notification "`+message+`" with title "`+title+`" sound name "default"`)
the code calls the binary osascript
, but it fails if title
or message
contains a double quotation mark
Go get has been deprecated. Please update this repo to support go install
Would be nice if beeep
offered a way to supply raw image data as a blob.
Notify() part has been fixed by #47, but not Alert() :)
See: #37 (comment)
It looks like it is possible for OSX: #13
It does not currently work for Linux though.
Hey, just saw your library
I made this a while ago, https://github.com/martinlindhe/notify
and I am wondering if you would like to join forces?
I haven't looked deep, but our use case and implementations seems similar.
Would you consider adding support for passing a custom applicationID to the Notify() method? Perhaps it could be solved using the functional options pattern, to avoid breaking API.
Also, I can't really understand why beeep digs out that powershell appID for use in toastNotify? Why powershell? Because, like, go-toast happens to use some powershell-shenanigans to actually show the toast? But then you get the powershell icon/name in the title of the toast. It would make sense to be if users of beeep could instead set the appID
It would be a good feature if this could have blinking alerts on the application icon.
Anyone knows if this package works with windows 11 aswell? Because i'm trying to implent it in my application but it doesn't send any system notification, i managed to make work only the beeep.Beep() .
Hello, in windows 10 notify window has unreadable characters if string not english
err := beeep.Notify("привет", "привет", "assets/information.png")
As the title says, with the example like :
package main
import (
"github.com/gen2brain/beeep"
)
func main() {
err := beeep.Notify("Title", "Message body", "")
if err != nil {
panic(err)
}
select {}
}
When the notification is clicked it will open the AppleScript editor. This seems to be a side effect from using the applescript approach: https://discussions.apple.com/thread/6449168
This issue is pretty old so maybe a solution was become available in the meantime?
https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html
Taken from the spec:
org.freedesktop.Notifications.CloseNotification
void org.freedesktop.Notifications.CloseNotification ( | ); |
---|
UINT32 id
;Causes a notification to be forcefully closed and removed from the user's view. It can be used, for example, in the event that what the notification pertains to is no longer relevant, or to cancel a notification with no expiration time.
Just started using the library and I like how it has been written using pure go and syscalls. While there are cgo packages that handle system tray icons i haven't found one that uses syscalls and was thinking of trying it. Would it be within the scope of this project to add that in? If so I will start looking into it.
In the readme it states "For icons to show up when using Alert() or Notify(), you will need to bundle your application with a app icon." but I'm not sure how that should work.
I've created an app bundle like so:
> tree danotify.app
danotify.app
└── Contents
├── MacOS
│ └── danotify
├── Resources
│ └── icon.icns
└── info.plist
3 directories, 3 files
And the app has the icon I assigned, but notifications are still the default 'pen on paper' icon
https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html
Taken from the spec:
Notifications have an urgency level associated with them. This defines the importance of the notification. For example, "Joe Bob signed on" would be a low urgency. "You have new mail" or "A USB device was unplugged" would be a normal urgency. "Your computer is on fire" would be a critical urgency.
Urgency levels are defined as follows:
Developers must use their own judgement when deciding the urgency of a notification. Typically, if the majority of programs are using the same level for a specific type of urgency, other applications should follow them.
For low and normal urgencies, server implementations may display the notifications how they choose. They should, however, have a sane expiration timeout dependent on the urgency level.
Critical notifications should not automatically expire, as they are things that the user will most likely want to know about. They should only be closed when the user dismisses them, for example, by clicking on the notification.
When sending a notification on Windows 11, all the content of the terminal is cleared while sending it. Me and my friend @el2zay can reproduce it with the examples in the README
Would love to be able to add a clickable link to notifications. Not sure how this would be implemented cross-platform, but toast on windows 10 has the capability (see https://github.com/go-toast/toast).
Other recommendations to accomplish the same thing?
Current implementation on Mac does not support custom images. How about using https://github.com/deckarep/gosx-notifier as Darwin notifier?
I used Alert to send a notification, I packaged the app with https://github.com/machinebox/appify and then created a dmg following https://medium.com/@mattholt/packaging-a-go-application-for-macos-f7084b00f6b5. Still no icon when sending notification.
I tried the app on the latest version of MacOS.
Can't get this to display in win 8.1. Instead it comes up with an error "2019/01/13 02:15:38 exec: "msg": executable file not found in %PATH%"
What msg executable?
For the notifications, it would be cool if it had the options of electron:
https://electronjs.org/docs/api/notification
https://electronjs.org/docs/tutorial/notifications
This includes clickability, different buttons on the notifications etc
All the BSD's use the same notify-send program as Linux. It would be nice to see this working.
I cant get a Windows build :)
I have a setup for cross platform builds running from OSX and Linux.
But I cant build for Windows from OSX.
Would appreciate advice here !
Step to repo:
make build-win-fromosx
Makefile you can run from anywhere:
LIB=github.com/gen2brain/beeep
LIB_FSPATH=$(GOPATH)/src/$(LIB)
NAME=n
print:
@echo Lib -
@echo LIB :$(LIB)
@echo LIB_FSPATH : $(LIB_FSPATH)
#cd $(LIB_FSPATH) && ls -al
@echo
dep:
go get $(LIB)
open-code:
code $(LIB_FSPATH)
open-bash:
bash $(LIB_FSPATH)
build-list:
cd $(LIB_FSPATH) && ls -al
build-clean:
cd $(LIB_FSPATH) && rm -rf $(NAME) go$(NAME) $(NAME).exe go$(NAME).exe *.tar.gz
build-win-fromosx:
brew install mingw-w64
go get gopkg.in/toast.v1
#windows with cgo. It needs CGO
#apt-get install gcc-multilib
#apt-get install gcc-mingw-w64
cd $(LIB_FSPATH) && CC=i686-w64-mingw32-gcc-win32 CGO_ENABLED=1 GOOS=windows GOARCH=386 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-386.tar.gz" $(NAME).exe
cd $(LIB_FSPATH) && rm -rf $(NAME).exe
cd $(LIB_FSPATH) && CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-amd64.tar.gz" $(NAME).exe
cd $(LIB_FSPATH) && rm -rf $(NAME).exe
build-win-fromlinux:
#windows with cgo
#apt-get install gcc-multilib
#apt-get install gcc-mingw-w64
cd $(LIB_FSPATH) && CC=i686-w64-mingw32-gcc-win32 CGO_ENABLED=1 GOOS=windows GOARCH=386 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-386.tar.gz" $(NAME).exe
cd $(LIB_FSPATH) && rm -rf $(NAME).exe
cd $(LIB_FSPATH) && CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-amd64.tar.gz" $(NAME).exe
cd $(LIB_FSPATH) && rm -rf $(NAME).exe
build-linux:
#linux
go get github.com/godbus/dbus
cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-linux-386.tar.gz" $(NAME)
cd $(LIB_FSPATH) && rm -rf $(NAME)
cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-linux-amd64.tar.gz" $(NAME)
cd $(LIB_FSPATH) && rm -rf $(NAME)
build-darwin:
#darwin
cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-darwin-386.tar.gz" $(NAME)
cd $(LIB_FSPATH) && rm -rf $(NAME)
cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-darwin-amd64.tar.gz" $(NAME)
cd $(LIB_FSPATH) && rm -rf $(NAME)
Do you plan to add Go module support, that is, go.mod, etc.?
On a Windows 7 system, the baloonNotify
function does not automatically close the system tray icon after displaying the message; it only closes when the program exits.
There's probable typo in this line:
Line 47 in 4e43051
Should be "org.freedesktop.Notifications.Notify"
Maybe that changed recently in godbus
/cc @gen2brain
The above tools yield much nicer notifications/alerts in my opinion and as far as I can tell, they also allow using non-bundled icons:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.