Code Monkey home page Code Monkey logo

toast's Introduction

Toast

A go package for Windows 10 toast notifications.

As seen in jacobmarshall/pokevision-cli.

CLI

As well as using go-toast within your Go projects, you can also utilise the CLI - for any of your projects.

Download 64bit or 32bit

C:\Users\Example\Downloads\toast64.exe \
  --app-id "Example App" \
  --title "Hello World" \
  --message "Lorem ipsum dolor sit amet, consectetur adipiscing elit." \
  --icon "C:\Users\Example\Pictures\icon.png" \
  --audio "default" --loop \
  --duration "long" \
  --activation-arg "https://google.com" \
  --action "Open maps" --action-arg "bingmaps:?q=sushi" \
  --action "Open browser" --action-arg "http://..."

CLI

Example

package main

import (
    "log"

    "gopkg.in/toast.v1"
)

func main() {
    notification := toast.Notification{
        AppID: "Example App",
        Title: "My notification",
        Message: "Some message about how important something is...",
        Icon: "go.png", // This file must exist (remove this line if it doesn't)
        Actions: []toast.Action{
            {"protocol", "I'm a button", ""},
            {"protocol", "Me too!", ""},
        },
    }
    err := notification.Push()
    if err != nil {
        log.Fatalln(err)
    }
}

Screenshots

Toast

Action centre

toast's People

Contributors

ammaralaa-dev avatar hebestreit avatar jacobmarshallpp avatar jmshal avatar kryptykphysh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

toast's Issues

Notifications not displaying image, message or title.

I have been trying to add toast notifications to an application I'm developing. Using the example in the readme the following notification is produced:

Notification

toast

Action Centre

toast2

As you can see, there is no image and no action buttons. I am not sure if this is down to a setting on my machine or not. However, the code I am using is a copy/paste of the example, using the gopher image as "go.png".

I'm running Go 1.7 on Windows 64-bit.

Thanks.

Not showing notification in Windows 10

image
Notification not showing up

`
package main

import (
"log"
toast "gopkg.in/toast.v1"
)

func main() {
notification := toast.Notification{
AppID: "Example AppID",
Title: "My notification",
Message: "Some message about how important something is...",
Icon: "C:\Users\noti\icon.png", // This file must exist (remove this line if it doesn't)
Actions: []toast.Action{
{"protocol", "I'm a button", ""},
{"protocol", "Me too!", ""},
},
}
err := notification.Push()
if err != nil {
log.Fatalln(err)
}
}
`

Configuring periodic toast

Hello,
I would like to configure periodic toast message. How can I configure it in Windows 10?
Thanks
Jayesh

Ampersands (&) in Notification parameters.

Ampersands produce the following errors:

Exception calling "LoadXml" with "1" argument(s): "Exception from HRESULT: 0xC00CE504"
At C:\Users\Redacted\AppData\Local\Temp\61b6b691-bd0b-4acb-7526-9b1398df7d67.ps1:26 char:1
+ $xml.LoadXml($template)
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : Exception

Exception calling "Show" with "1" argument(s): "The parameter is incorrect.
The parameter is incorrect.
"
At C:\Users\Redacted\AppData\Local\Temp\61b6b691-bd0b-4acb-7526-9b1398df7d67.ps1:28 char:1
+ [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotif ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException

I believe this can be solved with some clever string escaping, but I am not too familiar with PowerShell.

Notification pop ups are slow to appear

After the code runs, the notification pop-up window appears very slowly, and it takes a few seconds.

  • Example
func main() {
	start := time.Now()
	fmt.Println("start")
	msg := "测试通知内容"
	notification := toast.Notification{
		AppID:   "test",
		Title:   "测试通知标题",
		Message: msg,
	}
	err := notification.Push()
	if err != nil {
		panic(err)
	}
	end := time.Now()
	fmt.Println("end")
	fmt.Printf("use time: %v", end.Sub(start))
}
  • Output
start
end
use time: 3.8882003s

Example in the readme needs tweaking

Lines 15 and 16 need modifying in order to build.

Using go 1.6.3 and:

        Actions: []toast.Action{
            {"protocol", "I'm a button"},
            {"protocol", "Me too!"},
        },

I get:

.\main.go:15: too few values in struct initializer
.\main.go:16: too few values in struct initializer

Adding in the Arguments string worked:

        Actions: []toast.Action{
            {"protocol", "I'm a button", ""},
            {"protocol", "Me too!", ""},
        },

Notification drop some text

Hi, when i try to print the next text like a messege the notification just show some text
"$22.35"

And the notification print just
".35"

I cound fix the issue putting an spase between the dollar sing and the number
"$ 22.35" //This print all the text.

go get fails from OSX

any ideas ?
I can build windows stuff from OSX and linux using the fabulous mingw64.

apple$ go get gopkg.in/toast.v1
# gopkg.in/toast.v1
../../../../../../../../../gopkg.in/toast.v1/toast.go:352:41: unknown field 'HideWindow' in struct literal of type syscall.SysProcAttr

Here is my make file that is using the toast lib.

gen2brain/beeep#19

Would really appreciate help.

Action with multiple query args not working

For example this works:

.\toast64.exe --app-id "{D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}\WindowsPowerShell\v1.0\powershell.exe" --title Test --message Test --activation-arg "https://www.google.com/search?q=dogs"

while this does not (no notifications will be posted):

.\toast64.exe --app-id "{D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}\WindowsPowerShell\v1.0\powershell.exe" --title Test --message Test --activation-arg "https://www.google.com/search?q=dogs&start=10"

Is this more windows being dumb or might this actually be a bug here?

P.s. same behavior for when using --action ... --action-arg ....

If you need more input, just let me know :)

