class StreamdeckProf::Context

Public Class Methods

new(profiles_dir: default_profiles_dir) click to toggle source
# File lib/streamdeck_prof/context.rb, line 9
def initialize(profiles_dir: default_profiles_dir)
  @profiles_dir = profiles_dir
end

Public Instance Methods

default_profile() click to toggle source
# File lib/streamdeck_prof/context.rb, line 27
def default_profile
  profile_for_application("*")
end
new_profile(type: :xl) click to toggle source
# File lib/streamdeck_prof/context.rb, line 35
def new_profile(type: :xl)
  manifest = StreamdeckProf::DeviceData.const_get(type.upcase)[:empty_profile]
  uuid = SecureRandom.uuid.upcase
  profile_path = File.join(@profiles_dir, "#{uuid}.sdProfile")
  manifest_path = File.join(profile_path, "manifest.json")

  Dir.mkdir(profile_path)
  File.write(manifest_path, JSON.dump(manifest))

  @profiles = nil

  Profile.new(profile_path)
end
profile_by_name(name) click to toggle source
# File lib/streamdeck_prof/context.rb, line 31
def profile_by_name(name)
  profiles.find { |p| p.name == name }
end
profile_for_application(application, exact: true) click to toggle source
# File lib/streamdeck_prof/context.rb, line 19
def profile_for_application(application, exact: true)
  if exact
    profiles.find { |p| p.app_identifier == application }
  else
    profiles.find { |p| p.app_identifier&.include?(application) }
  end
end
profiles() click to toggle source
# File lib/streamdeck_prof/context.rb, line 13
def profiles
  @profiles ||= Dir.glob(File.join(@profiles_dir, "*.sdProfile"))
                   .map { |profile_path| Profile.new(profile_path) }
                   .freeze
end

Private Instance Methods

default_profiles_dir() click to toggle source
# File lib/streamdeck_prof/context.rb, line 51
def default_profiles_dir
  if Gem.win_platform?
    File.join(ENV["APPDATA"], "Elgato/StreamDeck/ProfilesV2")
  else
    File.expand_path("~/Library/Application Support/com.elgato.StreamDeck/ProfilesV2")
  end
end