File: notification.rb

package info (click to toggle)
mikutter 3.8.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,544 kB
  • sloc: ruby: 20,548; sh: 99; makefile: 19
file content (21 lines) | stat: -rw-r--r-- 931 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# coding: utf-8

Plugin.create :notification do
  settings(_('お知らせ')) do
    boolean(_('ステータスバーにmikutterから配信されるお知らせを表示する'), :notification_enable)
      .tooltip(_('チェックすると、ステータスバーに表示することが特にない間、mikutterの最新情報を表示しておきます。この変更は再起動後に適用されます'))
  end

  def main
    return unless UserConfig[:notification_enable]
    next_time = (Time.new + 86400).freeze
    Reserver.new(next_time){ main }
    open('https://mikutter.hachune.net/notification.json') do |io|
      JSON.parse(io.read, symbolize_names: true).sort_by{|n| n[:expire]}.reverse_each do |node|
        Plugin.call(:gui_window_rewindstatus, Plugin::GUI::Window.instance(:default), node[:text], [Time.iso8601(node[:expire]),next_time].min)
      end
    end
  end

  Delayer.new{ Thread.new{ main } }
end