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

Commit

Permalink
Merge pull request #8 from goropikari/dev
Browse files Browse the repository at this point in the history
increase functions and change the style of popup notification for windows
  • Loading branch information
goropikari authored Mar 7, 2018
2 parents 38b55cf + 0cdee0e commit a8bc064
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 78 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand Down
91 changes: 19 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 [email protected]
Expand All @@ -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="[email protected]") # default subject is set by date.
email("message", subject="result", To="[email protected]")
```


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
Expand All @@ -122,7 +80,7 @@ email("message", subject="result", To="[email protected]")
```


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.
Expand All @@ -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).
47 changes: 47 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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\")"
Binary file modified docs/winpopup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion src/linux.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Base.notify
export notify, alarm, register_email, email
export notify, alarm, say, register_email, email

include("email.jl")

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/mac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
Binary file added src/three-balls.ico
Binary file not shown.
34 changes: 30 additions & 4 deletions src/windows.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Base.notify
export notify, alarm
export notify, alarm, say
"""
---
Notifier.notify(message; title="Julia", sound=false, time=4)
Expand All @@ -14,17 +14,31 @@ 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'('')'`)
elseif ispath(sound)
@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

"""
Expand All @@ -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
6 changes: 6 additions & 0 deletions test/linux_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ end
catch
false
end
@test try
say("Hello")
true
catch
false
end
6 changes: 6 additions & 0 deletions test/windows_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ end
catch
false
end
@test try
say("Hello world")
true
catch
false
end

0 comments on commit a8bc064

Please sign in to comment.