Changeset 11969 in josm for trunk/src/org


Ignore:
Timestamp:
2017-04-22T01:28:44+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #14671 - Make sure we don't run the API call many times after system wakeup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/MessageNotifier.java

    r11288 r11969  
    5757
    5858        private int lastUnreadCount;
     59        private long lastTimeInMillis;
    5960
    6061        @Override
    6162        public void run() {
    6263            try {
    63                 final UserInfo userInfo = new OsmServerUserInfoReader().fetchUserInfo(NullProgressMonitor.INSTANCE,
    64                         tr("get number of unread messages"));
    65                 final int unread = userInfo.getUnreadMessages();
    66                 if (unread > 0 && unread != lastUnreadCount) {
    67                     GuiHelper.runInEDT(() -> {
    68                         JPanel panel = new JPanel(new GridBagLayout());
    69                         panel.add(new JLabel(trn("You have {0} unread message.", "You have {0} unread messages.", unread, unread)),
    70                                 GBC.eol());
    71                         panel.add(new UrlLabel(Main.getBaseUserUrl() + '/' + userInfo.getDisplayName() + "/inbox",
    72                                 tr("Click here to see your inbox.")), GBC.eol());
    73                         panel.setOpaque(false);
    74                         new Notification().setContent(panel)
    75                             .setIcon(JOptionPane.INFORMATION_MESSAGE)
    76                             .setDuration(Notification.TIME_LONG)
    77                             .show();
    78                     });
    79                     lastUnreadCount = unread;
     64                long currentTime = System.currentTimeMillis();
     65                // See #14671 - Make sure we don't run the API call many times after system wakeup
     66                if (currentTime >= lastTimeInMillis + TimeUnit.MINUTES.toMillis(PROP_INTERVAL.get())) {
     67                    lastTimeInMillis = currentTime;
     68                    final UserInfo userInfo = new OsmServerUserInfoReader().fetchUserInfo(NullProgressMonitor.INSTANCE,
     69                            tr("get number of unread messages"));
     70                    final int unread = userInfo.getUnreadMessages();
     71                    if (unread > 0 && unread != lastUnreadCount) {
     72                        GuiHelper.runInEDT(() -> {
     73                            JPanel panel = new JPanel(new GridBagLayout());
     74                            panel.add(new JLabel(trn("You have {0} unread message.", "You have {0} unread messages.", unread, unread)),
     75                                    GBC.eol());
     76                            panel.add(new UrlLabel(Main.getBaseUserUrl() + '/' + userInfo.getDisplayName() + "/inbox",
     77                                    tr("Click here to see your inbox.")), GBC.eol());
     78                            panel.setOpaque(false);
     79                            new Notification().setContent(panel)
     80                                .setIcon(JOptionPane.INFORMATION_MESSAGE)
     81                                .setDuration(Notification.TIME_LONG)
     82                                .show();
     83                        });
     84                        lastUnreadCount = unread;
     85                    }
    8086                }
    8187            } catch (OsmTransferException e) {
Note: See TracChangeset for help on using the changeset viewer.