Browse Source

RStudio Server Sessions

tags/v1.5.0
boB Rudis 1 year ago
parent
commit
5279fcce54
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
8 changed files with 250 additions and 6 deletions
  1. +26
    -2
      RSwitch.xcodeproj/project.pbxproj
  2. +47
    -0
      RSwitch/Base.lproj/Main.storyboard
  3. +16
    -3
      RSwitch/Swift/AppDelegate.swift
  4. +3
    -1
      RSwitch/Swift/Menu.swift
  5. +57
    -0
      RSwitch/Swift/MenuActions/RStudioServerAction.swift
  6. +43
    -0
      RSwitch/Swift/Sessions/RStudioServerSession.swift
  7. +29
    -0
      RSwitch/Swift/Sessions/RStudioServerSessionManager.swift
  8. +29
    -0
      RSwitch/Swift/WebViewController.swift

+ 26
- 2
RSwitch.xcodeproj/project.pbxproj View File

@ -25,6 +25,10 @@
0198B99E23196689003F7578 /* BrowseMenuAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198B99D23196689003F7578 /* BrowseMenuAction.swift */; };
0198B9A0231970ED003F7578 /* AppAlerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198B99F231970ED003F7578 /* AppAlerts.swift */; };
0198B9AA23197D3A003F7578 /* Running.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198B9A923197D3A003F7578 /* Running.swift */; };
01D3E43A232119DD00E3BC02 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01D3E439232119DD00E3BC02 /* WebViewController.swift */; };
01D3E43C23211B4C00E3BC02 /* RStudioServerAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01D3E43B23211B4C00E3BC02 /* RStudioServerAction.swift */; };
01D3E43F2321315900E3BC02 /* RStudioServerSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01D3E43E2321315900E3BC02 /* RStudioServerSession.swift */; };
01D3E441232131F300E3BC02 /* RStudioServerSessionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01D3E440232131F300E3BC02 /* RStudioServerSessionManager.swift */; };
01F3EF0C230E635300DF5DF9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F3EF0B230E635300DF5DF9 /* AppDelegate.swift */; };
01F3EF0E230E635300DF5DF9 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F3EF0D230E635300DF5DF9 /* ViewController.swift */; };
01F3EF10230E635500DF5DF9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 01F3EF0F230E635500DF5DF9 /* Assets.xcassets */; };
@ -56,6 +60,10 @@
0198B99D23196689003F7578 /* BrowseMenuAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseMenuAction.swift; sourceTree = "<group>"; };
0198B99F231970ED003F7578 /* AppAlerts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppAlerts.swift; sourceTree = "<group>"; };
0198B9A923197D3A003F7578 /* Running.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Running.swift; sourceTree = "<group>"; };
01D3E439232119DD00E3BC02 /* WebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = "<group>"; };
01D3E43B23211B4C00E3BC02 /* RStudioServerAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RStudioServerAction.swift; sourceTree = "<group>"; };
01D3E43E2321315900E3BC02 /* RStudioServerSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RStudioServerSession.swift; sourceTree = "<group>"; };
01D3E440232131F300E3BC02 /* RStudioServerSessionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RStudioServerSessionManager.swift; sourceTree = "<group>"; };
01F3EF08230E635300DF5DF9 /* RSwitch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RSwitch.app; sourceTree = BUILT_PRODUCTS_DIR; };
01F3EF0B230E635300DF5DF9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
01F3EF0D230E635300DF5DF9 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@ -84,19 +92,21 @@
01073F232311E859007162C9 /* Swift */ = {
isa = PBXGroup;
children = (
01F3EF0B230E635300DF5DF9 /* AppDelegate.swift */,
01D3E43D2321314100E3BC02 /* Sessions */,
0198B9A1231970F5003F7578 /* AppAlerts */,
0198B9A323197301003F7578 /* Downloaders */,
0198B99C23196666003F7578 /* MenuActions */,
0198B9A2231971D1003F7578 /* String+Version */,
0198B9A623197C8E003F7578 /* Utils */,
0178970C230ED25100F8F5BC /* AboutViewController.swift */,
01F3EF0B230E635300DF5DF9 /* AppDelegate.swift */,
01073F202311E6BD007162C9 /* HandleRSwitch.swift */,
01073F1E2311E67D007162C9 /* HandleUpdate.swift */,
018A8C402312F4940006E87D /* HandleSwitchTo.swift */,
01073F162311E397007162C9 /* Menu.swift */,
01073F142311E370007162C9 /* Notify.swift */,
01F3EF0D230E635300DF5DF9 /* ViewController.swift */,
01D3E439232119DD00E3BC02 /* WebViewController.swift */,
);
path = Swift;
sourceTree = "<group>";
@ -126,6 +136,7 @@
children = (
C4290DD5231F190E00AA5955 /* AppMenuActions.swift */,
0198B99D23196689003F7578 /* BrowseMenuAction.swift */,
01D3E43B23211B4C00E3BC02 /* RStudioServerAction.swift */,
);
path = MenuActions;
sourceTree = "<group>";
@ -167,6 +178,15 @@
path = Utils;
sourceTree = "<group>";
};
01D3E43D2321314100E3BC02 /* Sessions */ = {
isa = PBXGroup;
children = (
01D3E43E2321315900E3BC02 /* RStudioServerSession.swift */,
01D3E440232131F300E3BC02 /* RStudioServerSessionManager.swift */,
);
path = Sessions;
sourceTree = "<group>";
};
01F3EEFF230E635300DF5DF9 = {
isa = PBXGroup;
children = (
@ -188,11 +208,11 @@
01F3EF0A230E635300DF5DF9 /* RSwitch */ = {
isa = PBXGroup;
children = (
01F3EF11230E635500DF5DF9 /* Main.storyboard */,
016750FB2319A7A4009E2FD6 /* RSwitch.entitlements */,
018A8C342312C6510006E87D /* ObjC */,
01073F232311E859007162C9 /* Swift */,
01F3EF0F230E635500DF5DF9 /* Assets.xcassets */,
01F3EF11230E635500DF5DF9 /* Main.storyboard */,
01F3EF14230E635500DF5DF9 /* Info.plist */,
);
path = RSwitch;
@ -333,12 +353,15 @@
01073F212311E6BD007162C9 /* HandleRSwitch.swift in Sources */,
0198B9A0231970ED003F7578 /* AppAlerts.swift in Sources */,
011951B4231F00A000B62C3A /* Preferences.swift in Sources */,
01D3E43C23211B4C00E3BC02 /* RStudioServerAction.swift in Sources */,
018A8C3F2312CB480006E87D /* procHelper.m in Sources */,
01D3E43A232119DD00E3BC02 /* WebViewController.swift in Sources */,
01073F1F2311E67D007162C9 /* HandleUpdate.swift in Sources */,
01073F1B2311E613007162C9 /* DownloadTarball.swift in Sources */,
018A8C412312F4940006E87D /* HandleSwitchTo.swift in Sources */,
0198B9AA23197D3A003F7578 /* Running.swift in Sources */,
0178970D230ED25100F8F5BC /* AboutViewController.swift in Sources */,
01D3E43F2321315900E3BC02 /* RStudioServerSession.swift in Sources */,
01073F192311E3B8007162C9 /* Bundle.swift in Sources */,
0197554A231BD919003FAD7B /* RVersions.swift in Sources */,
01073F152311E370007162C9 /* Notify.swift in Sources */,
@ -347,6 +370,7 @@
01073F172311E397007162C9 /* Menu.swift in Sources */,
01F3EF0E230E635300DF5DF9 /* ViewController.swift in Sources */,
01F3EF0C230E635300DF5DF9 /* AppDelegate.swift in Sources */,
01D3E441232131F300E3BC02 /* RStudioServerSessionManager.swift in Sources */,
01073F0F2311AE2E007162C9 /* String+Version.swift in Sources */,
0198B99E23196689003F7578 /* BrowseMenuAction.swift in Sources */,
01073F132311E1CF007162C9 /* Globals.swift in Sources */,


+ 47
- 0
RSwitch/Base.lproj/Main.storyboard View File

@ -3,6 +3,7 @@
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14865.1"/>
<plugIn identifier="com.apple.WebKit2IBPlugin" version="14865.1"/>
<capability name="System colors introduced in macOS 10.14" minToolsVersion="10.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@ -696,6 +697,52 @@
<point key="canvasLocation" x="435" y="-92"/>
</scene>
<!--Window Controller-->
<scene sceneID="MKQ-4Y-Oth">
<objects>
<windowController storyboardIdentifier="wkPanelController" id="qjv-aN-QDU" sceneMemberID="viewController">
<window key="window" identifier="wkPanelController" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="0uE-Xe-6tV">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<rect key="contentRect" x="-480" y="985" width="480" height="270"/>
<rect key="screenRect" x="-2560" y="0.0" width="2560" height="1440"/>
<connections>
<outlet property="delegate" destination="qjv-aN-QDU" id="ydd-t5-B2B"/>
</connections>
</window>
<connections>
<segue destination="tec-9J-KNb" kind="relationship" relationship="window.shadowedContentViewController" id="idQ-y1-OGg"/>
</connections>
</windowController>
<customObject id="QEf-Ku-YK9" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-454" y="470"/>
</scene>
<!--Web View Controller-->
<scene sceneID="1Kq-xR-oeu">
<objects>
<viewController id="tec-9J-KNb" customClass="WebViewController" customModule="RSwitch" sceneMemberID="viewController">
<view key="view" id="8mP-w9-nMB">
<rect key="frame" x="0.0" y="0.0" width="970" height="790"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<wkWebView identifier="rstudio" wantsLayer="YES" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GCI-JV-AYs">
<rect key="frame" x="0.0" y="0.0" width="970" height="790"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<wkWebViewConfiguration key="configuration">
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
<wkPreferences key="preferences"/>
</wkWebViewConfiguration>
</wkWebView>
</subviews>
</view>
<connections>
<outlet property="rstudioServerView" destination="GCI-JV-AYs" id="EHB-ub-k1V"/>
</connections>
</viewController>
<customObject id="4Rz-ye-vi7" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="317" y="1011"/>
</scene>
<!--Window Controller-->
<scene sceneID="fg4-ci-0Xb">
<objects>
<windowController storyboardIdentifier="aboutPanelController" id="TxV-Pk-3ou" sceneMemberID="viewController">


+ 16
- 3
RSwitch/Swift/AppDelegate.swift View File

@ -10,14 +10,18 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@objc func showAabout(_ sender: NSMenuItem?) { abtController.showWindow(self) }
@objc func showAbout(_ sender: NSMenuItem?) {
abtController.showWindow(self)
abtController.window?.orderFront(self)
NSApp.activate(ignoringOtherApps: true)
}
@objc func performTimer(_ sender: Timer) { print("timer fired") }
var mainStoryboard: NSStoryboard!
var abtController: NSWindowController!
var rsController: NSWindowController!
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
let statusMenu = NSMenu(title: "RSwitch")
@ -25,6 +29,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var rdevel_enabled: Bool!
var rstudio_enabled: Bool!
var timer: Timer? = nil;
var sess : RStudioServerSessionManager!
override init() {
@ -35,6 +41,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
rdevel_enabled = true
rstudio_enabled = true
sess = RStudioServerSessionManager()
sess.newSession(url: "https://rstudio.hrbrmstr.de", title: "One")
sess.newSession(url: "https://rud.is/b", title: "Two")
sess.debugSessions()
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
}
@ -57,6 +69,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
statusItem.menu = statusMenu
mainStoryboard = NSStoryboard(name: "Main", bundle: nil)
abtController = (mainStoryboard.instantiateController(withIdentifier: "aboutPanelController") as! NSWindowController)
timer = Timer.scheduledTimer(


+ 3
- 1
RSwitch/Swift/Menu.swift View File

@ -69,13 +69,15 @@ extension AppDelegate: NSMenuDelegate {
// Add launchers
AppMenuAction.populateLaunchers(menu: menu)
RStudioServerMenuAction.populateRStudioServerSessions(menu: menu, manager: sess)
// Add a Check for update
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "Check for update…", action: #selector(checkForUpdate), keyEquivalent: ""))
// Add an About item
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "About RSwitch…", action: #selector(showAabout), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "About RSwitch…", action: #selector(showAbout), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "RSwitch Help…", action: #selector(rswitch_help), keyEquivalent: ""))
// Toggle Dock Icon


+ 57
- 0
RSwitch/Swift/MenuActions/RStudioServerAction.swift View File

@ -0,0 +1,57 @@
//
// RStudioServerAction.swift
// RSwitch
//
// Created by hrbrmstr on 9/5/19.
// Copyright © 2019 Bob Rudis. All rights reserved.
//
import Foundation
import Cocoa
extension AppDelegate {
@objc func newRstudioServerSession(_ sender: NSMenuItem) {
print("New Session")
}
@objc func activateServerSession(_ sender: NSMenuItem) {
print("activate Session")
let sess = (sender.representedObject as! RStudioServerSession)
sess.show()
}
}
class RStudioServerMenuAction {
public static func populateRStudioServerSessions(menu: NSMenu, manager : RStudioServerSessionManager) {
menu.addItem(NSMenuItem.separator())
let rsDropdown = NSMenuItem(title: "RStudio Server Sessions", action: nil, keyEquivalent: "")
let rsSub = NSMenu()
menu.addItem(rsDropdown)
menu.setSubmenu(rsSub, for: rsDropdown)
let newRStudioSessItem = NSMenuItem(title: "New RStudio Server Connection…", action: Selector(("newRstudioServerSession:")), keyEquivalent: "")
rsSub.addItem(newRStudioSessItem)
rsSub.addItem(NSMenuItem.separator())
for sess in manager.sessions {
let sessItem = NSMenuItem(title: sess.menuTitle, action: Selector(("activateServerSession:")), keyEquivalent: "")
sessItem.representedObject = sess
rsSub.addItem(sessItem)
}
}
}

+ 43
- 0
RSwitch/Swift/Sessions/RStudioServerSession.swift View File

@ -0,0 +1,43 @@
//
// RStudioServerSession.swift
// RSwitch
//
// Created by hrbrmstr on 9/5/19.
// Copyright © 2019 Bob Rudis. All rights reserved.
//
import Foundation
import Cocoa
class RStudioServerSession {
var url : String
var menuTitle : String
var wk : NSWindowController?
var wv : WebViewController?
init(url: String, title: String) {
self.url = url
self.menuTitle = title
}
func show() {
let appDelegate = NSApplication.shared.delegate as! AppDelegate
let mainStoryboard = appDelegate.mainStoryboard!
if (wk == nil) {
wk = (mainStoryboard.instantiateController(withIdentifier: "wkPanelController") as! NSWindowController)
wv = wk!.window?.contentViewController as? WebViewController
wv!.url = url
}
wk?.window?.orderFront(appDelegate)
wk?.showWindow(appDelegate)
wk?.window?.orderFront(appDelegate)
NSApp.activate(ignoringOtherApps: true)
}
}

+ 29
- 0
RSwitch/Swift/Sessions/RStudioServerSessionManager.swift View File

@ -0,0 +1,29 @@
//
// RStudioServerSessionManager.swift
// RSwitch
//
// Created by hrbrmstr on 9/5/19.
// Copyright © 2019 Bob Rudis. All rights reserved.
//
import Foundation
import Cocoa
import WebKit
class RStudioServerSessionManager {
var sessions = [ RStudioServerSession ]()
func newSession(url: String, title: String) {
sessions.append(RStudioServerSession(url: url, title: title))
}
func debugSessions() {
for s in sessions {
print(s.menuTitle)
}
}
}

+ 29
- 0
RSwitch/Swift/WebViewController.swift View File

@ -0,0 +1,29 @@
//
// WebViewController.swift
// RSwitch
//
// Created by hrbrmstr on 9/5/19.
// Copyright © 2019 Bob Rudis. All rights reserved.
//
import Cocoa
import WebKit
class WebViewController: NSViewController {
@IBOutlet weak var rstudioServerView: WKWebView!
var url = "https://rstudio.hrbrmstr.de/"
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear() {
super.viewDidAppear()
self.view.window?.title = url
let request = URLRequest(url: URL(string: url)!)
rstudioServerView.load(request)
}
}

Loading…
Cancel
Save