Browse Source

notification center

tags/v1.4.0
boB Rudis 3 years ago
parent
commit
d6f24d7611
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 4
      NEWS.md
  2. 4
      RSwitch.xcodeproj/project.pbxproj
  3. 18
      RSwitch.xcworkspace/xcuserdata/hrbrmstr.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
  4. 54
      RSwitch/AppDelegate.swift
  5. 8
      RSwitch/Base.lproj/Main.storyboard

4
NEWS.md

@ -1,3 +1,7 @@
# 1.4.0
- Use Notification Center vs alerts for everything but super-fatal errors
# 1.3.0
- revamped app icon

4
RSwitch.xcodeproj/project.pbxproj

@ -354,7 +354,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.3.0;
MARKETING_VERSION = 1.4.0;
PRODUCT_BUNDLE_IDENTIFIER = is.rud.bob.RSwitch;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -378,7 +378,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.3.0;
MARKETING_VERSION = 1.4.0;
PRODUCT_BUNDLE_IDENTIFIER = is.rud.bob.RSwitch;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";

18
RSwitch.xcworkspace/xcuserdata/hrbrmstr.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@ -3,22 +3,4 @@
uuid = "B14F3897-C728-4EB6-993B-56A42F270486"
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "703EDCF5-C979-44A9-99BC-AE8390E5E25C"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "RSwitch/AppDelegate.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "139"
endingLineNumber = "139"
landmarkName = "download_latest_rstudio(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

54
RSwitch/AppDelegate.swift

