discourse-systray 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 342570ecbf8771500b6be8dd6deba05ceb429b4465746c3fa2fc822dedbff311
4
- data.tar.gz: c6a5dbc3ab88a256c2d9f5a9bda9def61ce26ec46a32280e4a81c144335f1017
3
+ metadata.gz: 95ff2cc576c4d66442c61d9834a3acec72c3e4580dafbee456207554b16af844
4
+ data.tar.gz: efab7206a8bdecf9bccdbd1dc0712954291e559cba789247be93b9b157d2e5d9
5
5
  SHA512:
6
- metadata.gz: 183b3a72d39b1f6525d7a2ce533829349709192f8da6ede5d53ae231441a3064e37e04eaa94050ed3e63327784184c9b004049521c7a79fc6f2db688618aec96
7
- data.tar.gz: 5c803012c9fdcaeea04465e8803e66f3531cec3c3487616256e24ede3b28d4e2a0e3a3e59c583fdb9a1a1618d411de98297b43b77ed7abd2c664e2a4a2e648de
6
+ metadata.gz: 034dc4dbe05f8a2d7f4a4fa8a82ea0e1baae3c200eceb7650a9ef8a37c2de9e8bd950d69d001838ac62c298dc59a9f820fc07b3a1d1baaf5c6e52c844d7e609e
7
+ data.tar.gz: 7c2c636e716c62ebc0412d2551c7913f4ecb31a1341ae9d1ae6d5d0eefc1b364868dc162d2217d331e513132be78a6f317ee15e7e3148a214a31906b0d5bfbfa
@@ -5,22 +5,19 @@ require "timeout"
5
5
  require "fileutils"
6
6
  require "json"
7
7
 
8
- # Parse command line options
9
- OPTIONS = { debug: false, path: nil }
10
-
11
- OptionParser
12
- .new do |opts|
13
- opts.banner = "Usage: systray.rb [options]"
14
- opts.on("--debug", "Enable debug mode") { OPTIONS[:debug] = true }
15
- opts.on("--path PATH", "Set Discourse path") { |p| OPTIONS[:path] = p }
16
- end
17
- .parse!
18
-
19
8
  class DiscourseSystemTray
20
9
  CONFIG_DIR = File.expand_path("~/.config/discourse-systray")
21
10
  CONFIG_FILE = File.join(CONFIG_DIR, "config.json")
11
+ OPTIONS = { debug: false, path: nil }
22
12
 
23
13
  def self.load_or_prompt_config
14
+ OptionParser
15
+ .new do |opts|
16
+ opts.banner = "Usage: systray.rb [options]"
17
+ opts.on("--debug", "Enable debug mode") { OPTIONS[:debug] = true }
18
+ opts.on("--path PATH", "Set Discourse path") { |p| OPTIONS[:path] = p }
19
+ end
20
+ .parse!
24
21
  FileUtils.mkdir_p(CONFIG_DIR) unless Dir.exist?(CONFIG_DIR)
25
22
 
26
23
  if OPTIONS[:path]
@@ -73,7 +70,10 @@ class DiscourseSystemTray
73
70
  def initialize
74
71
  @discourse_path = self.class.load_or_prompt_config
75
72
  @indicator = Gtk::StatusIcon.new
76
- @indicator.pixbuf = GdkPixbuf::Pixbuf.new(file: File.join(File.dirname(__FILE__), "../../assets/discourse.png"))
73
+ @indicator.pixbuf =
74
+ GdkPixbuf::Pixbuf.new(
75
+ file: File.join(File.dirname(__FILE__), "../../assets/discourse.png")
76
+ )
77
77
  @indicator.tooltip_text = "Discourse Manager"
78
78
  @running = false
79
79
  @ember_output = []
@@ -160,6 +160,17 @@ class DiscourseSystemTray
160
160
  def cleanup
161
161
  return if @processes.empty?
162
162
 
163
+ # First disable updates to prevent race conditions
164
+ @view_timeouts&.values&.each do |id|
165
+ begin
166
+ GLib::Source.remove(id)
167
+ rescue StandardError => e
168
+ puts "Error removing timeout: #{e}" if OPTIONS[:debug]
169
+ end
170
+ end
171
+ @view_timeouts&.clear
172
+
173
+ # Then stop processes
163
174
  @processes.each do |name, process|
164
175
  begin
165
176
  Process.kill("TERM", process[:pid])
@@ -172,21 +183,11 @@ class DiscourseSystemTray
172
183
  @processes.clear
173
184
  @ember_running = false
174
185
  @unicorn_running = false
175
- update_tab_labels if @notebook
176
186
 
177
- # Clean up window and timeouts on exit
178
- if @status_window
179
- # Clean up any existing timeouts
180
- if @view_timeouts
181
- @view_timeouts.values.each do |id|
182
- begin
183
- GLib::Source.remove(id)
184
- rescue StandardError
185
- nil
186
- end
187
- end
188
- @view_timeouts.clear
189
- end
187
+ # Finally clean up UI elements
188
+ update_tab_labels if @notebook && !@notebook.destroyed?
189
+
190
+ if @status_window && !@status_window.destroyed?
190
191
  @status_window.destroy
191
192
  @status_window = nil
192
193
  end
@@ -315,10 +316,22 @@ class DiscourseSystemTray
315
316
  end
316
317
 
317
318
  def update_all_views
319
+ return unless @status_window && !@status_window.destroyed?
318
320
  return unless @ember_view && @unicorn_view
321
+ return unless @ember_view.child && @unicorn_view.child
322
+ return if @ember_view.destroyed? || @unicorn_view.destroyed?
323
+ return if @ember_view.child.destroyed? || @unicorn_view.child.destroyed?
319
324
 
320
- update_log_view(@ember_view.child, @ember_output)
321
- update_log_view(@unicorn_view.child, @unicorn_output)
325
+ begin
326
+ if @ember_view.visible? && @ember_view.child.visible?
327
+ update_log_view(@ember_view.child, @ember_output)
328
+ end
329
+ if @unicorn_view.visible? && @unicorn_view.child.visible?
330
+ update_log_view(@unicorn_view.child, @unicorn_output)
331
+ end
332
+ rescue StandardError => e
333
+ puts "Error updating views: #{e}" if OPTIONS[:debug]
334
+ end
322
335
  end
323
336
 
324
337
  def create_log_view(buffer)
@@ -393,8 +406,9 @@ class DiscourseSystemTray
393
406
  end
394
407
 
395
408
  def update_log_view(text_view, buffer)
396
- return if buffer.empty? || text_view.nil? || !text_view.visible?
397
- return unless text_view.parent&.visible?
409
+ return if buffer.empty? || text_view.nil? || text_view.destroyed?
410
+ return unless text_view.visible? && text_view.parent&.visible?
411
+ return if text_view.buffer.nil? || text_view.buffer.destroyed?
398
412
 
399
413
  text_view.buffer.text = ""
400
414
  iter = text_view.buffer.get_iter_at(offset: 0)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discourse-systray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron