Skip to content

Commit

Permalink
Fix issue with viewport width dropdown being stale
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyalIcing committed Nov 8, 2019
1 parent 86d5903 commit 092772b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Lantern/BrowserMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BrowserMenuController: NSObject, NSUserInterfaceValidations {
var browserPreferencesObserver: NotificationObserver<BrowserPreferences.Notification>!

var browserPrefences: BrowserPreferences {
return BrowserPreferences.sharedBrowserPreferences
return BrowserPreferences.shared
}

init(browserWidthPlaceholderMenuItem: NSMenuItem) {
Expand All @@ -60,7 +60,7 @@ class BrowserMenuController: NSObject, NSUserInterfaceValidations {
// return (chosenWidthChoice == widthChoice) ? NSOnState : NSOffState
// }
widthMenuItemsAssistant.customization.additionalSetUp = { widthChoice, menuItem in
let chosenWidthChoice = BrowserPreferences.sharedBrowserPreferences.widthChoice
let chosenWidthChoice = BrowserPreferences.shared.widthChoice
menuItem.state = (chosenWidthChoice == widthChoice) ? NSControl.StateValue.on : NSControl.StateValue.off
}

Expand All @@ -78,7 +78,7 @@ class BrowserMenuController: NSObject, NSUserInterfaceValidations {
}

func startObservingBrowserPreferences() {
browserPreferencesObserver = NotificationObserver<BrowserPreferences.Notification>(object: BrowserPreferences.sharedBrowserPreferences)
browserPreferencesObserver = NotificationObserver<BrowserPreferences.Notification>(object: BrowserPreferences.shared)

browserPreferencesObserver.observe(.widthChoiceDidChange) { notification in
self.updateWidthMenu()
Expand All @@ -95,7 +95,7 @@ class BrowserMenuController: NSObject, NSUserInterfaceValidations {
menuItem = sender as? NSMenuItem,
let widthChoice = widthMenuItemsAssistant.itemRepresentative(for: menuItem)
{
BrowserPreferences.sharedBrowserPreferences.widthChoice = widthChoice
BrowserPreferences.shared.widthChoice = widthChoice
}
}

Expand Down
6 changes: 3 additions & 3 deletions Lantern/BrowserPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ class BrowserPreferences {
}
}

func updateFromDefaults() {
private func updateFromDefaults() {
widthChoice = ud.choice(BrowserWidthChoice.self)
}

init() {
private init() {
updateFromDefaults()
}

static var sharedBrowserPreferences = BrowserPreferences()
static var shared = BrowserPreferences()
}
6 changes: 3 additions & 3 deletions Lantern/CrawlerMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CrawlerMenuController: NSObject, NSUserInterfaceValidations {
// return (chosenImageDownloadChoice == imageDownloadChoice) ? NSOnState : NSOffState
// }
imageDownloadMenuItemsAssistant.customization.additionalSetUp = { imageDownloadChoice, menuItem in
let chosenImageDownloadChoice = CrawlerPreferences.sharedCrawlerPreferences.imageDownloadChoice
let chosenImageDownloadChoice = CrawlerPreferences.shared.imageDownloadChoice
menuItem.state = (chosenImageDownloadChoice == imageDownloadChoice) ? NSControl.StateValue.on : NSControl.StateValue.off
}

Expand All @@ -61,7 +61,7 @@ class CrawlerMenuController: NSObject, NSUserInterfaceValidations {
}

func startObservingCrawlerPreferences() {
crawlerPreferencesObserver = NotificationObserver<CrawlerPreferences.Notification>(object: CrawlerPreferences.sharedCrawlerPreferences)
crawlerPreferencesObserver = NotificationObserver<CrawlerPreferences.Notification>(object: CrawlerPreferences.shared)

crawlerPreferencesObserver.observe(.ImageDownloadChoiceDidChange) { notification in
self.updateImageDownloadMenu()
Expand All @@ -78,7 +78,7 @@ class CrawlerMenuController: NSObject, NSUserInterfaceValidations {
menuItem = sender as? NSMenuItem,
let imageDownloadChoice = imageDownloadMenuItemsAssistant.itemRepresentative(for: menuItem)
{
CrawlerPreferences.sharedCrawlerPreferences.imageDownloadChoice = imageDownloadChoice
CrawlerPreferences.shared.imageDownloadChoice = imageDownloadChoice
}
}

Expand Down
2 changes: 1 addition & 1 deletion Lantern/CrawlerPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ class CrawlerPreferences {
updateFromDefaults()
}

static var sharedCrawlerPreferences = CrawlerPreferences()
static var shared = CrawlerPreferences()
}
4 changes: 2 additions & 2 deletions Lantern/MainState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func ==(lhs: SiteChoice, rhs: SiteChoice) -> Bool {


class MainState {
let crawlerPreferences = CrawlerPreferences.sharedCrawlerPreferences
let browserPreferences = BrowserPreferences.sharedBrowserPreferences
let crawlerPreferences = CrawlerPreferences.shared
let browserPreferences = BrowserPreferences.shared

var siteChoice = SiteChoice.custom {
didSet {
Expand Down
9 changes: 5 additions & 4 deletions Lantern/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,15 @@ class MainWindowToolbarAssistant: NSObject, NSToolbarDelegate {
toggleViewControl.setSelected(shownViews.contains(.meta), forSegment: 1)
}

//var viewportWidthAssistant: SegmentedControlAssistant<BrowserWidthChoice>?
var viewportWidthAssistant: PopUpButtonAssistant<BrowserWidthChoice>?
@IBAction func changeViewportWidth(_ sender: Any?) {
guard let widthChoice = viewportWidthAssistant?.selectedItemRepresentative else { return }
BrowserPreferences.sharedBrowserPreferences.widthChoice = widthChoice
BrowserPreferences.shared.widthChoice = widthChoice
}

var browserPreferencesObserver: NotificationObserver<BrowserPreferences.Notification>!
func startObservingBrowserPreferences() {
let preferences = BrowserPreferences.sharedBrowserPreferences
let preferences = BrowserPreferences.shared
browserPreferencesObserver = NotificationObserver<BrowserPreferences.Notification>(object: preferences)

browserPreferencesObserver.observe(.widthChoiceDidChange) { notification in
Expand Down Expand Up @@ -385,10 +384,12 @@ class MainWindowToolbarAssistant: NSObject, NSToolbarDelegate {
popUpButton.target = self
popUpButton.action = #selector(changeViewportWidth(_:))

let preferences = BrowserPreferences.shared
let assistant = PopUpButtonAssistant<BrowserWidthChoice>(popUpButton: popUpButton)
assistant.menuItemRepresentatives = BrowserWidthChoice.allChoices
//print(assistant.defaultSegmentedItemRepresentatives)
print("WIDTH \(preferences.widthChoice)")
assistant.update()
assistant.selectedUniqueIdentifier = preferences.widthChoice
self.viewportWidthAssistant = assistant
}
else if itemIdentifier == "showToggles" {
Expand Down
2 changes: 1 addition & 1 deletion Lantern/StatsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class StatsViewController: NSViewController {
var rowMenu: NSMenu!
var rowMenuAssistant: MenuAssistant<MenuActions>!

let crawlerPreferences = CrawlerPreferences.sharedCrawlerPreferences
let crawlerPreferences = CrawlerPreferences.shared
var crawlerPreferencesObserver: NotificationObserver<CrawlerPreferences.Notification>!


Expand Down

0 comments on commit 092772b

Please sign in to comment.