diff --git a/.travis.yml b/.travis.yml index 853eed9..cfbf1de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ addons: packages: - libnotify-bin - alsa-utils + - espeak script: - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - julia -e 'Pkg.clone(pwd()); Pkg.build("Notifier"); Pkg.test("Notifier"; coverage=true)' diff --git a/README.md b/README.md index 3de9562..e1c0133 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Notifier [![Notifier](http://pkg.julialang.org/badges/Notifier_0.6.svg)](http://pkg.julialang.org/detail/Notifier) +[![Notifier](http://pkg.julialang.org/badges/Notifier_0.7.svg)](http://pkg.julialang.org/detail/Notifier) [![Build Status](https://travis-ci.org/goropikari/Notifier.jl.svg?branch=master)](https://travis-ci.org/goropikari/Notifier.jl) +[![Build status](https://ci.appveyor.com/api/projects/status/cv0ilbo2f6d43xcp?svg=true)](https://ci.appveyor.com/project/goropikari/notifier-jl) [![codecov.io](http://codecov.io/github/goropikari/Notifier.jl/coverage.svg?branch=master)](http://codecov.io/github/goropikari/Notifier.jl?branch=master) This package is notification tools for Julialang. @@ -12,36 +14,33 @@ notify("Task completed") ![Screenshot of a Notification](./docs/linuxpopup.png?raw=true) ## Features: - - Linux + - Linux and macOS - desktop notification - sound notification + - say notification (Read a given massage aloud) - email notification - - macOS - - desktop notification - - sound notification - - email notification - - say notification (Read given massage aloud) - Windows (Experimental) - desktop notification - sound notification + - say notification (Read a given massage aloud) ## Installation ```Julia Pkg.add("Notifier") ``` -# Linux OS -## Setup +## Setup for Linux user Before using Notifier.jl, you need to install following softwares in your Linux system. - `libnotify` for a desktop notification - `mail` for an e-mail notification - `aplay` (Advanced Linux Sound Architecture) for a sound notification +- `espeak` for reading a given massage aloud ```bash -$ sudo apt install libnotify-bin alsa-utils mailutils heirloom-mailx bsd-mailx +$ sudo apt install libnotify-bin alsa-utils espeak mailutils heirloom-mailx bsd-mailx ``` -This package uses `mail` command to notify by e-mail. Thus you need some settings in advance. +This package uses `mail` command to notify by e-mail. You may need some settings in advance. If following command works correctly, you don't need further setting. ```bash $ echo test | mail -s foo yourmail@example.com @@ -56,64 +55,23 @@ notify("Task completed") # You can change the title by title option. notify("Task completed", title="foofoo") notify("Task completed", sound=true) # with sound -notify("Task completed", sound="foo.wav") # specify a sound file -alarm() # only sound. You can specify a sound file, alarm(sound="foo.wav") +notify("Task completed", sound="foo.wav") # Specify a sound file (for Linux and Windows) ``` +Linux ![Screenshot of a Notification](./docs/linuxpopup.png?raw=true) -### e-mail notification -```Julia -email("message", To="foo@example.com") # default subject is set by date. -email("message", subject="result", To="foo@example.com") -``` - - -If you use "email" function frequently, I recommend you to register your email address by "register_email" function. -```Julia -julia> register_email() -Type your desired recipient e-mail address to receive a notification. -e-mail: foo@example.com - -Recipient e-mail address is saved at /path/to/.julia/v0.6/Notifier/email/address.txt. -If you want to change the address, modify /path/to/.julia/v0.6/Notifier/email/address.txt directly or run register_email() again -``` - -After you registered, you don't need to specify e-mail address. -```Julia -email("message") -``` +macOS +![Screenshot of a Notification](./docs/macpopup.png?raw=true) +Windows +![Screenshot of a Notification](./docs/winpopup.png?raw=true) -# macOS -## Usage -### popup notification +### sound and say notification ```julia -using Notifier -notify("Task completed") -notify("Change title", title="foofoo") -notify("Notification with sound", sound=true) alarm() # only sound. You can specify a sound file, alarm(sound="foo.wav") say("Finish calculation!") # Read aloud ``` -![Screenshot of a Notification](./docs/macpopup.png?raw=true) - -Other supported parameters include `group` and `subtitle`. - -You can also remove notifications. However, this does not seem to work reliably. - -```julia -Notifier.remove() # removes all notifications -``` - -To remove specific notifications, you need to specify a group identifier when calling `notify`. This identifier can then be passed to `remove()`. - -```julia -notify("Notification A", group="group1") -notify("Notification B", group="group2") - -Notifier.remove("group1") -``` ### e-mail notification ```Julia @@ -122,7 +80,7 @@ email("message", subject="result", To="foo@example.com") ``` -If you use "email" function frequently, I recommend you to register your email address by "register_email" function. +If you use `email` function frequently, I recommend you to register your email address by `register_email` function. ```Julia julia> register_email() Type your desired recipient e-mail address to receive a notification. @@ -137,16 +95,5 @@ After you registered, you don't need to specify e-mail address. email("message") ``` -# Windows (Experimental) -## Usage -```Julia -using Notifier -notify("calculation done") -# defalut title is "Julia". -# You can change the title by title option. -notify("calculation done", title="foofoo") -notify("calculation done", sound=true) # with sound -notify("calculation done", sound="foo.wav") # specify a sound file -alarm() # only sound. You can specify a sound file, alarm(sound="foo.wav") -``` -![Screenshot of a Notification](./docs/winpopup.png?raw=true) +## Acknowledgement +Inspired by [OSXNotifier.jl](https://github.com/jonasrauber/OSXNotifier.jl). diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..83a0be2 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,47 @@ +environment: + matrix: + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" + - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" + - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" + +## uncomment the following lines to allow failures on nightly julia +## (tests will run but not make your overall status red) +matrix: + allow_failures: + - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" + - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" + +branches: + only: + - master + - /release-.*/ + +notifications: + - provider: Email + on_build_success: false + on_build_failure: false + on_build_status_changed: false + +install: + - ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" +# If there's a newer build queued for the same PR, cancel this one + - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` + https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` + Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` + throw "There are newer queued builds for this pull request, failing early." } +# Download most recent Julia Windows binary + - ps: (new-object net.webclient).DownloadFile( + $env:JULIA_URL, + "C:\projects\julia-binary.exe") +# Run installer silently, output to C:\projects\julia + - C:\projects\julia-binary.exe /S /D=C:\projects\julia + +build_script: +# Need to convert from shallow to complete for Pkg.clone to work + - IF EXIST .git\shallow (git fetch --unshallow) + - C:\projects\julia\bin\julia -e "versioninfo(); + Pkg.clone(pwd(), \"Notifier\"); Pkg.build(\"Notifier\")" + +test_script: + - C:\projects\julia\bin\julia -e "Pkg.test(\"Notifier\")" diff --git a/docs/winpopup.png b/docs/winpopup.png index 2c43597..7ec44df 100644 Binary files a/docs/winpopup.png and b/docs/winpopup.png differ diff --git a/src/linux.jl b/src/linux.jl index 92fcb92..9748cb6 100644 --- a/src/linux.jl +++ b/src/linux.jl @@ -1,5 +1,5 @@ import Base.notify -export notify, alarm, register_email, email +export notify, alarm, say, register_email, email include("email.jl") @@ -39,3 +39,12 @@ function alarm(;sound::AbstractString=joinpath(@__DIR__, "default.wav")) @async run(`aplay -q $sound`) return nothing end + +""" + Notifier.say(message::AbstractString) + +Read a given message aloud. +""" +function say(msg::AbstractString) + run(pipeline(`espeak $msg`, stderr=DevNull)) +end diff --git a/src/mac.jl b/src/mac.jl index 614785c..4bb467e 100644 --- a/src/mac.jl +++ b/src/mac.jl @@ -56,7 +56,7 @@ end """ Notifier.say(message::AbstractString) -Read given message aloud. +Read a given message aloud. """ function say(msg::AbstractString) run(`say $msg`) diff --git a/src/three-balls.ico b/src/three-balls.ico new file mode 100644 index 0000000..fd3d33d Binary files /dev/null and b/src/three-balls.ico differ diff --git a/src/windows.jl b/src/windows.jl index 1a57761..47e0571 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -1,5 +1,5 @@ import Base.notify -export notify, alarm +export notify, alarm, say """ --- Notifier.notify(message; title="Julia", sound=false, time=4) @@ -14,7 +14,7 @@ Notify by desktop notification. function notify(message::AbstractString; title="Julia", sound::Union{Bool, AbstractString}=false, - time::Real=4) + time::Real=8) if sound == true || typeof(sound) <: AbstractString if sound == true @async run(`powershell -Command '('new-object System.Media.SoundPlayer $(joinpath(@__DIR__, "default.wav"))')'.PlaySync'('')'`) @@ -22,9 +22,23 @@ function notify(message::AbstractString; @async run(`powershell -Command '('new-object System.Media.SoundPlayer $sound')'.PlaySync'('')'`) end end - @async run(pipeline(`powershell '('new-object -comobject wscript.shell')'.popup'(''"'$message'"', $time,'"'$title'"',0')'`, stdout=DevNull, stderr=DevNull)) + #@async run(pipeline(`powershell '('new-object -comobject wscript.shell')'.popup'(''"'$message'"', $time,'"'$title'"',0')'`, stdout=DevNull, stderr=DevNull)) - return + # ref. Create a balloon notification in PowerShell / IT Pro + # http://www.itprotoday.com/management-mobility/create-balloon-notification-powershell + @async run(`powershell '['Void']''['System.Reflection.Assembly']'':'':'LoadWithPartialName'(''"'System.Windows.Forms'"'')'';' + \$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon';' + \$objNotifyIcon.BalloonTipIcon = '"'Info'"'';' + \$objNotifyIcon.Icon = '"'$(joinpath(@__DIR__, "three-balls.ico"))'"'';' + \$objNotifyIcon.BalloonTipText = '"'$message'"'';' + \$objNotifyIcon.BalloonTipTitle = '"'$title'"'';' + \$objNotifyIcon.Visible = \$True';' + \$objNotifyIcon.ShowBalloonTip'('$(time*1000)')'';' + Start-Sleep -s $time';' + \$objNotifyIcon.dispose'('')' + `) + + return nothing end """ @@ -39,3 +53,15 @@ alarm(sound="foo.wav") function alarm(;sound::AbstractString=joinpath(@__DIR__, "default.wav")) @async run(`powershell -Command '('new-object System.Media.SoundPlayer $sound')'.PlaySync'('')'`) end + +""" + Notifier.say(message::AbstractString) + +Read a given message aloud. +""" +function say(message::AbstractString) + @async run(`powershell Add-Type -AssemblyName System.speech';' + \$s = New-Object System.Speech.Synthesis.SpeechSynthesizer';' + \$s.Speak'(' '"' $message '"' ')' + `) +end diff --git a/test/linux_test.jl b/test/linux_test.jl index e69699d..6abb146 100644 --- a/test/linux_test.jl +++ b/test/linux_test.jl @@ -28,3 +28,9 @@ end catch false end +@test try + say("Hello") + true +catch + false +end diff --git a/test/windows_test.jl b/test/windows_test.jl index e69699d..e579ed3 100644 --- a/test/windows_test.jl +++ b/test/windows_test.jl @@ -28,3 +28,9 @@ end catch false end +@test try + say("Hello world") + true +catch + false +end