Skip to content

Commit 64c8e25

Browse files
committed
Add baked_file_system for baked sound files into binary and use it directly in memory.
1 parent 14acd60 commit 64c8e25

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

shard.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ targets:
55
sentry:
66
main: src/sentry_cli.cr
77

8+
dependencies:
9+
baked_file_system:
10+
github: schovi/baked_file_system
11+
version: 0.10.0
12+
813
authors:
914
- Sam Eaton <[email protected]>
1015
crystal: ">= 0.34.0"

src/sentry.cr

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "yaml"
22
require "colorize"
3+
require "./sound_file_storage"
34

45
module Sentry
56
FILE_TIMESTAMPS = {} of String => String # {file => timestamp}
@@ -146,8 +147,8 @@ module Sentry
146147
property should_build = true
147148
property files = [] of String
148149
@sound_player : String = ""
149-
@success_wav = "#{__DIR__}/sounds/success.wav"
150-
@error_wav = "#{__DIR__}/sounds/error.wav"
150+
@success_wav : BakedFileSystem::BakedFile = SoundFileStorage.get("success.wav")
151+
@error_wav : BakedFileSystem::BakedFile = SoundFileStorage.get("error.wav")
151152

152153
def initialize(
153154
@display_name : String,
@@ -167,13 +168,11 @@ module Sentry
167168
@should_install_shards = install_shards
168169
@colorize = colorize
169170

170-
if File.exists?(@success_wav) && File.exists?(@error_wav)
171-
{% if flag?(:linux) %}
172-
@sound_player = `which aplay 2>/dev/null`.chomp
173-
{% elsif flag(:darwin) %}
174-
@sound_player = `which afplay 2>/dev/null`.chomp
175-
{% end %}
176-
end
171+
{% if flag?(:linux) %}
172+
@sound_player = `which aplay 2>/dev/null`.chomp
173+
{% elsif flag(:darwin) %}
174+
@sound_player = `which afplay 2>/dev/null`.chomp
175+
{% end %}
177176
end
178177

179178
private def stdout(str : String)
@@ -225,13 +224,22 @@ module Sentry
225224
if build_result && build_result.success?
226225
@app_built = true
227226
create_app_process()
228-
`#{@sound_player} #{@success_wav} 2>/dev/null` unless @sound_player.blank?
227+
unless @sound_player.blank?
228+
Process.new(command: @sound_player, input: @success_wav)
229+
@success_wav.rewind
230+
end
229231
elsif !@app_built # if build fails on first time compiling, then exit
230232
stdout "🤖 Compile time errors detected. SentryBot shutting down..."
231-
`#{@sound_player} #{@error_wav} 2>/dev/null` unless @sound_player.blank?
233+
unless @sound_player.blank?
234+
Process.new(command: @sound_player, input: @error_wav)
235+
@error_wav.rewind
236+
end
232237
exit 1
233238
else
234-
`#{@sound_player} #{@error_wav} 2>/dev/null` unless @sound_player.blank?
239+
unless @sound_player.blank?
240+
Process.new(command: @sound_player, input: @error_wav)
241+
@error_wav.rewind
242+
end
235243
end
236244
end
237245

src/sound_file_storage.cr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "baked_file_system"
2+
3+
class SoundFileStorage
4+
extend BakedFileSystem
5+
6+
bake_folder "./sounds"
7+
end

0 commit comments

Comments
 (0)