-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/Windos/BurntToast Use: notifier.implementation = burnttoast notifier.burnttoast.sound = A sound ID from available sound list below (default: none) Available sounds: Default;IM;Mail;Reminder;SMS;Alarm;Alarm2;Alarm3;Alarm4;Alarm5; Alarm6;Alarm7;Alarm8;Alarm9;Alarm10;Call;Call2;Call3;Call4;Call5;Call6;Call7;Call8;Call9;Call10
- Loading branch information
Showing
7 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...fication/src/main/java/fr/jcgay/notification/notifier/burnttoast/BurntToastException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package fr.jcgay.notification.notifier.burnttoast; | ||
|
||
import fr.jcgay.notification.UrlSendNotificationException; | ||
|
||
public class BurntToastException extends UrlSendNotificationException { | ||
|
||
public BurntToastException(String message) { | ||
super(message); | ||
} | ||
|
||
@Override | ||
public String getURL() { | ||
return "https://github.com/jcgay/send-notification/wiki/burnttoast"; | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...ification/src/main/java/fr/jcgay/notification/notifier/burnttoast/BurntToastNotifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package fr.jcgay.notification.notifier.burnttoast; | ||
|
||
import com.google.common.base.MoreObjects; | ||
import com.google.common.base.Objects; | ||
import com.profesorfalken.jpowershell.PowerShell; | ||
import com.profesorfalken.jpowershell.PowerShellResponse; | ||
import fr.jcgay.notification.Application; | ||
import fr.jcgay.notification.DiscoverableNotifier; | ||
import fr.jcgay.notification.Notification; | ||
import fr.jcgay.notification.Notifier; | ||
import org.slf4j.Logger; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
public class BurntToastNotifier implements DiscoverableNotifier { | ||
|
||
private static final Logger LOGGER = getLogger(BurntToastNotifier.class); | ||
|
||
private final Application application; | ||
private final BurntToastNotifierConfiguration configuration; | ||
|
||
public BurntToastNotifier(Application application, BurntToastNotifierConfiguration configuration) { | ||
this.application = application; | ||
this.configuration = configuration; | ||
} | ||
|
||
@Override | ||
public void send(Notification notification) { | ||
StringBuilder command = new StringBuilder() | ||
.append("New-BurntToastNotification -Text '") | ||
.append(notification.title()) | ||
.append("', '") | ||
.append(notification.message()) | ||
.append("' -AppLogo ") | ||
.append(notification.icon().asPath()) | ||
.append(" -AppId '") | ||
.append(application.id()) | ||
.append("'"); | ||
|
||
if (configuration.sound() == null) { | ||
command.append(" -Silent"); | ||
} else { | ||
command.append(" -Sound ") | ||
.append(configuration.sound()); | ||
} | ||
|
||
if (LOGGER.isDebugEnabled()) { | ||
LOGGER.debug("Will execute PowerShell: {}", command.toString()); | ||
} | ||
|
||
PowerShellResponse response = PowerShell.executeSingleCommand(command.toString()); | ||
LOGGER.debug("Response: {}", response.getCommandOutput()); | ||
if (response.isError()) { | ||
throw new BurntToastException(response.getCommandOutput()); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public boolean isPersistent() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Notifier init() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean tryInit() { | ||
PowerShellResponse response = PowerShell.executeSingleCommand("Get-Module -ListAvailable | Format-Table Name"); | ||
return !response.isError() && response.getCommandOutput().toLowerCase().contains("burnttoast"); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(application, configuration); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
final BurntToastNotifier other = (BurntToastNotifier) obj; | ||
return Objects.equal(this.application, other.application) | ||
&& Objects.equal(this.configuration, other.configuration); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("application", application) | ||
.add("configuration", configuration) | ||
.toString(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../main/java/fr/jcgay/notification/notifier/burnttoast/BurntToastNotifierConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package fr.jcgay.notification.notifier.burnttoast; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Properties; | ||
|
||
@AutoValue | ||
public abstract class BurntToastNotifierConfiguration { | ||
|
||
private static final BurntToastNotifierConfiguration DEFAULT = new AutoValue_BurntToastNotifierConfiguration(null); | ||
|
||
BurntToastNotifierConfiguration() { | ||
// prevent external subclasses | ||
} | ||
|
||
public static BurntToastNotifierConfiguration byDefault() { | ||
return DEFAULT; | ||
} | ||
|
||
public static BurntToastNotifierConfiguration create(Properties properties) { | ||
if (properties == null) { | ||
return byDefault(); | ||
} | ||
|
||
return new AutoValue_BurntToastNotifierConfiguration(properties.getProperty("notifier.burnttoast.sound")); | ||
} | ||
|
||
@Nullable | ||
public abstract String sound(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters