discourse-systray 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/discourse_systray/systray.rb +73 -115
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2a747e5c405b575a86d5ec8976fcd670f089b5af9bd5452b6077138c8a63830
4
- data.tar.gz: 1a2354eece536b24f535b0bdd46612517685da8402703d07da40f136ad33d63c
3
+ metadata.gz: 52f16a25286153255ec00c850f08e74cd2b704903d8adf850705f17aa6898fdb
4
+ data.tar.gz: 4f708705f6669dff35a737ff328917c3b603b7cc7f87c0c1d3a7602ee0157852
5
5
  SHA512:
6
- metadata.gz: 6e8cd660630fdd77c5b9ba901caa3507593e87524dd12b884a7fffd59c1070c1d065bed0297694c806841a463ad3d4cf41d660b3a92d70f186fba4494cfc002c
7
- data.tar.gz: 5f3b2075cda0f0a8b7703fb34f06c075357325d16bb9964a5c7c21d3350a697b45286b7764964aa46a84d3db37a22ee8c22ab553170e125095d7ee1808d6c6d8
6
+ metadata.gz: ffaf161d05e11185dde22eb1f4a8c61dd42fa14ffcc72738391e5a8f54c68523f225d8442bd83f49bdec36c15e7237bf58eb351811781f845bedd15f92592781
7
+ data.tar.gz: 5cf888a341f139472fc4858731310d42e4586910f19992643c015e1be1f95ce20140d9d37ca0b8644f8fd2afa8d363b185cc42509d1a41f96293ae338f3dfa3a
@@ -321,7 +321,6 @@ module ::DiscourseSystray
321
321
 
322
322
  # Force immediate GUI update
323
323
  GLib::Idle.add do
324
- show_status_window if @status_window.nil? || !@status_window.visible?
325
324
  update_all_views
326
325
  false
327
326
  end
@@ -356,7 +355,7 @@ module ::DiscourseSystray
356
355
  end
357
356
 
358
357
  # Also publish to pipe for --attach mode in background
359
- publish_to_pipe(line)
358
+ publish_to_pipe(line, process: command.include?("ember-cli") ? :ember : :unicorn, stream: :stdout)
360
359
  end
361
360
  rescue => e
362
361
  puts "DEBUG: Error in stdout thread: #{e.message}" if OPTIONS[:debug]
@@ -383,7 +382,7 @@ module ::DiscourseSystray
383
382
  puts "[ERR] #{line}" if OPTIONS[:debug]
384
383
 
385
384
  # Format error line
386
- error_line = "ERROR: #{line}"
385
+ error_line = "E: #{line}"
387
386
 
388
387
  # Add to buffer with size management
389
388
  buffer << error_line
@@ -408,7 +407,7 @@ module ::DiscourseSystray
408
407
  end
409
408
 
410
409
  # Also publish to pipe for --attach mode in background
411
- publish_to_pipe(error_line)
410
+ publish_to_pipe(error_line, process: command.include?("ember-cli") ? :ember : :unicorn, stream: :stderr)
412
411
  end
413
412
  rescue => e
414
413
  puts "DEBUG: Error in stderr thread: #{e.message}" if OPTIONS[:debug]
@@ -447,10 +446,7 @@ module ::DiscourseSystray
447
446
  if @status_window.window
448
447
  @status_window.window.raise
449
448
  if system("which i3-msg >/dev/null 2>&1")
450
- # First move to current workspace, then focus
451
- system(
452
- "i3-msg '[id=#{@status_window.window.xid}] move workspace current'"
453
- )
449
+ system("i3-msg '[id=#{@status_window.window.xid}] move workspace current'")
454
450
  system("i3-msg '[id=#{@status_window.window.xid}] focus'")
455
451
  end
456
452
  end
@@ -464,13 +460,19 @@ module ::DiscourseSystray
464
460
  return
465
461
  end
466
462
 
467
- # Clean up any existing window
463
+ # Clean up any existing window and notebook
468
464
  if @status_window
469
465
  puts "DEBUG: Destroying existing status window" if OPTIONS[:debug]
466
+ @notebook = nil # Clear notebook reference
467
+ @ember_view = nil
468
+ @unicorn_view = nil
469
+ @ember_label = nil
470
+ @unicorn_label = nil
470
471
  @status_window.destroy
471
472
  @status_window = nil
472
473
  end
473
474
 
475
+ # Create new window and components
474
476
  puts "DEBUG: Creating new status window" if OPTIONS[:debug]
