Skip to content

Commit

Permalink
Merge pull request #3 from marcingajda/rewrite
Browse files Browse the repository at this point in the history
Configuration window, total app rewrite
  • Loading branch information
marcingajda authored Apr 18, 2020
2 parents c1570ad + 1d2c92a commit bc1ee77
Show file tree
Hide file tree
Showing 28 changed files with 1,299 additions and 417 deletions.
104 changes: 76 additions & 28 deletions Covid-19 Status.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

231 changes: 194 additions & 37 deletions Covid-19 Status/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

65 changes: 6 additions & 59 deletions Covid-19 Status/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,60 +1,7 @@
/*
Localizable.strings"
Covid-19 Status"

/* Class = "NSMenuItem"; title = "Covid-19 Status"; ObjectID = "1Xt-HY-uBw"; */
"1Xt-HY-uBw.title" = "Covid-19 Status";

/* Class = "NSMenuItem"; title = "Quit"; ObjectID = "4sb-4s-VLi"; */
"4sb-4s-VLi.title" = "Zamknij";

/* Class = "NSMenuItem"; title = "Loading"; ObjectID = "5kV-Vb-QxS"; */
"5kV-Vb-QxS.title" = "Ładowanie";

/* Class = "NSMenuItem"; title = "Retry now"; ObjectID = "6jx-Ii-JOn"; */
"6jx-Ii-JOn.title" = "Spróbuj ponownie";

/* Class = "NSMenuItem"; title = "About..."; ObjectID = "8AQ-8p-cQP"; */
"8AQ-8p-cQP.title" = "O aplikacji...";

/* Class = "NSMenu"; title = "Main Menu"; ObjectID = "AYu-sK-qS6"; */
"AYu-sK-qS6.title" = "Menu główne";

/* Class = "NSButtonCell"; title = "Close"; ObjectID = "E40-p5-Mjh"; */
"E40-p5-Mjh.title" = "Zamknij";

/* Class = "NSWindow"; title = "About"; ObjectID = "EIX-4g-u9N"; */
"EIX-4g-u9N.title" = "O programie";

/* Class = "NSMenuItem"; title = "Select region"; ObjectID = "MAg-rl-DVH"; */
"MAg-rl-DVH.title" = "Wybierz region";

/* Class = "NSTextFieldCell"; title = "version: 1.0.0"; ObjectID = "OSg-Ed-kOh"; */
"OSg-Ed-kOh.title" = "wersja: 1.0.0";

/* Class = "NSMenu"; title = "Select region"; ObjectID = "URq-Fm-ggV"; */
"URq-Fm-ggV.title" = "Wybierz region";

/* Class = "NSTextFieldCell"; title = "COVID-19 Status"; ObjectID = "YJw-ga-rD7"; */
"YJw-ga-rD7.title" = "COVID-19 Status";

/* Class = "NSBox"; title = "Box"; ObjectID = "dPt-xi-xGS"; */
"dPt-xi-xGS.title" = "Box";

/* Class = "NSTextFieldCell"; title = "https://iconmonstr.com/virus-2-svg/"; ObjectID = "er1-QF-EuT"; */
"er1-QF-EuT.title" = "https://iconmonstr.com/virus-2-svg/";

/* Class = "NSMenuItem"; title = "Brak"; ObjectID = "i8c-sB-7Tp"; */
"i8c-sB-7Tp.title" = "Brak";

/* Class = "NSTextFieldCell"; title = "https://corona-stats.online/?source=2"; ObjectID = "lhY-fZ-nQY"; */
"lhY-fZ-nQY.title" = "https://corona-stats.online/?source=2";

/* Class = "NSMenuItem"; title = "Show notifications"; ObjectID = "ljG-1J-Upa"; */
"ljG-1J-Upa.title" = "Pokazuj powiadomienia";

/* Class = "NSTextFieldCell"; title = "Data source"; ObjectID = "spg-XS-UDd"; */
"spg-XS-UDd.title" = "Źródło danych";

/* Class = "NSMenu"; title = "Covid-19 Status"; ObjectID = "uQy-DD-JDr"; */
"uQy-DD-JDr.title" = "Covid-19 Status";

/* Class = "NSTextFieldCell"; title = "Logo icon"; ObjectID = "uop-yu-b1c"; */
"uop-yu-b1c.title" = "Ikona logo";
Created by Marcin Gajda on 25/03/2020."
Copyright © 2020 Marcin Gajda. All rights reserved."
*/
14 changes: 14 additions & 0 deletions Covid-19 Status/pl.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
"COVID-19 Status: Error" = "COVID-19 Status: Błąd";
"unknown cause" = "powód nieznany";
"An error occured" = "Wystąpił błąd";
"(empty)" = "(puste)";

"None" = "Brak";
"3 entries" = "3 wpisy";
"5 entries" = "5 wpisów";
"10 entries" = "10 wpisów";
"20 entries" = "20 wpisów";
"30 entries" = "30 wpisów";

"1 minute" = "1 minuta";
"3 minute" = "3 minuty";
"10 minute" = "10 minut";
"30 minute" = "30 minut";
"60 minute" = "60 minut";

"World" = "Świat";
"Afghanistan" = "Afganistan";
Expand Down
47 changes: 38 additions & 9 deletions Covid-19 Status/pl.lproj/Main.strings
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@

/* Class = "NSMenuItem"; title = "Covid-19 Status"; ObjectID = "1Xt-HY-uBw"; */
"1Xt-HY-uBw.title" = "Covid-19 Status";

/* Class = "NSTextFieldCell"; title = "Regions history size:"; ObjectID = "4Z9-8E-CNG"; */
"4Z9-8E-CNG.title" = "Wielkość historii regionów:";

/* Class = "NSMenuItem"; title = "Quit"; ObjectID = "4sb-4s-VLi"; */
"4sb-4s-VLi.title" = "Zamknij";

/* Class = "NSTextFieldCell"; title = "Refresh interval:"; ObjectID = "51x-8i-TTI"; */
"51x-8i-TTI.title" = "Częstotliwość odświeżania:";

/* Class = "NSMenuItem"; title = "Loading"; ObjectID = "5kV-Vb-QxS"; */
"5kV-Vb-QxS.title" = "Ładowanie";

/* Class = "NSMenuItem"; title = "Retry now"; ObjectID = "6jx-Ii-JOn"; */
"6jx-Ii-JOn.title" = "Spróbuj ponownie";
"6jx-Ii-JOn.title" = "Ponów teraz";

/* Class = "NSMenuItem"; title = "About..."; ObjectID = "8AQ-8p-cQP"; */
"8AQ-8p-cQP.title" = "O programie...";
"8AQ-8p-cQP.title" = "O aplikacji...";

/* Class = "NSMenu"; title = "Main Menu"; ObjectID = "AYu-sK-qS6"; */
"AYu-sK-qS6.title" = "Menu główne";
"AYu-sK-qS6.title" = "Główne menu";

/* Class = "NSButtonCell"; title = "Close"; ObjectID = "CeK-V0-XNw"; */
"CeK-V0-XNw.title" = "Zamknij";

/* Class = "NSButtonCell"; title = "Close"; ObjectID = "E40-p5-Mjh"; */
"E40-p5-Mjh.title" = "Zamknij";

/* Class = "NSWindow"; title = "About"; ObjectID = "EIX-4g-u9N"; */
"EIX-4g-u9N.title" = "O programie";
"EIX-4g-u9N.title" = "O aplikacji";

/* Class = "NSMenuItem"; title = "Last regions"; ObjectID = "LV7-r5-pVW"; */
"LV7-r5-pVW.title" = "Ostatnie regiony";

/* Class = "NSMenuItem"; title = "Select region"; ObjectID = "MAg-rl-DVH"; */
"MAg-rl-DVH.title" = "Wybierz region";

/* Class = "NSTextFieldCell"; title = "version: 1.0.0"; ObjectID = "OSg-Ed-kOh"; */
"OSg-Ed-kOh.title" = "version: 1.0.0";
"OSg-Ed-kOh.title" = "wersja: 1.0.0";

/* Class = "NSMenu"; title = "Select region"; ObjectID = "URq-Fm-ggV"; */
"URq-Fm-ggV.title" = "Wybierz region";
Expand All @@ -38,23 +49,41 @@
/* Class = "NSTextFieldCell"; title = "COVID-19 Status"; ObjectID = "YJw-ga-rD7"; */
"YJw-ga-rD7.title" = "COVID-19 Status";

/* Class = "NSMenu"; title = "Last regions"; ObjectID = "ZRd-S3-NG4"; */
"ZRd-S3-NG4.title" = "Ostatnie regiony";

/* Class = "NSBox"; title = "Box"; ObjectID = "dPt-xi-xGS"; */
"dPt-xi-xGS.title" = "Box";

/* Class = "NSWindow"; title = "Preferences"; ObjectID = "fUu-Lr-91U"; */
"fUu-Lr-91U.title" = "Preferencje";

/* Class = "NSMenuItem"; title = "None"; ObjectID = "i8c-sB-7Tp"; */
"i8c-sB-7Tp.title" = "Brak";
"i8c-sB-7Tp.title" = "None";

/* Class = "NSTextFieldCell"; title = "https://corona-stats.online/?source=2"; ObjectID = "lhY-fZ-nQY"; */
"lhY-fZ-nQY.title" = "https://corona-stats.online/?source=2";

/* Class = "NSMenuItem"; title = "Show notifications"; ObjectID = "ljG-1J-Upa"; */
"ljG-1J-Upa.title" = "Pokaż powiadomienia";

/* Class = "NSMenuItem"; title = "Preferences..."; ObjectID = "nsq-oj-T39"; */
"nsq-oj-T39.title" = "Preferencje...";

/* Class = "NSTextFieldCell"; title = "COVID-19 Status Preferences"; ObjectID = "plv-g9-ghO"; */
"plv-g9-ghO.title" = "Preferencje COVID-19 Status";

/* Class = "NSTextFieldCell"; title = "Data source"; ObjectID = "spg-XS-UDd"; */
"spg-XS-UDd.title" = "Źródło danych";

/* Class = "NSMenu"; title = "Covid-19 Status"; ObjectID = "uQy-DD-JDr"; */
"uQy-DD-JDr.title" = "Covid-19 Status";

/* Class = "NSTextFieldCell"; title = "Daily data resets at midnight GMT+0"; ObjectID = "uop-yu-b1c"; */
"uop-yu-b1c.title" = "Dane dzienne resetują się o północy GMT+0";
/* Class = "NSTextFieldCell"; title = "Data of daily change in given region \nresets everyday at midnight GMT+0"; ObjectID = "uop-yu-b1c"; */
"uop-yu-b1c.title" = "Dane o dziennej zmianie w danym regionie\nresetują się o północy czasu GMT+0";

/* Class = "NSBox"; title = "Box"; ObjectID = "xdV-7Q-XdL"; */
"xdV-7Q-XdL.title" = "Box";

/* Class = "NSMenuItem"; title = "None"; ObjectID = "xrM-70-jyW"; */
"xrM-70-jyW.title" = "Brak";
109 changes: 12 additions & 97 deletions Covid-19 Status/src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,118 +13,33 @@ import LetsMove
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
let settings = UserDefaults.standard
var alertsEnabled: Bool = false

var aboutWindowController: NSWindowController?
var display: StatsDisplay = StatsDisplay()
var notificator: Notificator = Notificator()
var provider: DataProvider?
var appController: AppController?

@IBOutlet weak var menu: NSMenu?
var statusBarItem: NSStatusItem?
@IBOutlet weak var retryMenuItem: NSMenuItem?
@IBOutlet weak var deltaMenuItem: NSMenuItem?
@IBOutlet weak var regionsMenu: RegionsMenu?
@IBOutlet weak var alertsMenuItem: NSMenuItem?

var currentRegion: String = SpecialRegions.world.rawValue

func setAlertsEnabled(enabled: Bool) {
alertsEnabled = enabled
notificator.isEnabled = enabled
alertsMenuItem?.state = enabled ? .on : .off
settings.set(enabled, forKey: SettingsKey.alertsEnabled.rawValue)
}

@IBAction func alertsSwitchHandler(_ sender: NSMenuItem) {
setAlertsEnabled(enabled: !alertsEnabled)
}

func onRegionChange (region: String) {
self.currentRegion = region

guard let stats = provider?.getStatsFor(region: currentRegion) else {
return
}

self.display.showStats(region: stats)
}

func onUpdateSuccess (stats: CoronaStats) {
guard let currentStats = provider?.getStatsFor(region: currentRegion) else {
print("No stats data is available")
return
}

regionsMenu?.updateList(regionsStats: stats.data)
retryMenuItem?.isHidden = true
display.showStats(region: currentStats)
notificator.handle(stats: currentStats)
}

func onUpdateFailure (error: String?) {
display.showError(message: error)
retryMenuItem?.isHidden = false
}

@IBAction func retryHandler(_ sender: AnyObject) {
display.showLoading()
provider?.doUpdate()
}

@IBAction func showAboutWindow(_ sender: AnyObject) {
let storyboard = NSStoryboard(name: "Main", bundle: nil)

if let aboutWindowController = aboutWindowController {
aboutWindowController.close()
}

aboutWindowController = storyboard.instantiateController(
withIdentifier: "About Window Controller"
) as? NSWindowController

guard let aboutWindowController = aboutWindowController else {
criticalError(message: "The About window failed", terminate: false)
return
}

aboutWindowController.showWindow(self)
}
@IBOutlet weak var mainMenu: MainMenu?

func applicationDidFinishLaunching(_ aNotification: Notification) {
PFMoveToApplicationsFolderIfNecessary()

statusBarItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)

guard let menu = menu else {
criticalError(message: "The app UI is broken (menu)")
return
}
guard let regionsMenu = regionsMenu else {
criticalError(message: "The app UI is broken (regions menu)")
guard let statusBarItem = statusBarItem else {
ErrorHandler.standard.critical(withMessage: "The app UI is broken (status bar item)")
return
}
guard let deltaMenuItem = deltaMenuItem else {
criticalError(message: "The app UI is broken (delta menu item)")

guard let menu = mainMenu else {
ErrorHandler.standard.critical(withMessage: "The app UI is broken (menu)")
return
}
guard let button = statusBarItem?.button else {
criticalError(message: "Menu bar item was not created. Try removing some menu bar items")

guard let button = statusBarItem.button else {
ErrorHandler.standard.critical(withMessage: "Menu bar item was not created. Not enough space?")
return
}

statusBarItem?.menu = menu
display.setComponents(statusItem: button, deltaItem: deltaMenuItem)

setAlertsEnabled(enabled: settings.bool(forKey: SettingsKey.alertsEnabled.rawValue))

regionsMenu.onRegionChange(callback: onRegionChange)
provider = DataProvider(onSuccess: onUpdateSuccess, onError: onUpdateFailure)

let prefferedRegion = settings.string(forKey: SettingsKey.selectedRegion.rawValue)
regionsMenu.setCurrent(region: prefferedRegion ?? SpecialRegions.world.rawValue)

provider?.doUpdate()
provider?.startTimer()
statusBarItem.menu = menu
appController = AppController(statusButton: button, statusMenu: menu)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class AboutViewController: NSViewController {
super.viewDidLoad()

guard let version = version else {
criticalError(message: "The app UI is broken (version)")
ErrorHandler.standard.critical(withMessage: "The app UI is broken (version)")
return
}

guard let sourceLink = sourceLink else {
criticalError(message: "The app UI is broken (source link)")
ErrorHandler.standard.critical(withMessage: "The app UI is broken (source link)")
return
}

Expand All @@ -45,12 +45,12 @@ class AboutViewController: NSViewController {

@IBAction func sourceLinkHandler(sender: NSClickGestureRecognizer) {
guard let link = sourceLink?.stringValue else {
criticalError(message: "Can't open the URL address.")
ErrorHandler.standard.critical(withMessage: "Can't open the URL address.")
return
}

guard let urlAddress = URL(string: link) else {
criticalError(message: "Can't open the URL address.")
ErrorHandler.standard.critical(withMessage: "Can't open the URL address.")
return
}

Expand Down
Loading

0 comments on commit bc1ee77

Please sign in to comment.