aboutsummaryrefslogtreecommitdiffstats
path: root/mikutter.rb
blob: 5e3fe84b8c3ab4ba43f88721603d399b77b24391 (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
#! /usr/bin/ruby
# -*- coding: utf-8 -*-
=begin rdoc
= mikutter - the moest twitter client
Copyright (C) 2009-2010 Toshiaki Asai

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

=end

Dir.chdir(File.join(File.dirname($0), 'core'))
Thread.abort_on_exception = true
ENV['LIBOVERLAY_SCROLLBAR'] = '0'

require 'benchmark'
require 'webrick'
require 'thread'
require 'fileutils'

require File.expand_path('boot/option')
require File.expand_path('utils')

miquire :boot, 'check_config_permission'
miquire :core, 'post'
miquire :boot, 'load_plugin'

notice "fire boot event"
Plugin.call(:boot, Post.primary_service)

Gtk.timeout_add(100){
  Delayer.run
  true }

# イベントの待受を開始する。
# _profile_ がtrueなら、プロファイリングした結果を一時ディレクトリに保存する
def boot!(profile)
  if profile
    require 'ruby-prof'
    begin
      notice 'start profiling'
      RubyProf.start
      Gtk.main
    ensure
      result = RubyProf.stop
      printer = RubyProf::CallTreePrinter.new(result)
      profile_out = File.join(File.expand_path(Environment::TMPDIR), 'profile-'+Time.new.strftime('%Y-%m-%d-%H%M%S')+'.out')
      notice "profile: writing to #{profile_out}"
      printer.print(File.open(profile_out, 'w'), {})
      notice "profile: done."
    end
  else
    Gtk.main end
rescue => e
  into_debug_mode(e) end

begin
  errfile = File.join(File.expand_path(Environment::TMPDIR), 'mikutter_dump')
  File.rename(errfile, File.expand_path(File.join(Environment::TMPDIR, 'mikutter_error'))) if File.exist?(errfile)
  if not Mopt.debug
    $stderr = File.open(errfile, 'w')
    def $stderr.write(string)
      super(string)
      self.fsync rescue nil end end
  boot!(Mopt.profile)
rescue Interrupt => e
  File.delete(errfile) if File.exist?(errfile)
  raise e
rescue Exception => e
  m = e.backtrace.first.match(/(.+?):(\d+)/)
  file_put_contents(File.join(File.expand_path(Environment::TMPDIR), 'crashed_file'), m[1])
  file_put_contents(File.join(File.expand_path(Environment::TMPDIR), 'crashed_line'), m[2])
  raise e
end