| 1 |
|
| 2 |
|
| 3 |
require 'configloader' |
| 4 |
require 'plugin' |
| 5 |
|
| 6 |
require 'singleton' |
| 7 |
require 'fileutils' |
| 8 |
|
| 9 |
|
| 10 |
的な設定 |
| 11 |
|
| 12 |
ら動的に変更される設定。 |
| 13 |
の設定ではないので注意。 |
| 14 |
class UserConfig |
| 15 |
include Singleton |
| 16 |
include ConfigLoader |
| 17 |
extend MonitorMixin |
| 18 |
|
| 19 |
れた設定一覧 |
| 20 |
|
| 21 |
|
| 22 |
@@defaults = { |
| 23 |
ルトのフッダ |
| 24 |
:footer => "", |
| 25 |
|
| 26 |
元を常に取得する |
| 27 |
:retrieve_force_mumbleparent => true, |
| 28 |
|
| 29 |
きを投稿するキー |
| 30 |
:shortcutkey_keybinds => {1 => {:key => "Control + Return", :name => '投稿する', :slug => :post_it}}, |
| 31 |
|
| 32 |
トをリトライする回数 |
| 33 |
:message_retry_limit => 10, |
| 34 |
|
| 35 |
表示しておく秒数 |
| 36 |
:notify_expire_time => 10, |
| 37 |
|
| 38 |
:retweeted_by_anyone_show_timeline => true, |
| 39 |
|
| 40 |
:retweeted_by_anyone_age => true, |
| 41 |
|
| 42 |
:favorited_by_anyone_show_timeline => true, |
| 43 |
|
| 44 |
:favorited_by_anyone_age => true, |
| 45 |
|
| 46 |
ールタブの並び順 |
| 47 |
:profile_tab_order => [:usertimeline, :aboutuser, :list], |
| 48 |
|
| 49 |
タブの並び順 |
| 50 |
:tab_order_in_settings => ["基本設定", "表示", "入力", "通知", "抽出タブ", "リスト", "ショートカットキー", "アカウント情報", "プロキシ"], |
| 51 |
|
| 52 |
[上,下,左,右] |
| 53 |
:tab_position => 3, |
| 54 |
|
| 55 |
短縮して投稿 |
| 56 |
:shrinkurl_always => false, |
| 57 |
|
| 58 |
展開して表示 |
| 59 |
:shrinkurl_expand => true, |
| 60 |
|
| 61 |
:bitly_user => '', |
| 62 |
:bitly_apikey => '', |
| 63 |
|
| 64 |
:mumble_basic_font => 'Sans 10', |
| 65 |
:mumble_basic_color => [0, 0, 0], |
| 66 |
:reply_text_font => 'Sans 8', |
| 67 |
:reply_text_color => [0, 0, 0], |
| 68 |
:quote_text_font => 'Sans 8', |
| 69 |
:quote_text_color => [0, 0, 0], |
| 70 |
:mumble_basic_left_font => 'Sans 10', |
| 71 |
:mumble_basic_left_color => [0, 0, 0], |
| 72 |
:mumble_basic_right_font => 'Sans 10', |
| 73 |
:mumble_basic_right_color => [0x9999, 0x9999, 0x9999], |
| 74 |
|
| 75 |
:mumble_basic_bg => [0xffff, 0xffff, 0xffff], |
| 76 |
:mumble_reply_bg => [0xffff, 0xdede, 0xdede], |
| 77 |
:mumble_self_bg => [0xffff, 0xffff, 0xdede], |
| 78 |
:mumble_selected_bg => [0xdede, 0xdede, 0xffff], |
| 79 |
:replyviewer_background_color => [0xffff, 0xdede, 0xdede], |
| 80 |
:quote_background_color => [0xffff, 0xffff, 0xffff], |
| 81 |
|
| 82 |
:reply_icon_size => 32, |
| 83 |
:quote_icon_size => 32, |
| 84 |
|
| 85 |
:reply_present_policy => %i<header icon edge>, |
| 86 |
:reply_edge => :solid, |
| 87 |
|
| 88 |
:quote_present_policy => %i<header icon edge>, |
| 89 |
:quote_edge => :solid, |
| 90 |
|
| 91 |
クメニューの並び順 |
| 92 |
:mumble_contextmenu_order => ['copy_selected_region', |
| 93 |
'copy_description', |
| 94 |
'reply', |
| 95 |
'reply_all', |
| 96 |
'retweet', |
| 97 |
'delete_retweet', |
| 98 |
'legacy_retweet', |
| 99 |
'favorite', |
| 100 |
'delete_favorite', |
| 101 |
'delete'], |
| 102 |
|
| 103 |
:subparts_order => ["Gdk::ReplyViewer", "Gdk::SubPartsFavorite", "Gdk::SubPartsShare"], |
| 104 |
|
| 105 |
:activity_mute_kind => ["error"], |
| 106 |
:activity_show_timeline => ["system", "achievement"], |
| 107 |
|
| 108 |
:notification_enable => true, |
| 109 |
|
| 110 |
:reply_text_max_line_count => 10, |
| 111 |
:quote_text_max_line_count => 10, |
| 112 |
:reply_clicked_action => :open, |
| 113 |
:quote_clicked_action => :open, |
| 114 |
|
| 115 |
:intent_selector_rules => [], |
| 116 |
|
| 117 |
:postbox_visibility => :auto, |
| 118 |
:world_shifter_visibility => :auto, |
| 119 |
|
| 120 |
:miraclepainter_expand_custom_emoji => true, |
| 121 |
:ui_scale => :auto |
| 122 |
} |
| 123 |
|
| 124 |
@@watcher = Hash.new{ [] } |
| 125 |
@@watcher_id = Hash.new |
| 126 |
@@watcher_id_count = 0 |
| 127 |
|
| 128 |
る値が存在するかを調べる。 |
| 129 |
_ や _false_ であっても _true_ を返す |
| 130 |
|
| 131 |
キー |
| 132 |
|
| 133 |
在する |
| 134 |
在しない |
| 135 |
def self.include?(key) |
| 136 |
UserConfig.instance.include?(key) || @@defaults.include?(key) |
| 137 |
end |
| 138 |
|
| 139 |
たいする値を取り出す |
| 140 |
ていない場合、nilを返す。 |
| 141 |
def self.[](key) |
| 142 |
UserConfig.instance.at(key, @@defaults[key.to_sym]) |
| 143 |
end |
| 144 |
|
| 145 |
ue_ を関連付ける |
| 146 |
def self.[]=(key, val) |
| 147 |
Plugin.call(:userconfig_modify, key, val) |
| 148 |
watchers = synchronize{ |
| 149 |
if not(@@watcher[key].empty?) |
| 150 |
before_val = UserConfig.instance.at(key, @@defaults[key.to_sym]) |
| 151 |
@@watcher[key].map{ |id| |
| 152 |
proc = if @@watcher_id.has_key?(id) |
| 153 |
@@watcher_id[id] |
| 154 |
else |
| 155 |
@@watcher[key].delete(id) |
| 156 |
nil end |
| 157 |
lambda{ proc.call(key, val, before_val, id) } if proc } end } |
| 158 |
if watchers.is_a? Enumerable |
| 159 |
watchers.each{ |w| w.call if w } end |
| 160 |
UserConfig.instance.store(key, val) |
| 161 |
end |
| 162 |
|
| 163 |
きに、ブロック _watcher_ を呼び出す。 |
| 164 |
返す。 |
| 165 |
def self.connect(key, &watcher) |
| 166 |
synchronize{ |
| 167 |
id = @@watcher_id_count |
| 168 |
@@watcher_id_count += 1 |
| 169 |
@@watcher[key] = @@watcher[key].push(id) |
| 170 |
@@watcher_id[id] = watcher |
| 171 |
id |
| 172 |
} |
| 173 |
end |
| 174 |
|
| 175 |
を削除する。 |
| 176 |
def self.disconnect(id) |
| 177 |
synchronize{ |
| 178 |
@@watcher_id.delete(id) |
| 179 |
} |
| 180 |
end |
| 181 |
|
| 182 |
def self.setup |
| 183 |
last_boot_version = UserConfig[:last_boot_version] || [0, 0, 0, 0] |
| 184 |
if last_boot_version < Environment::VERSION.to_a |
| 185 |
UserConfig[:last_boot_version] = Environment::VERSION.to_a |
| 186 |
if last_boot_version == [0, 0, 0, 0] |
| 187 |
key_add "Alt + x", "コンソールを開く", :console_open |
| 188 |
UserConfig[:postbox_visibility] = :always |
| 189 |
UserConfig[:world_shifter_visibility] = :always |
| 190 |
end |
| 191 |
if last_boot_version < [3, 3, 0, 0] |
| 192 |
UserConfig[:notification_enable] = true |
| 193 |
activity_show_statusbar = (UserConfig[:activity_show_statusbar] || []).map(&:to_s) |
| 194 |
unless activity_show_statusbar.include? 'streaming_status' |
| 195 |
activity_show_statusbar << 'streaming_status' |
| 196 |
UserConfig[:activity_show_statusbar] = activity_show_statusbar end end |
| 197 |
if last_boot_version < [3, 4, 0, 0] |
| 198 |
UserConfig[:replyviewer_background_color] = UserConfig[:mumble_reply_bg] |
| 199 |
UserConfig[:quote_background_color] = UserConfig[:mumble_basic_bg] |
| 200 |
UserConfig[:reply_text_font] = UserConfig[:mumble_reply_font] || 'Sans 8' |
| 201 |
UserConfig[:reply_text_color] = UserConfig[:mumble_reply_color] || [0x6666, 0x6666, 0x6666] |
| 202 |
UserConfig[:reply_icon_size] = 24 |
| 203 |
UserConfig[:quote_text_font] = UserConfig[:reply_text_font] || 'Sans 8' |
| 204 |
UserConfig[:quote_text_color] = UserConfig[:reply_text_color] |
| 205 |
UserConfig[:reply_present_policy] = %i<icon> |
| 206 |
UserConfig[:quote_edge] = :floating |
| 207 |
UserConfig[:reply_text_max_line_count] = 3 |
| 208 |
UserConfig[:reply_clicked_action] = nil |
| 209 |
UserConfig[:quote_clicked_action] = :smartthread |
| 210 |
end |
| 211 |
end |
| 212 |
end |
| 213 |
|
| 214 |
def self.key_add(key, name, slug) |
| 215 |
type_strict key => String, name => String, slug => Symbol |
| 216 |
keys = UserConfig[:shortcutkey_keybinds].melt |
| 217 |
keys[(keys.keys.max || 0)+1] = { |
| 218 |
:key => key, |
| 219 |
:name => name, |
| 220 |
:slug => slug} |
| 221 |
UserConfig[:shortcutkey_keybinds] = keys end |
| 222 |
|
| 223 |
setup |
| 224 |
|
| 225 |
end |