A small menubar app that allows you to switch between R versions quickly (if you have multiple versions of R framework installed). https://rud.is/rswitch
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.0 KiB

5 years ago
//
// AppDelegate.swift
// RSwitch
//
// Created by hrbrmstr on 8/24/19.
// Copyright © 2019 Bob Rudis. All rights reserved.
//
5 years ago
import Cocoa
5 years ago
import Just
5 years ago
class DeleteSessionViewController : NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
5 years ago
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, NSToolbarDelegate {
@objc func showAbout(_ sender: NSMenuItem?) {
abtController.showWindow(self)
abtController.window?.orderFront(self)
NSApp.activate(ignoringOtherApps: true)
}
5 years ago
5 years ago
@objc func performRStudioCheck(_ sender: NSObject) {
4 years ago
if (currentReachabilityStatus != .notReachable) {
let v = RStudioUtils.latestVersionNumber()
if (!Preferences.lastVersionNotified.isVersion(equalTo: v)) {
Preferences.lastVersionNotified = v
notifyUserWithDL(title: "New RStudio Daily version available", text: ("Version: " + v))
}
5 years ago
}
}
5 years ago
@objc func performTimer(_ sender: Timer) {
5 years ago
if (Preferences.hourlyRStudioCheck) { performRStudioCheck(sender) }
4 years ago
if (Preferences.ensureFileHandlers) { FileAssociationUtils.setHandlers() }
5 years ago
}
5 years ago
5 years ago
var mainStoryboard: NSStoryboard!
var abtController: NSWindowController!
var rsController: NSWindowController!
var newSessController: NSWindowController!
5 years ago
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
5 years ago
let statusMenu = NSMenu(title: "RSwitch")
5 years ago
var rdevel_enabled: Bool!
var rstudio_enabled: Bool!
5 years ago
var timer: Timer? = nil;
var sess : RStudioServerSessionManager!
5 years ago
override init() {
super.init()
statusMenu.delegate = self
5 years ago
rdevel_enabled = true
rstudio_enabled = true
5 years ago
5 years ago
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
}
func applicationWillFinishLaunching(_ aNotification: Notification) {
if Preferences.firstRunGone == false {
Preferences.firstRunGone = true
Preferences.restore()
}
DockIcon.standard.setVisibility(Preferences.showDockIcon)
4 years ago
5 years ago
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
5 years ago
5 years ago
// dial by IconMark from the Noun Project
statusItem.button?.image = #imageLiteral(resourceName: "RSwitch")
statusItem.menu = statusMenu
mainStoryboard = NSStoryboard(name: "Main", bundle: nil)
5 years ago
abtController = (mainStoryboard.instantiateController(withIdentifier: "aboutPanelController") as! NSWindowController)
newSessController = (mainStoryboard.instantiateController(withIdentifier: "newSessPanel") as! NSWindowController)
5 years ago
sess = RStudioServerSessionManager()
4 years ago
4 years ago
if (Preferences.ensureFileHandlers) { FileAssociationUtils.setHandlers() }
4 years ago
5 years ago
timer = Timer.scheduledTimer(
timeInterval: 3600,
target: self,
5 years ago
selector: #selector(performTimer),
5 years ago
userInfo: nil,
repeats: true
)
5 years ago
}
5 years ago
func applicationWillTerminate(_ aNotification: Notification) {
sess.saveSessions()
5 years ago
}
5 years ago
}