475
477
  @status_window = Gtk::Window.new("Discourse Status")
476
478
  @status_window.set_wmclass("discourse-status", "Discourse Status")
@@ -504,24 +506,24 @@ module ::DiscourseSystray
504
506
  false
505
507
  end
506
508
 
509
+ # Create notebook only if it doesn't exist
507
510
  puts "DEBUG: Creating notebook" if OPTIONS[:debug]
508
511
  @notebook = Gtk::Notebook.new
509
512
 
510
- # Debug buffer contents before creating views
511
- puts "DEBUG: ember_output size: #{@ember_output.size}" if OPTIONS[:debug]
512
- puts "DEBUG: unicorn_output size: #{@unicorn_output.size}" if OPTIONS[:debug]
513
-
514
- puts "DEBUG: Creating ember view" if OPTIONS[:debug]
515
- @ember_view = create_log_view(@ember_output)
516
- @ember_label = create_status_label("Ember CLI", @ember_running)
517
- @notebook.append_page(@ember_view, @ember_label)
518
- puts "DEBUG: Added ember view to notebook" if OPTIONS[:debug]
513
+ # Only create views if they don't exist
514
+ if @ember_view.nil?
515
+ puts "DEBUG: Creating ember view" if OPTIONS[:debug]
516
+ @ember_view = create_log_view(@ember_output)
517
+ @ember_label = create_status_label("Ember CLI", @ember_running)
518
+ @notebook.append_page(@ember_view, @ember_label)
519
+ end
519
520
 
520
- puts "DEBUG: Creating unicorn view" if OPTIONS[:debug]
521
- @unicorn_view = create_log_view(@unicorn_output)
522
- @unicorn_label = create_status_label("Unicorn", @unicorn_running)
523
- @notebook.append_page(@unicorn_view, @unicorn_label)
524
- puts "DEBUG: Added unicorn view to notebook" if OPTIONS[:debug]
521
+ if @unicorn_view.nil?
522
+ puts "DEBUG: Creating unicorn view" if OPTIONS[:debug]
523
+ @unicorn_view = create_log_view(@unicorn_output)
524
+ @unicorn_label = create_status_label("Unicorn", @unicorn_running)
525
+ @notebook.append_page(@unicorn_view, @unicorn_label)
526
+ end
525
527
 
526
528
  @status_window.add(@notebook)
527
529
  puts "DEBUG: Added notebook to status window" if OPTIONS[:debug]
@@ -821,19 +823,12 @@ module ::DiscourseSystray
821
823
  if OPTIONS[:attach]
822
824
  require "rb-inotify"
823
825
 
824
- # Initialize GTK for attach mode too
825
- Gtk.init
826
-
827
- # Initialize empty buffers
828
- @ember_output = []
829
- @unicorn_output = []
830
-
831
- # Show status window immediately in attach mode too
832
- GLib::Idle.add do
833
- show_status_window
834
- false
826
+ # Set up signal handling for Ctrl+C
827
+ Signal.trap("INT") do
828
+ puts "Received interrupt signal, shutting down..."
829
+ exit 0
835
830
  end
836
-
831
+
837
832
  notifier = INotify::Notifier.new
838
833
 
839
834
  begin
@@ -848,65 +843,57 @@ module ::DiscourseSystray
848
843
  end
849
844
 
850
845
  # Read from pipe in a separate thread
851
- reader =
852
- Thread.new do
853
- begin
854
- while true
855
- begin
856
- # Use non-blocking read with timeout
857
- ready = IO.select([pipe], nil, nil, 0.1)
858
- if ready && ready[0].include?(pipe)
859
- line = pipe.gets
860
- if line
861
- puts line
862
- STDOUT.flush
863
-
864
- # Process the line for our buffers
865
- if line.include?("ember") || line.include?("Ember") || line.include?("ERROR: ...")
866
- @ember_output << line
867
- puts "DEBUG: Added to ember buffer: #{line}" if OPTIONS[:debug]
868
- else
869
- @unicorn_output << line
870
- puts "DEBUG: Added to unicorn buffer: #{line}" if OPTIONS[:debug]
871
- end
872
-
873
- # Force GUI update immediately
874
- GLib::Idle.add do
875
- update_all_views
876
- false
877
- end
878
- end
846
+ reader = Thread.new do
847
+ # Set thread abort on exception
848
+ Thread.current.abort_on_exception = true
849
+
850
+ begin
851
+ while true
852
+ begin
853
+ # Use non-blocking read with timeout
854
+ ready = IO.select([pipe], nil, nil, 0.1)
855
+ if ready && ready[0].include?(pipe)
856
+ line = pipe.gets
857
+ if line
858
+ puts line
859
+ STDOUT.flush
879
860
  end
