Class: AppCask::LocalApp

Inherits:
Object
  • Object
show all
Defined in:
lib/appcask/local_app.rb

Constant Summary collapse

APPS_DIR =
"/Applications"
OUTPUT_BASE =
File.join(Dir.home, "Desktop", "AppCask Downloads", "Local Apps")

Class Method Summary collapse

Class Method Details

.fetch_allObject



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
# File 'lib/appcask/local_app.rb', line 14

def fetch_all
  puts "\nFetching local app icons..."
  puts "Source: #{APPS_DIR}"
  puts "Output: #{OUTPUT_BASE}\n\n"

  FileUtils.mkdir_p(OUTPUT_BASE)

  apps = Dir.glob(File.join(APPS_DIR, "*.app"))
  total = apps.count
  success = 0
  skipped = 0

  apps.each_with_index do |app_path, index|
    app_name = File.basename(app_path, ".app")
    print "\r[#{index + 1}/#{total}] Processing: #{app_name.ljust(30)}"

    result = extract_icon(app_path)
    if result
      success += 1
    else
      skipped += 1
    end
  end

  puts "\n\n#{"=" * 50}"
  puts "Done!"
  puts "  Total apps: #{total}"
  puts "  Extracted: #{success}"
  puts "  Skipped: #{skipped}"
  puts "  Output: #{OUTPUT_BASE}"
  puts "=" * 50

  # Open folder on macOS
  return unless RUBY_PLATFORM.include?("darwin")

  print "\nOpen the folder? (y/n): "
  response = $stdin.gets
  system("open '#{OUTPUT_BASE}'") if response&.strip&.downcase == "y"
end