Check invalid fields before passing off to PowerShell

The main example code

func main() {
    notification := toast.Notification{
        AppID: "Example App",
        Title: "My notification",
        Message: "Some message about how important something is...",
        Icon: "go.png",
        Actions: []toast.Action{
            {"protocol", "I'm a button", ""},
            {"protocol", "Me too!", ""},
        },
    }
    err := notification.Push()
    if err != nil {
        log.Fatalln(err)
    }
}

works very different from the example screenshots. Tested with both Win10x64 and Win10x32.
Only the "Example App" is shown, and a kind of "you have a new notification" message.

Title, Message and Buttons are missing.

bildschirmfoto 2017-02-14 um 14 26 38

[Encoding problem] Special characters appear like this: É

Golang doesn't support bom in utf8.
But it is much needed most of the time when reading files for Windows.
When the powershell script launches the toast, special characters (eg: é) would appear like this: É.

We need to add the bom to the temporary powershell script for the content to be properly displayed in the toast notification.

like so:

toast.go

func invokeTemporaryScript(content string) error {
id, _ := uuid.NewV4()
file := filepath.Join(os.TempDir(), id.String()+".ps1")
defer os.Remove(file)

bom := []byte{0xef, 0xbb, 0xbf}
final := append(bom, content...)
err := ioutil.WriteFile(file, final, 0600)
if err != nil {
	return err
}

[...]

}

Notification with expiration time

I read somewhere that by default toast notifications will stay in action center for 7 days, but this can be customized (I think here)
Is it possible to do this with your package?

Windows 7?

Any chance this might be enhanced to work on Windows 7?

Unable to find type [Windows.UI.Notifications.ToastNotificationManager,Windows.UI.Notifications, ContentType=WindowsRuntime].    
At C:\Users\<user>\AppData\Local\Temp\<long-hash>.ps1:2 char:1                                       
+ [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifi ...                                                      
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                          
    + CategoryInfo          : InvalidOperation: (Windows.UI.Noti...=WindowsRuntime:TypeName) [], RuntimeException                
    + FullyQualifiedErrorId : TypeNotFound                                                                                       

Button & Copy the content

What should I do if I want to copy the content of the notification after clicking the button?

Thanks❤

"Flashing" powershell console

Imported "gopkg.in/toast.v1"

Maybe i'm using it wrong, but when the powershell script gets executed i can see for a fraction of a second the powershell console window ("Flashing like popup") before the toast notification. Is this an expected behaviour ?

I modified toast.go to get rid of it. I'm sharing just in case.

toast.go

import ( "syscall" )

func invokeTemporaryScript(content string) error {
id, _ := uuid.NewV4()
file := filepath.Join(os.TempDir(), id.String()+".ps1")
defer os.Remove(file)
err := ioutil.WriteFile(file, []byte(content), 0600)
if err != nil {
return err
}
cmd := exec.Command("PowerShell", "-ExecutionPolicy", "Bypass", "-File", file)
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
if err = cmd.Run(); err != nil {
return err
}
return nil
}

Image URL

I'd love it if I could just use an image URL instead of having to manually download the image.

Characters get garbled or even no notification when contains Chinese or Japanese.

I tested the code and the case one by one, and got this result:

func main (){
  notification := toast.Notification{
    Title: "1_Title", 
    // 2_Title
    // 3_Title
    // 4_Title
    // 5_标题 
    Message: "msg test",
    // msg 测试
    // msg テスト
    // 测试
    // msg test
  }
  notification.Push()
}

garbled-notification

Notifications 2,4,5 got garbled, and Notification 3 is not be notified.
Message 2,4 have Chinese characters. Message 3 has Japanese characters.
Title 5 have Chinese characters.

The version of Windows 10 is 18362.239.

No Notification is shown

Hi,
I am using your library like this:

import "github.com/go-toast/toast" // also tried "gopkg.in/toast.v1"

// ...

notification := toast.Notification{
	AppID:   "...",
	Title:   "...",
	Message: "...",
	Audio:   toast.Default,
}
err := notification.Push()
checkErr(err)

The notification is not shown, no sound is played and no error is returned from notification.Push().
System Info: Windows 10 (Version 1709, Build 16288.1)

I've had a glance at your code real quick, but could not see the bug myself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.