@ -16,8 +16,9 @@ public func quitAlert(_ message: String, _ extra: String? = nil) {
NSApp.terminate(nil)
}
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
var mainStoryboard: NSStoryboard!
var abtController: NSWindowController!
@ -27,6 +28,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let macos_cran_url = "https://cran.rstudio.org/bin/macosx/"
let r_sig_mac_url = "https://stat.ethz.ch/pipermail/r-sig-mac/"
let rstudio_dailies_url = "https://dailies.rstudio.com/rstudio/oss/mac/"
let latest_rstudio_dailies_url = "https://www.rstudio.org/download/latest/daily/desktop/mac/RStudio-latest.dmg"
// Get the bar setup
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
@ -45,7 +47,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
mainStoryboard = NSStoryboard(name: "Main", bundle: nil)
abtController = (mainStoryboard.instantiateController(withIdentifier: "aboutPanelController") as! NSWindowController)
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
@ -54,7 +56,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down app
}
func notifyUser(title: String? = nil, subtitle: String? = nil, text: String? = nil) -> Void {
let notification = NSUserNotification()
notification.title = title
notification.subtitle = subtitle
notification.informativeText = text
notification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.delegate = self
NSUserNotificationCenter.default.deliver(notification)
}
func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
return true
}
// The core worker function. Receives the basename of the selected directory
// then removes the current alias and creates the new one.
@objc func handleSwitch(_ sender: NSMenuItem?) {
@ -65,7 +87,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
do {
try fm.removeItem(atPath: macos_r_framework_dir + "/" + "Current")
} catch {
infoAlert("Failed to remove 'Current' alias", macos_r_framework_dir + "/" + "Current")
self.notifyUser(title: "Action failed", text: "Failed to remove 'Current' alias" + macos_r_framework_dir + "/" + "Current")
}
do {
@ -73,8 +95,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
at: NSURL(fileURLWithPath: macos_r_framework_dir + "/" + "Current") as URL,
withDestinationURL: NSURL(fileURLWithPath: macos_r_framework_dir + "/" + title!) as URL
)
self.notifyUser(title: "Success", text: "Current R version switched to " + title!)
} catch {
infoAlert("Failed to create alias for " + macos_r_framework_dir + "/" + title!)
self.notifyUser(title: "Action failed", text: "Failed to create alias for " + macos_r_framework_dir + "/" + title!)
}
}
@ -131,7 +154,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
dlfile.appendPathComponent(dlurl.lastPathComponent)
if (FileManager.default.fileExists(atPath: dlfile.relativePath)) {
infoAlert("A local copy of the latest RStudio daily already exists. Please remove or rename it if you wish to re-download it.")
self.notifyUser(title: "Action required", subtitle: "RStudio Download", text: "A local copy of the latest RStudio daily already exists. Please remove or rename it if you wish to re-download it.")
} else {
let task = URLSession.shared.downloadTask(with: dlurl) { (tempURL, response, error) in
if let tempURL = tempURL, error == nil {
@ -139,21 +162,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
do {
try FileManager.default.copyItem(at: tempURL, to: dlfile)
NSWorkspace.shared.openFile(dldir.path, withApplication: "Finder")
DispatchQueue.main.async { infoAlert("Download of latest RStudio daily (" + dlurl.lastPathComponent + ") successful.") }
self.notifyUser(title: "Success", subtitle: "RStudio Download", text: "Download of latest RStudio daily (" + dlurl.lastPathComponent + ") successful.")
} catch {
DispatchQueue.main.async { infoAlert("Error downloading and saving latest RStudio daily.") }
self.notifyUser(title: "Action failed", subtitle: "RStudio Download", text: "Failed to successfully save latest RStudio daily.")
}
} else {
DispatchQueue.main.async { infoAlert("Latest RStudio daily not found.") }
self.notifyUser(title: "Action failed", subtitle: "RStudio Download", text: "Received unsuccessful status code from RStudio's site.")
}
} else {
DispatchQueue.main.async { infoAlert("Error downloading latest RStudio daily.") }
self.notifyUser(title: "Action failed", subtitle: "RStudio Download", text: "System error when attempting to download file.")
}
}
task.resume()
}
} catch {
DispatchQueue.main.async { infoAlert("Error downloading latrest RStudio daily.") }
self.notifyUser(title: "Action failed", subtitle: "RStudio Download", text: "Error downloading and saving latest RStudio daily.")
}
}
@ -167,9 +190,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
dlfile.appendPathComponent("R-devel-el-capitan-sa-x86_64.tar.gz")
if (FileManager.default.fileExists(atPath: dlfile.relativePath)) {
infoAlert("R-devel tarball already exists. Please remove or rename it before downloading.")
self.notifyUser(title: "Action required", subtitle: "r-devel Download", text: "R-devel tarball already exists. Please remove or rename it before downloading.")
} else {
let task = URLSession.shared.downloadTask(with: url) { (tempURL, response, error) in
if let tempURL = tempURL, error == nil {
@ -177,15 +199,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
do {
try FileManager.default.copyItem(at: tempURL, to: dlfile)
NSWorkspace.shared.openFile(dldir.path, withApplication: "Finder")
DispatchQueue.main.async { infoAlert("Download of latest r-devel successful.") }
self.notifyUser(title: "Success", subtitle: "r-devel Download", text: "Download of latest r-devel successful.")
} catch {
DispatchQueue.main.async { infoAlert("Error downloading and saving latest r-devel .") }
self.notifyUser(title: "Action failed", subtitle: "r-devel Download", text: "Failed to save latest r-devel.")
}
} else {
DispatchQueue.main.async { infoAlert("Latest r-devel file not found.") }
self.notifyUser(title: "Action failed", subtitle: "r-devel Download", text: "Received unsuccessful status code from macOS r-devel site.")
}
} else {
DispatchQueue.main.async { infoAlert("Error downloading latest r-devel .") }
self.notifyUser(title: "Action failed", subtitle: "r-devel Download", text: "Error downloading and saving latest r-devel .")
}
}
task.resume()

8
RSwitch/Base.lproj/Main.storyboard

@ -741,7 +741,7 @@
<attributedString key="textStorage">
<fragment>
<string key="content">
RSwitch v1.3.0
RSwitch v1.4.0
Copyright © 2019 Bob Rudis
@ -750,14 +750,14 @@ MIT Licensed
</string>
<attributes>
<color key="NSColor" name="textColor" catalog="System" colorSpace="catalog"/>
<font key="NSFont" metaFont="system" size="17"/>
<font key="NSFont" metaFont="label" size="17"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
<fragment content="https://git.rud.is/hrbrmstr/RSwitch">
<attributes>
<color key="NSColor" name="textColor" catalog="System" colorSpace="catalog"/>
<font key="NSFont" metaFont="system" size="17"/>
<font key="NSFont" metaFont="label" size="17"/>
<url key="NSLink" string="https://git.rud.is/hrbrmstr/RSwitch"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
@ -769,7 +769,7 @@ dial app icon by IconMark from the Noun Project
</string>
<attributes>
<color key="NSColor" name="textColor" catalog="System" colorSpace="catalog"/>
<font key="NSFont" metaFont="system" size="17"/>
<font key="NSFont" metaFont="label" size="17"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>

Loading…
Cancel
Save