aboutsummaryrefslogtreecommitdiffstats
path: root/core/userconfig.rb
blob: bbb82ca9896e8d1b8b3f012210026cb557d82160 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# -*- coding: utf-8 -*-

miquire :core, 'configloader'

require 'singleton'
require 'fileutils'

#
#= UserConfig 動的な設定
#
#プログラムから動的に変更される設定。
#プラグインの設定ではないので注意。
class UserConfig
  include Singleton
  include ConfigLoader
  extend MonitorMixin
  #
  # 予約された設定一覧
  #

  @@defaults = {
    :retrieve_interval_friendtl => 1,   # TLを更新する間隔(int)
    :retrieve_interval_mention => 20,   # Replyを更新する間隔(int)
    :retrieve_interval_search => 60,    # 検索を更新する間隔(int)
    :retrieve_interval_followings => 60,  # followを更新する間隔(int)
    :retrieve_interval_followers => 60,  # followerを更新する間隔(int)
    :retrieve_interval_direct_messages => 20,  # DirectMessageを更新する間隔(int)
    :retrieve_interval_list_timeline => 60,    # リストの更新間隔(int)

    :retrieve_count_friendtl => 20,   # TLを取得する数(int)
    :retrieve_count_mention => 20,    # Replyを取得する数(int)
    :retrieve_count_followings => 20,   # followを取得する数(int)
    :retrieve_count_followers => 20,   # followerを取得する数(int)
    :retrieve_count_direct_messages => 200,   # followerを取得する数(int)

    :update_queue_delay => 100,
    :favorite_queue_delay => 100,
    :follow_queue_delay => 100,
    :direct_message_queue_delay => 100,

    # User Stream
    :realtime_rewind => true,
    :filter_realtime_rewind => true,

    # デフォルトのフッダ
    :footer => "",

    # リプライ元を常に取得する
    :retrieve_force_mumbleparent => true,

    # 遅延対策
    :anti_retrieve_fail => false,

    # つぶやきを投稿するキー
    :shortcutkey_keybinds => {1 => {:key => "Control + Return", :name => '投稿する', :slug => :post_it}},

    # リクエストをリトライする回数
    :message_retry_limit => 10,

    # 通知を表示しておく秒数
    :notify_expire_time => 10,

    :retweeted_by_anyone_show_timeline => true,

    :retweeted_by_anyone_age => true,

    :favorited_by_anyone_show_timeline => true,

    :favorited_by_anyone_age => true,

    # プロフィールタブの並び順
    :profile_tab_order => [:usertimeline, :aboutuser, :list],

    # 設定タブの並び順
    :tab_order_in_settings => ["基本設定", "表示", "入力", "通知", "抽出タブ", "リスト", "ショートカットキー", "アカウント情報", "プロキシ"],

    # タブの位置 [上,下,左,右]
    :tab_position => 3,

    # 常にURLを短縮して投稿
    :shrinkurl_always => false,

    # 常にURLを展開して表示
    :shrinkurl_expand => true,

    # 非公式RTにin_reply_to_statusをつける
    :legacy_retweet_act_as_reply => false,

    :bitly_user => '',
    :bitly_apikey => '',

    :mumble_basic_font => 'Sans 10',
    :mumble_basic_color => [0, 0, 0],
    :reply_text_font => 'Sans 8',
    :reply_text_color => [0, 0, 0],
    :quote_text_font => 'Sans 8',
    :quote_text_color => [0, 0, 0],
    :mumble_basic_left_font => 'Sans 10',
    :mumble_basic_left_color => [0, 0, 0],
    :mumble_basic_right_font => 'Sans 10',
    :mumble_basic_right_color => [0x9999, 0x9999, 0x9999],

    :mumble_basic_bg => [0xffff, 0xffff, 0xffff],
    :mumble_reply_bg => [0xffff, 0xdede, 0xdede],
    :mumble_self_bg => [0xffff, 0xffff, 0xdede],
    :mumble_selected_bg => [0xdede, 0xdede, 0xffff],
    :replyviewer_background_color => [0xffff, 0xdede, 0xdede],
    :quote_background_color => [0xffff, 0xffff, 0xffff],

    :reply_icon_size => 32,
    :quote_icon_size => 32,

    :reply_present_policy => %i<header icon edge>,
    :reply_edge => :solid,

    :quote_present_policy => %i<header icon edge>,
    :quote_edge => :solid,

    # 右クリックメニューの並び順
    :mumble_contextmenu_order => ['copy_selected_region',
                                  'copy_description',
                                  'reply',
                                  'reply_all',
                                  'retweet',
                                  'delete_retweet',
                                  'legacy_retweet',
                                  'favorite',
                                  'delete_favorite',
                                  'delete'],

    :subparts_order => ["Gdk::ReplyViewer", "Gdk::SubPartsFavorite", "Gdk::SubPartsRetweet"],

    :activity_mute_kind => ["error"],
    :activity_show_timeline => ["system", "achievement"],

    :notification_enable => true,

    :reply_text_max_line_count => 10,
    :quote_text_max_line_count => 10,
    :reply_clicked_action => :open,
    :quote_clicked_action => :open,
  }

  @@watcher = Hash.new{ [] }
  @@watcher_id = Hash.new
  @@watcher_id_count = 0

  # キーに対応する値が存在するかを調べる。
  # 値が設定されていれば、それが _nil_ や _false_ であっても _true_ を返す
  # ==== Args
  # [key] Symbol キー
  # ==== Return
  # [true] 存在する
  # [false] 存在しない
  def self.include?(key)
    UserConfig.instance.include?(key) || @@defaults.include?(key)
  end

  # 設定名 _key_ にたいする値を取り出す
  # 値が設定されていない場合、nilを返す。
  def self.[](key)
    UserConfig.instance.at(key, @@defaults[key.to_sym])
  end

  # 設定名 _key_ に値 _value_ を関連付ける
  def self.[]=(key, val)
    watchers = synchronize{
      if not(@@watcher[key].empty?)
        before_val = UserConfig.instance.at(key, @@defaults[key.to_sym])
        @@watcher[key].map{ |id|
          proc = if @@watcher_id.has_key?(id)
                   @@watcher_id[id]
                 else
                   @@watcher[key].delete(id)
                   nil end
          lambda{ proc.call(key, val, before_val, id) } if proc } end }
    if watchers.is_a? Enumerable
      watchers.each{ |w| w.call if w } end
    UserConfig.instance.store(key, val)
  end

  # 設定名 _key_ の値が変更されたときに、ブロック _watcher_ を呼び出す。
  # watcher_idを返す。
  def self.connect(key, &watcher)
    synchronize{
      id = @@watcher_id_count
      @@watcher_id_count += 1
      @@watcher[key] = @@watcher[key].push(id)
      @@watcher_id[id] = watcher
      id
    }
  end

  # watcher idが _id_ のwatcherを削除する。
  def self.disconnect(id)
    synchronize{
      @@watcher_id.delete(id)
    }
  end

  def self.setup
    last_boot_version = UserConfig[:last_boot_version] || [0, 0, 0, 0]
    if last_boot_version < Environment::VERSION.to_a
      UserConfig[:last_boot_version] = Environment::VERSION.to_a
      if last_boot_version == [0, 0, 0, 0]
        key_add "Alt + x", "コンソールを開く", :console_open end
      if last_boot_version < [3, 3, 0, 0]
        UserConfig[:notification_enable] = true
        activity_show_statusbar = (UserConfig[:activity_show_statusbar] || []).map(&:to_s)
        unless activity_show_statusbar.include? 'streaming_status'
          activity_show_statusbar << 'streaming_status'
          UserConfig[:activity_show_statusbar] = activity_show_statusbar end end
      if last_boot_version < [3, 4, 0, 0]
        UserConfig[:replyviewer_background_color] = UserConfig[:mumble_reply_bg]
        UserConfig[:quote_background_color] = UserConfig[:mumble_basic_bg]
        UserConfig[:reply_text_font] = UserConfig[:mumble_reply_font] || 'Sans 8'
        UserConfig[:reply_text_color] = UserConfig[:mumble_reply_color] || [0x6666, 0x6666, 0x6666]
        UserConfig[:reply_icon_size] = 24
        UserConfig[:quote_text_font] = UserConfig[:reply_text_font] || 'Sans 8'
        UserConfig[:quote_text_color] = UserConfig[:reply_text_color]
        UserConfig[:reply_present_policy] = %i<icon>
        UserConfig[:quote_edge] = :floating
        UserConfig[:reply_text_max_line_count] = 3
        UserConfig[:reply_clicked_action] = nil
        UserConfig[:quote_clicked_action] = :smartthread
      end
    end
  end

  def self.key_add(key, name, slug)
    type_strict key => String, name => String, slug => Symbol
    keys = UserConfig[:shortcutkey_keybinds].melt
    keys[(keys.keys.max || 0)+1] = {
      :key => key,
      :name => name,
      :slug => slug}
    UserConfig[:shortcutkey_keybinds] = keys end

  setup

end