Browse Source

dock icon

tags/v1.5.0
boB Rudis 5 years ago
parent
commit
87e2020606
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 4
      RSwitch.xcodeproj/project.pbxproj
  2. 2
      RSwitch/RSwitch.entitlements
  3. 10
      RSwitch/Swift/AboutViewController.swift
  4. 42
      RSwitch/Swift/AppDelegate.swift
  5. 21
      RSwitch/Swift/Menu.swift
  6. 1
      RSwitch/Swift/Utils/Globals.swift
  7. 79
      RSwitch/Swift/Utils/Preferences.swift
  8. 13
      guide/_site/acknowledgements.html
  9. 1
      guide/_site/index.html
  10. 7
      guide/acknowledgements.Rmd
  11. 1
      guide/index.Rmd

4
RSwitch.xcodeproj/project.pbxproj

@ -16,6 +16,7 @@
01073F1D2311E64E007162C9 /* DownloadRStudio.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01073F1C2311E64E007162C9 /* DownloadRStudio.swift */; };
01073F1F2311E67D007162C9 /* HandleUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01073F1E2311E67D007162C9 /* HandleUpdate.swift */; };
01073F212311E6BD007162C9 /* HandleRSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01073F202311E6BD007162C9 /* HandleRSwitch.swift */; };
011951B4231F00A000B62C3A /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011951B3231F00A000B62C3A /* Preferences.swift */; };
0178970D230ED25100F8F5BC /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0178970C230ED25100F8F5BC /* AboutViewController.swift */; };
018A8C3B2312C7BC0006E87D /* libprocInfo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 018A8C3A2312C7BC0006E87D /* libprocInfo.a */; };
018A8C3F2312CB480006E87D /* procHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 018A8C3E2312CB480006E87D /* procHelper.m */; };
@ -42,6 +43,7 @@
01073F1C2311E64E007162C9 /* DownloadRStudio.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadRStudio.swift; sourceTree = "<group>"; };
01073F1E2311E67D007162C9 /* HandleUpdate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandleUpdate.swift; sourceTree = "<group>"; };
01073F202311E6BD007162C9 /* HandleRSwitch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandleRSwitch.swift; sourceTree = "<group>"; };
011951B3231F00A000B62C3A /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
016750FB2319A7A4009E2FD6 /* RSwitch.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = RSwitch.entitlements; sourceTree = "<group>"; };
0178970C230ED25100F8F5BC /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; };
018A8C392312C7BC0006E87D /* procInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = procInfo.h; sourceTree = "<group>"; };
@ -160,6 +162,7 @@
0198B9A723197CBA003F7578 /* Launch.swift */,
01975549231BD919003FAD7B /* RVersions.swift */,
0198B9A923197D3A003F7578 /* Running.swift */,
011951B3231F00A000B62C3A /* Preferences.swift */,
);
path = Utils;
sourceTree = "<group>";
@ -329,6 +332,7 @@
files = (
01073F212311E6BD007162C9 /* HandleRSwitch.swift in Sources */,
0198B9A0231970ED003F7578 /* AppAlerts.swift in Sources */,
011951B4231F00A000B62C3A /* Preferences.swift in Sources */,
018A8C3F2312CB480006E87D /* procHelper.m in Sources */,
01073F1F2311E67D007162C9 /* HandleUpdate.swift in Sources */,
01073F1B2311E613007162C9 /* DownloadTarball.swift in Sources */,

2
RSwitch/RSwitch.entitlements

@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.automation.apple-events</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>

10
RSwitch/Swift/AboutViewController.swift

@ -1,3 +1,10 @@
//
// AboutViewController.swift
// RSwitch
//
// Created by hrbrmstr on 8/24/19.
// Copyright © 2019 Bob Rudis. All rights reserved.
//
import Cocoa
@ -6,6 +13,9 @@ extension AppDelegate {
// Show about dialog
@objc func about(_ sender: NSMenuItem?) { abtController.showWindow(self) }
@objc
func updateTimer(_ sender: Timer) { print("timer fired") }
}
class AboutViewController: NSViewController {

42
RSwitch/Swift/AppDelegate.swift

@ -1,3 +1,11 @@
//
// AppDelegate.swift
// RSwitch
//
// Created by hrbrmstr on 8/24/19.
// Copyright © 2019 Bob Rudis. All rights reserved.
//
import Cocoa
@NSApplicationMain
@ -11,6 +19,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var rdevel_enabled: Bool!
var rstudio_enabled: Bool!
var timer: Timer? = nil;
override init() {
@ -18,6 +27,26 @@ class AppDelegate: NSObject, NSApplicationDelegate {
statusMenu.delegate = self
rdevel_enabled = true
rstudio_enabled = true
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)
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
// dial by IconMark from the Noun Project
statusItem.button?.image = #imageLiteral(resourceName: "RSwitch")
statusItem.menu = statusMenu
@ -25,14 +54,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
mainStoryboard = NSStoryboard(name: "Main", bundle: nil)
abtController = (mainStoryboard.instantiateController(withIdentifier: "aboutPanelController") as! NSWindowController)
rdevel_enabled = true
rstudio_enabled = true
timer = Timer.scheduledTimer(
timeInterval: 3600,
target: self,
selector: #selector(updateTimer),
userInfo: nil,
repeats: true
)
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
}
func applicationDidFinishLaunching(_ aNotification: Notification) { }
func applicationWillTerminate(_ aNotification: Notification) { }

21
RSwitch/Swift/Menu.swift

@ -10,6 +10,19 @@ import Foundation
import Cocoa
extension AppDelegate: NSMenuDelegate {
@objc
func toggle_dock_icon(_ sender: NSMenuItem) {
Preferences.showDockIcon = !Preferences.showDockIcon
DockIcon.standard.setVisibility(Preferences.showDockIcon)
if let menu = statusItem.menu, let item = menu.item(withTag: 99) {
item.state = Preferences.showDockIcon.stateValue
}
}
func menuWillOpen(_ menu: NSMenu) {
@ -65,6 +78,14 @@ extension AppDelegate: NSMenuDelegate {
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "About RSwitch…", action: #selector(about), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "RSwitch Help…", action: #selector(rswitch_help), keyEquivalent: ""))
// Toggle Dock Icon
menu.addItem(NSMenuItem.separator())
let item = NSMenuItem(title: "Toggle Dock Icon", action: #selector(toggle_dock_icon), keyEquivalent: "")
item.tag = 99
item.target = self
item.state = Preferences.showDockIcon.stateValue
menu.addItem(item)
// Add a Quit item
menu.addItem(NSMenuItem.separator())

1
RSwitch/Swift/Utils/Globals.swift

@ -9,7 +9,6 @@
import Foundation
import Cocoa
extension AppDelegate {
struct app_urls {

79
RSwitch/Swift/Utils/Preferences.swift

@ -0,0 +1,79 @@
//
// Preferences.swift
// RSwitch
//
// Created by hrbrmstr on 9/3/19.
// Copyright © 2019 Bob Rudis. All rights reserved.
//
import Foundation
import AppKit
fileprivate let defaults: UserDefaults = UserDefaults.standard
extension Bool {
var stateValue: NSControl.StateValue { return self.toStateValue() }
private func toStateValue() -> NSControl.StateValue { return(self ? .on : .off) }
}
extension UserDefaults {
enum Key: String {
case showDockIcon = "showDockIcon"
case firstRunGone = "firstRunGone"
}
func set<T>(_ value: T, forKey key: Key) { set(value, forKey: key.rawValue) }
func bool(forKey key: Key) -> Bool { return(bool(forKey: key.rawValue)) }
func string(forKey key: Key) -> String? { return(string(forKey: key.rawValue)) }
func integer(forKey key: Key) -> Int? { return(integer(forKey: key.rawValue)) }
func url(forKey key: Key) -> URL? { return(url(forKey: key.rawValue)) }
}
struct DockIcon {
static var standard = DockIcon()
var isVisible: Bool {
get { return(NSApp.activationPolicy() == .regular) }
set { setVisibility(newValue) }
}
@discardableResult
func setVisibility(_ state: Bool) -> Bool {
NSApp.setActivationPolicy(state ? .regular : .accessory)
return(isVisible)
}
}
struct Preferences {
static var showDockIcon: Bool {
get { return(defaults.bool(forKey: .showDockIcon)) }
set {
defaults.set(newValue, forKey: .showDockIcon)
defaults.synchronize()
}
}
static var firstRunGone: Bool {
get { return(defaults.bool(forKey: .firstRunGone)) }
set {
defaults.set(newValue, forKey: .firstRunGone)
defaults.synchronize()
}
}
static func restore() { Preferences.showDockIcon = false }
}

13
guide/_site/acknowledgements.html

@ -300,6 +300,11 @@ $(document).ready(function () {
</div>
<div id="TOC">
<ul>
<li><a href="#extra-credits">Extra Credits</a></li>
</ul>
</div>
<p>RSwitch wasn’t my idea. It’s been around forever on the <a href="http://mac.r-project.org/">R for macOS Developer’s Page</a> but stopped working on Catalina since it hadn’t been updated in ages, was only 32-bit (which is a no-go for Catalina), and had no available source code to modify.</p>
<p>Despite having found and old-old copy of the source code by hacking URLs via the Internet Archive, none of that code was used to make this incarnation of RSwitch.</p>
@ -310,6 +315,14 @@ $(document).ready(function () {
<li><a href="https://github.com/DragonCherry/VersionCompare/">VersionCompare</a> by DragonCherry</li>
</ul>
<p>The current (but, likely not final) app icon and menubar icon is based on the <a href="https://thenounproject.com/search/?q=dial&amp;i=866019#">‘dial’ Noun Project font icon</a> created by Icon Mark.</p>
<div id="extra-credits" class="section level2">
<h2>Extra Credits</h2>
<p>Many thanks to the following folks for their contributions to the project to help make RSwitch better for everyone:</p>
<ul>
<li><a href="https://github.com/guiastrennec">Benjamin Guiastrennec</a> for suggesting improvements to the documentation regarding how to use the installer packages from the <a href="https://mac.r-project.org/">R for macOS Developer’s Page</a> without clobbering existing R Framework installs.</li>
<li><a href="https://github.com/xvrdm">Xavier Adam</a> for <a href="https://github.com/hrbrmstr/RSwitch/pull/4">adding books to the RSwitch library</a>.</li>
</ul>
</div>
<hr noshade size=1/>
<p>Copyright &copy; 2019 Bob Rudis. All rights reserved.</p>

1
guide/_site/index.html

@ -377,6 +377,7 @@ div.tocify {
<p>Many thanks to the following folks for their contributions to the project to help make RSwitch better for everyone:</p>
<ul>
<li><a href="https://github.com/guiastrennec">Benjamin Guiastrennec</a> for suggesting improvements to the documentation regarding how to use the installer packages from the <a href="https://mac.r-project.org/">R for macOS Developer’s Page</a> without clobbering existing R Framework installs.</li>
<li><a href="https://github.com/xvrdm">Xavier Adam</a> for <a href="https://github.com/hrbrmstr/RSwitch/pull/4">adding books to the RSwitch library</a>.</li>
</ul>
</div>
<div id="basiccore-usage" class="section level2">

7
guide/acknowledgements.Rmd

@ -13,3 +13,10 @@ RSwitch uses three external frameworks to accomplish its tasks:
- [VersionCompare](https://github.com/DragonCherry/VersionCompare/) by DragonCherry
The current (but, likely not final) app icon and menubar icon is based on the ['dial' Noun Project font icon](https://thenounproject.com/search/?q=dial&i=866019#) created by Icon Mark.
## Extra Credits
Many thanks to the following folks for their contributions to the project to help make RSwitch better for everyone:
- [Benjamin Guiastrennec](https://github.com/guiastrennec) for suggesting improvements to the documentation regarding how to use the installer packages from the [R for macOS Developer's Page](https://mac.r-project.org/) without clobbering existing R Framework installs.
- [Xavier Adam](https://github.com/xvrdm) for [adding books to the RSwitch library](https://github.com/hrbrmstr/RSwitch/pull/4).

1
guide/index.Rmd

@ -18,6 +18,7 @@ RSwitch is a macOS menubar application that works on macOS 10.14+ and provides h
Many thanks to the following folks for their contributions to the project to help make RSwitch better for everyone:
- [Benjamin Guiastrennec](https://github.com/guiastrennec) for suggesting improvements to the documentation regarding how to use the installer packages from the [R for macOS Developer's Page](https://mac.r-project.org/) without clobbering existing R Framework installs.
- [Xavier Adam](https://github.com/xvrdm) for [adding books to the RSwitch library](https://github.com/hrbrmstr/RSwitch/pull/4).
## Basic/Core Usage

Loading…
Cancel
Save