From 0e502f6d5ccd1c9cd6719cebffa2384c67d0cbd4 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 23 Mar 2020 00:10:19 -0400 Subject: [PATCH] Ensures the macOS version retains volume. --- .../Base.lproj/MachineDocument.xib | 1 + .../Documents/MachineDocument.swift | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Base.lproj/MachineDocument.xib b/OSBindings/Mac/Clock Signal/Base.lproj/MachineDocument.xib index 32fd2c841..8d955fcaf 100644 --- a/OSBindings/Mac/Clock Signal/Base.lproj/MachineDocument.xib +++ b/OSBindings/Mac/Clock Signal/Base.lproj/MachineDocument.xib @@ -9,6 +9,7 @@ + diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index 9fdf62fd6..f5912a427 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -64,7 +64,8 @@ class MachineDocument: } /// The volume view. - @IBOutlet var volumeView: NSView! + @IBOutlet var volumeView: NSBox! + @IBOutlet var volumeSlider: NSSlider! // MARK: - NSDocument Overrides and NSWindowDelegate methods. @@ -114,6 +115,7 @@ class MachineDocument: override func windowControllerDidLoadNib(_ aController: NSWindowController) { super.windowControllerDidLoadNib(aController) aController.window?.contentAspectRatio = self.aspectRatio() + volumeSlider.floatValue = userDefaultsVolume() } private var missingROMs: [CSMissingROM] = [] @@ -125,6 +127,7 @@ class MachineDocument: self.machine = machine setupMachineOutput() setupActivityDisplay() + machine.setVolume(userDefaultsVolume()) } else { // Store the selected machine and list of missing ROMs, and // show the missing ROMs dialogue. @@ -720,7 +723,8 @@ class MachineDocument: // MARK: - Volume Control. @IBAction func setVolume(_ sender: NSSlider!) { if let machine = self.machine { - machine.setVolume(sender.floatValue); + machine.setVolume(sender.floatValue) + setUserDefaultsVolume(sender.floatValue) } } @@ -767,4 +771,14 @@ class MachineDocument: volumeView.layer?.opacity = 0.0 } } + + // The user's selected volume is stored as 1 - volume in the user defaults in order + // to take advantage of the default value being 0. + private func userDefaultsVolume() -> Float { + return 1.0 - UserDefaults.standard.float(forKey: "defaultVolume") + } + + private func setUserDefaultsVolume(_ volume: Float) { + UserDefaults.standard.set(1.0 - volume, forKey: "defaultVolume") + } }