emilianbold commented on a change in pull request #1948: Simple linux 
notifications integration module
URL: https://github.com/apache/netbeans/pull/1948#discussion_r379766685
 
 

 ##########
 File path: 
ide/notifications.linux/src/org/netbeans/modules/notifications/linux/LinuxNotificationDisplayer.java
 ##########
 @@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.notifications.linux;
+
+import com.sun.jna.Native;
+import com.sun.jna.Pointer;
+import java.awt.event.ActionListener;
+import java.util.Optional;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.Icon;
+import javax.swing.JComponent;
+import org.openide.awt.Notification;
+import org.openide.awt.NotificationDisplayer;
+import org.openide.util.Lookup;
+import org.openide.util.lookup.ServiceProvider;
+import org.netbeans.modules.notifications.linux.jna.Libnotify;
+
+/**
+ *
+ * @author Hector Espert
+ */
+@ServiceProvider(service = LinuxNotificationDisplayer.class, position = 50)
+public class LinuxNotificationDisplayer extends NotificationDisplayer {
+
+    private static final Logger LOG = 
Logger.getLogger(LinuxNotificationDisplayer.class.getName());
+
+    private static final String LIBNOTIFY = "libnotify.so.4";
+
+    private static final String APP_NAME = "netbeans";
+
+    private Optional<Libnotify> optionalLibnotify;
+
+    public LinuxNotificationDisplayer() {
+        try {
+            this.optionalLibnotify = Optional.of(Native.load(LIBNOTIFY, 
Libnotify.class));
+            LOG.log(Level.FINE, "Libnotify library loaded");
+        } catch (UnsatisfiedLinkError unsatisfiedLinkError) {
+            LOG.log(Level.WARNING, "Libnotify library not found", 
unsatisfiedLinkError);
+            this.optionalLibnotify = Optional.empty();
+        }
+    }
+
+    public boolean isStarted() {
+        return optionalLibnotify.map(libnotify -> 
libnotify.notify_is_initted()).orElse(false);
+    }
+
+    public boolean notStarted() {
+        return !isStarted();
+    }
+
+    public void start() {
+        optionalLibnotify.filter(libnotify -> !libnotify.notify_is_initted())
 
 Review comment:
   I am impressed by your mastery of `Optional`. Honestly.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to