<commit_before>import Cocoa
import AudioToolbox

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
  func applicationDidFinishLaunching(_ aNotification: Notification) {
    let defaultOutputDeviceID: AudioDeviceID?
    do {
      try defaultOutputDeviceID = getDefaultOutputDevice()
      NSLog("Default output device ID: \(defaultOutputDeviceID)")
      
      do {
        let currentVolume: Float32 = try getDeviceVolume(outputDeviceID: defaultOutputDeviceID!)
        NSLog("Current volume: \(currentVolume)")
      } catch VolumeError.failedToGetVolume(let status) {
        NSLog("Failed to get current volume: \(status)")
      } catch VolumeError.outputDeviceHasNoVolumeProperty {
        NSLog("Output device missing volume property")
      }
      
      do {
        try setDeviceVolume(outputDeviceID: defaultOutputDeviceID!, value: 0.25)
      } catch VolumeError.failedToSetVolume(let status) {
        NSLog("Failed to set current volume: \(status)")
      } catch VolumeError.outputDeviceHasNoVolumeProperty {
        NSLog("Output device missing volume property")
      }
    } catch {
      NSLog("No default output device found")
    }
    
    NSLog("Setting up will sleep & did wake notifications")
    let nc = NSWorkspace.shared().notificationCenter
    nc.addObserver(forName: NSNotification.Name.NSWorkspaceWillSleep, object: nil, queue: nil) { (notification: Notification) in
      NSLog("Workspace will sleep")
      NSLog(notification.description)
    }
    
    nc.addObserver(forName: NSNotification.Name.NSWorkspaceDidWake, object: nil, queue: nil) { (notification: Notification) in
      NSLog("Workspace did wake")
      NSLog(notification.description)
    }
  }

  func applicationWillTerminate(_ aNotification: Notification) {
  }<commit_msg>Add desired volume preference and set it on wake.<commit_after>import Cocoa
import AudioToolbox

// TODO Add function to check device (simplifies repeated if checks

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
  let desiredVolumeKey: String = "desiredVolume"
  
  func applicationDidFinishLaunching(_ aNotification: Notification) {
    // ---
    var defaultOutputDeviceID: AudioDeviceID? = kAudioObjectUnknown // TODO Remove default assigned value?
    do {
      try defaultOutputDeviceID = getDefaultOutputDevice()
      NSLog("Default output device ID: \(defaultOutputDeviceID)")
      
      do {
        let currentVolume: Float32 = try getDeviceVolume(outputDeviceID: defaultOutputDeviceID!)
        NSLog("Current volume: \(currentVolume)")
      } catch VolumeError.failedToGetVolume(let status) {
        NSLog("Failed to get current volume: \(status)")
      } catch VolumeError.outputDeviceHasNoVolumeProperty {
        NSLog("Output device missing volume property")
      }
      
      do {
        try setDeviceVolume(outputDeviceID: defaultOutputDeviceID!, value: 0.25)
      } catch VolumeError.failedToSetVolume(let status) {
        NSLog("Failed to set current volume: \(status)")
      } catch VolumeError.outputDeviceHasNoVolumeProperty {
        NSLog("Output device missing volume property")
      }
    } catch {
      NSLog("No default output device found")
    }
    
    // ---
    let defaults = UserDefaults.standard
    defaults.set(0.0, forKey: desiredVolumeKey)
    var desiredVolume = defaults.float(forKey: desiredVolumeKey)
    
    // ---
    NSLog("Setting up will sleep & did wake notifications")
    let nc = NSWorkspace.shared().notificationCenter
    nc.addObserver(forName: NSNotification.Name.NSWorkspaceWillSleep, object: nil, queue: nil) { (notification: Notification) in
      NSLog("Workspace will sleep")
      NSLog(notification.description)
    }
    
    nc.addObserver(forName: NSNotification.Name.NSWorkspaceDidWake, object: nil, queue: nil) { (notification: Notification) in
      NSLog("Workspace did wake")
      NSLog(notification.description)
      guard defaultOutputDeviceID != nil && defaultOutputDeviceID != kAudioObjectUnknown else {
        NSLog("defaultOutputDeviceID invalid")
        return
      }
      

      do {
        try setDeviceVolume(outputDeviceID: defaultOutputDeviceID!, value: desiredVolume)
      } catch VolumeError.failedToSetVolume {
          
      } catch VolumeError.outputDeviceHasNoVolumeProperty {
          
      } catch {
      
      }

    }
  }

  func applicationWillTerminate(_ aNotification: Notification) {
  }
{'fraction_non_alphanumeric': 0.08597794283142021, 'fraction_numerical': 0.0027008777852802163, 'mean_word_length': 3.3525954946131242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5369016', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1154, 'n_words': 296}