private static Icon icon() { return Icon.create(SendNotificationCli.class.getResource("/brochure5.png"), "send-notification-cli"); }
@Override public void write(Icon icon) { for (Dimension dimension : Dimension.values()) { File resizedIcon = new File(destination + icon.id() + dimension.fileNameSuffix + "." + icon.extension()); if (!resizedIcon.exists()) { new File(destination).mkdirs(); try (InputStream input = icon.content().openStream(); FileOutputStream output = new FileOutputStream(resizedIcon)) { Thumbnailator.createThumbnail(input, output, dimension.width, dimension.height); } catch (IOException e) { throw new SendNotificationException("Can't write notification icon: " + resizedIcon.getPath(), e); } } } }
public String asPath() { String folder = System.getProperty("java.io.tmpdir") + "/send-notifications-icons/"; String extension = extension(); File icon = new File(folder + id() + "." + extension); if (!icon.exists()) { new File(folder).mkdirs(); try { write(icon); } catch (IOException e) { throw new SendNotificationException("Can't write notification icon : " + icon.getPath(), e); } } return icon.getPath(); }
@Override public void send(Notification notification) { List<String> commands = new ArrayList<>(); commands.add(configuration.bin()); commands.add("-t"); commands.add(DOUBLE_QUOTE + notification.title() + DOUBLE_QUOTE); commands.add("-m"); commands.add(DOUBLE_QUOTE + notification.message() + DOUBLE_QUOTE); commands.add("-p"); commands.add(DOUBLE_QUOTE + notification.icon().asPath() + DOUBLE_QUOTE); try { executor.exec(commands.toArray(new String[0])); } catch (RuntimeException e) { throw new ToasterNotificationException("Error while sending notification with toaster", e); } }
private void write(File destination) throws IOException { try (InputStream input = content().openStream(); FileOutputStream output = new FileOutputStream(destination)) { byte[] buffer = new byte[1024 * 4]; int n; while ((n = input.read(buffer)) != -1) { output.write(buffer, 0, n); } } } }
@Override public void send(Notification notification) { if (!skipNotifications) { icon.setImage(createImage(notification.icon().toByteArray())); icon.displayMessage(notification.title(), notification.message(), toMessageType(notification.level())); } }
@Override public void send(Notification notification) { if (isClientRegistered()) { GntpNotification success = Gntp.notification(gNotification, notification.title()) .text(notification.message()) .icon(notification.icon().toImage()) .priority(toPriority(notification.level())) .build(); try { gClient.notify(success, 5, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
private void changeIcon(Icon icon) { iconWriter.write(icon); byte[] data = icon.id().getBytes(); try { socket.send(new DatagramPacket(data, data.length, InetAddress.getByName(configuration.host()), configuration.port())); } catch (IOException e) { throw new AnyBarException("Error while changing AnyBar icon", e); } }
@Override public void send(Notification notification) { List<String> commands = new ArrayList<>(); commands.add(configuration.bin()); commands.add("-t"); commands.add(DOUBLE_QUOTE + notification.title() + DOUBLE_QUOTE); commands.add("-m"); commands.add(DOUBLE_QUOTE + notification.message() + DOUBLE_QUOTE); commands.add("-p"); commands.add(DOUBLE_QUOTE + notification.icon().asPath() + DOUBLE_QUOTE); try { executor.exec(commands.toArray(new String[0])); } catch (RuntimeException e) { throw new ToasterNotificationException("Error while sending notification with toaster", e); } }
@Override public Notifier init() { if (icon != null) { return this; } if (!SystemTray.isSupported()) { skipNotifications = true; LOGGER.warn("SystemTray is not supported, skipping notifications..."); return this; } icon = new TrayIcon(createImage(application.icon().toByteArray()), application.name()); icon.setImageAutoSize(true); try { SystemTray.getSystemTray().add(icon); } catch (AWTException e) { throw new SystemTrayNotificationException("Error initializing SystemTray Icon.", e); } return this; }
@Override public void send(Notification notification) { if (isClientRegistered()) { GntpNotification success = Gntp.notification(gNotification, notification.title()) .text(notification.message()) .icon(notification.icon().toImage()) .priority(toPriority(notification.level())) .build(); try { gClient.notify(success, 5, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
private void changeIcon(Icon icon) { iconWriter.write(icon); byte[] data = icon.id().getBytes(); try { socket.send(new DatagramPacket(data, data.length, InetAddress.getByName(configuration.host()), configuration.port())); } catch (IOException e) { throw new AnyBarException("Error while changing AnyBar icon", e); } }
private Icon notificationIcon() { try { return Icon.create(icon.toURI().toURL(), "send-notification-" + icon.getName()); } catch (MalformedURLException e) { throw new SendNotificationException("Cannot build URL from file: " + icon, e); } }
@Override public void write(Icon icon) { for (Dimension dimension : Dimension.values()) { File resizedIcon = new File(destination + icon.id() + dimension.fileNameSuffix + "." + icon.extension()); if (!resizedIcon.exists()) { new File(destination).mkdirs(); try (InputStream input = icon.content().openStream(); FileOutputStream output = new FileOutputStream(resizedIcon)) { Thumbnailator.createThumbnail(input, output, dimension.width, dimension.height); } catch (IOException e) { throw new SendNotificationException("Can't write notification icon: " + resizedIcon.getPath(), e); } } } }
public String asPath() { String folder = System.getProperty("java.io.tmpdir") + "/send-notifications-icons/"; String extension = extension(); File icon = new File(folder + id() + "." + extension); if (!icon.exists()) { new File(folder).mkdirs(); try { write(icon); } catch (IOException e) { throw new SendNotificationException("Can't write notification icon : " + icon.getPath(), e); } } return icon.getPath(); }
@Override public void send(Notification notification) { List<String> commands = new ArrayList<>(); commands.add(configuration.bin()); commands.add("--passivepopup"); commands.add(notification.message()); if (application.timeout() != -1) { commands.add(String.valueOf(TimeUnit.MILLISECONDS.toSeconds(application.timeout()))); } commands.add("--title"); commands.add(notification.title()); commands.add("--icon"); commands.add(notification.icon().asPath()); try { executor.exec(commands.toArray(new String[0])); } catch (RuntimeException e) { throw new KdialogException("Error while sending notification with Kdialog.", e); } }