880
- rescue IOError, Errno::EBADF => e
881
- puts "DEBUG: Pipe read error: #{e.message}" if OPTIONS[:debug]
882
- break
883
861
  end
862
+ rescue IOError, Errno::EBADF => e
863
+ puts "DEBUG: Pipe read error: #{e.message}" if OPTIONS[:debug]
864
+ break
865
+ end
884
866
 
885
- # Check if pipe still exists
886
- unless File.exist?(PIPE_PATH)
887
- puts "Pipe was deleted, exiting."
888
- exit 0
889
- end
890
-
891
- # Small sleep to prevent CPU hogging
892
- sleep 0.01
867
+ # Check if pipe still exists
868
+ unless File.exist?(PIPE_PATH)
869
+ puts "Pipe was deleted, exiting."
870
+ exit 0
893
871
  end
894
- rescue EOFError, IOError
895
- puts "Pipe closed, exiting."
896
- exit 0
872
+
873
+ # Small sleep to prevent CPU hogging
874
+ sleep 0.01
897
875
  end
876
+ rescue EOFError, IOError
877
+ puts "Pipe closed, exiting."
878
+ exit 0
898
879
  end
899
-
900
- # Start GTK main loop in a separate thread
901
- gtk_thread = Thread.new do
902
- Gtk.main
903
880
  end
904
881
 
905
- # Handle notifications in main thread
906
- notifier.run
882
+ # Set up non-blocking notifier processing
883
+ # Instead of notifier.run which blocks indefinitely, use a loop with timeout
884
+ while true
885
+ # Process any pending inotify events, with timeout
886
+ notifier.process
887
+
888
+ # Sleep briefly to prevent CPU hogging
889
+ sleep 0.1
890
+ end
907
891
  rescue Errno::ENOENT
908
892
  puts "Pipe doesn't exist, exiting."
909
893
  exit 1
894
+ rescue Interrupt
895
+ puts "Interrupted, exiting."
896
+ exit 0
910
897
  ensure
911
898
  reader&.kill
912
899
  pipe&.close
@@ -937,12 +924,6 @@ module ::DiscourseSystray
937
924
  # Setup systray icon and menu
938
925
  init_systray
939
926
 
940
- # Show status window immediately on startup
941
- GLib::Idle.add do
942
- show_status_window
943
- false
944
- end
945
-
946
927
  # Start GTK main loop
947
928
  Gtk.main
948
929
  end
@@ -982,33 +963,10 @@ module ::DiscourseSystray
982
963
  end
983
964
  end
984
965
 
985
- def publish_to_pipe(msg)
986
- puts "Publish to pipe: #{msg}" if OPTIONS[:debug]
987
-
988
- # Add to our buffers directly - do this immediately
989
- if msg.include?("ember") || msg.include?("Ember") || msg.include?("ERROR: ...")
990
- @ember_output ||= []
991
- @ember_output << msg
992
- # Trim if needed
993
- if @ember_output.size > BUFFER_SIZE
994
- @ember_output.shift(@ember_output.size - BUFFER_SIZE)
995
- end
996
- else
997
- @unicorn_output ||= []
998
- @unicorn_output << msg
999
- # Trim if needed
1000
- if @unicorn_output.size > BUFFER_SIZE
1001
- @unicorn_output.shift(@unicorn_output.size - BUFFER_SIZE)
1002
- end
1003
- end
1004
-
1005
- # Force GUI update immediately
1006
- GLib::Idle.add do
1007
- update_all_views if defined?(update_all_views)
1008
- false
1009
- end
966
+ def publish_to_pipe(msg, process: nil, stream: nil)
967
+ source_info = "[#{process || 'unknown'}:#{stream || 'unknown'}]"
968
+ puts "Publish to pipe #{source_info}: #{msg}" if OPTIONS[:debug]
1010
969
 
1011
- # Queue the message for pipe writing in background
1012
970
  @pipe_queue.push(msg) if @pipe_queue
1013
971
  end
1014
972
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discourse-systray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-07 00:00:00.000000000 Z
11
+ date: 2025-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gtk3