Skip to content

Commit

Permalink
fixed #44 and #60
Browse files Browse the repository at this point in the history
  • Loading branch information
0xWDG committed May 1, 2016
1 parent 8434b71 commit 206721a
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 241 deletions.
2 changes: 1 addition & 1 deletion WebShell/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15F24b" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15F28b" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
<plugIn identifier="com.apple.WebKitIBPlugin" version="10116"/>
Expand Down
3 changes: 3 additions & 0 deletions WebShell/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class WebShell {
// Menubar app (right side next to clock) (Default: true)
"MenuBarApp": false,

// Navigate trough trackpad (back/forward) (Default: true)
"navigateViaTrackpad": true,

// Media keys settings
"MediaKeys": [
// Enable "Back" & "Forward"
Expand Down
2 changes: 1 addition & 1 deletion WebShell/WebShellCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension ViewController {
// Issue: #48
let ws = NSWorkspace.sharedWorkspace()
do {
if (WebShell().Settings["debugmode"] as! Bool) {
if (WebShellSettings["debugmode"] as! Bool) {
try ws.launchApplicationAtURL(NSURL(string: "file://\(Process.arguments[0])")!, options: .NewInstance, configuration: [NSWorkspaceLaunchConfigurationArguments: ["-NSDocumentRevisionsDebugMode", "YES", "-url", url, "-height", height, "-width", width]])
} else {
try ws.launchApplicationAtURL(NSURL(string: Process.arguments[0])!, options: .NewInstance, configuration: [NSWorkspaceLaunchConfigurationArguments: ["-url", url, "-height", height, "-width", width]])
Expand Down
12 changes: 6 additions & 6 deletions WebShell/WebShellCustomInject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ extension ViewController {
*/
internal func _WSInjectJS(jsContext: JSContext!) {
// JSInject
if (WebShell().Settings["JSInject"] as! String != "") {
jsContext.evaluateScript(WebShell().Settings["JSInject"] as! String)
if (WebShellSettings["JSInject"] as! String != "") {
jsContext.evaluateScript(WebShellSettings["JSInject"] as! String)
}
_WSFindJS(jsContext)
}
Expand All @@ -38,8 +38,8 @@ extension ViewController {
*/
internal func _WSInjectCSS(jsContext: JSContext!) {
// CSSInject
if (WebShell().Settings["CSSInject"] as! String != "") {
let css: String = (WebShell().Settings["CSSInject"] as! String)
if (WebShellSettings["CSSInject"] as! String != "") {
let css: String = (WebShellSettings["CSSInject"] as! String)
.stringByReplacingOccurrencesOfString("\n", withString: "")
.stringByReplacingOccurrencesOfString("\r", withString: "")
.stringByReplacingOccurrencesOfString("'", withString: "\\'")
Expand All @@ -50,7 +50,7 @@ extension ViewController {
}

internal func _WSFindCSS(jsContext: JSContext!) {
if (WebShell().Settings["EnableInjectImport"] as! Bool) { // (EII)
if (WebShellSettings["EnableInjectImport"] as! Bool) { // (EII)

let Seperated = (Process.arguments[0]).componentsSeparatedByString("/")
var newPath = ""
Expand Down Expand Up @@ -90,7 +90,7 @@ extension ViewController {
}

internal func _WSFindJS(jsContext: JSContext!) {
if (WebShell().Settings["EnableInjectImport"] as! Bool) { // (EII)
if (WebShellSettings["EnableInjectImport"] as! Bool) { // (EII)

let Seperated = (Process.arguments[0]).componentsSeparatedByString("/")
var newPath = ""
Expand Down
18 changes: 9 additions & 9 deletions WebShell/WebShellDebug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ extension ViewController {
// for (var i = 1; i < Int(Process.argc) ; i = i + 2) {
if ((String(Process.arguments[i])) == "-NSDocumentRevisionsDebugMode") {
if ((String(Process.arguments[i + 1])) == "YES") {
WebShell().Settings["debugmode"] = true
WebShell().Settings["consoleSupport"] = true
WebShellSettings["debugmode"] = true
WebShellSettings["consoleSupport"] = true
}
}

if ((String(Process.arguments[i])).uppercaseString == "-DEBUG") {
if ((String(Process.arguments[i + 1])).uppercaseString == "YES" || (String(Process.arguments[i + 1])).uppercaseString == "true") {
WebShell().Settings["debugmode"] = true
WebShell().Settings["consoleSupport"] = true
WebShellSettings["debugmode"] = true
WebShellSettings["consoleSupport"] = true
}
}

Expand All @@ -40,15 +40,15 @@ extension ViewController {
}

if ((String(Process.arguments[i])) == "-url") {
WebShell().Settings["url"] = String(Process.arguments[i + 1])
WebShellSettings["url"] = String(Process.arguments[i + 1])
}

if ((String(Process.arguments[i])) == "-height") {
WebShell().Settings["initialWindowHeight"] = (Int(Process.arguments[i + 1]) > 250) ? Int(Process.arguments[i + 1]) : Int(250)
WebShellSettings["initialWindowHeight"] = (Int(Process.arguments[i + 1]) > 250) ? Int(Process.arguments[i + 1]) : Int(250)
}

if ((String(Process.arguments[i])) == "-width") {
WebShell().Settings["initialWindowWidth"] = (Int(Process.arguments[i + 1]) > 250) ? Int(Process.arguments[i + 1]) : Int(250)
WebShellSettings["initialWindowWidth"] = (Int(Process.arguments[i + 1]) > 250) ? Int(Process.arguments[i + 1]) : Int(250)
}
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ extension ViewController {
}

var NewMenu: [AnyObject] = [AnyObject]()
let contextMenu = WebShell().Settings["Contextmenu"] as! [String: Bool]
let contextMenu = WebShellSettings["Contextmenu"] as! [String: Bool]

// if can back
if (contextMenu["BackAndForward"]!) {
Expand Down Expand Up @@ -113,7 +113,7 @@ extension ViewController {

NewMenu.append(NSMenuItem.separatorItem())
// Add debug menu. (if enabled)
if (WebShell().Settings["debugmode"] as! Bool) {
if (WebShellSettings["debugmode"] as! Bool) {
let debugMenu = NSMenu(title: "Debug")
debugMenu.addItem(IElement)
debugMenu.addItem(NSMenuItem.init(title: "Open New window", action: #selector(ViewController._debugNewWindow(_:)), keyEquivalent: ""))
Expand Down
4 changes: 2 additions & 2 deletions WebShell/WebShellInjector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extension ViewController {

// @wdg Hack URL's if settings is set.
// Issue: #5
if ((WebShell().Settings["openInNewScreen"] as? Bool) != false) {
if ((WebShellSettings["openInNewScreen"] as? Bool) != false) {
// _blank to external
// JavaScript -> Select all <a href='...' target='_blank'>
jsContext.evaluateScript("var links=document.querySelectorAll('a');for(var i=0;i<links.length;i++){if(links[i].target==='_blank'){links[i].addEventListener('click',function () {app.openExternal(this.href);})}}")
Expand All @@ -90,7 +90,7 @@ extension ViewController {

// Add console.log ;)
// Add Console.log (and console.error, and console.warn)
if (WebShell().Settings["consoleSupport"] as! Bool) {
if (WebShellSettings["consoleSupport"] as! Bool) {
jsContext.evaluateScript("var console = {log: function () {var message = '';for (var i = 0; i < arguments.length; i++) {message += arguments[i] + ' '};console.print(message)},warn: function () {var message = '';for (var i = 0; i < arguments.length; i++) {message += arguments[i] + ' '};console.print(message)},error: function () {var message = '';for (var i = 0; i < arguments.length; i++){message += arguments[i] + ' '};console.print(message)}};")
let logFunction: @convention(block)(NSString!) -> Void = {(message: NSString!) in
print("JS: \(message)")
Expand Down
2 changes: 1 addition & 1 deletion WebShell/WebShellMediaKeysSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ extension ViewController {

// @wdg Merge Statut with WebShell.
// Issue: #56
if (WebShell().Settings["MenuBarApp"] as! Bool) {
if (WebShellSettings["MenuBarApp"] as! Bool) {
if ((NSApplication.sharedApplication().keyWindow) != nil) {
if (self.MustCloseWindow) {
NSApplication.sharedApplication().keyWindow?.close()
Expand Down
22 changes: 11 additions & 11 deletions WebShell/WebShellPageActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension ViewController {
}

func goHome() {
loadUrl((WebShell().Settings["url"] as? String)!)
loadUrl((WebShellSettings["url"] as? String)!)
}

func reload() {
Expand All @@ -38,13 +38,13 @@ extension ViewController {

func initSettings() {
// controll the progress bar
if (!(WebShell().Settings["showLoadingBar"] as? Bool)!) {
if (!(WebShellSettings["showLoadingBar"] as? Bool)!) {
progressBar.hidden = true // @wdg: Better progress indicator | Issue: #37
}

// @wdg Add Custom useragent support
// Issue: #52
if ((WebShell().Settings["useragent"] as! String).lowercaseString == "default") {
if ((WebShellSettings["useragent"] as! String).lowercaseString == "default") {
var UA: String = NSBundle.mainBundle().infoDictionary!["CFBundleName"] as! String
UA = UA.stringByAppendingString("/")
UA = UA.stringByAppendingString(NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"] as! String)
Expand All @@ -53,13 +53,13 @@ extension ViewController {
NSUserDefaults.standardUserDefaults().registerDefaults(["UserAgent": UA]) // For iOS
mainWebview.customUserAgent = UA // For Mac OS X
} else {
let UA: String = WebShell().Settings["useragent"] as! String
let UA: String = WebShellSettings["useragent"] as! String
NSUserDefaults.standardUserDefaults().registerDefaults(["UserAgent": UA]) // For iOS
mainWebview.customUserAgent = UA // For Mac OS X
}

// set launching text
launchingLabel.stringValue = (WebShell().Settings["launchingText"] as? String)!
launchingLabel.stringValue = (WebShellSettings["launchingText"] as? String)!
}

func initWindow() {
Expand All @@ -68,8 +68,8 @@ extension ViewController {
// set window size
var frame: NSRect = mainWindow.frame

let WIDTH: CGFloat = CGFloat(WebShell().Settings["initialWindowWidth"] as! Int),
HEIGHT: CGFloat = CGFloat(WebShell().Settings["initialWindowHeight"] as! Int)
let WIDTH: CGFloat = CGFloat(WebShellSettings["initialWindowWidth"] as! Int),
HEIGHT: CGFloat = CGFloat(WebShellSettings["initialWindowHeight"] as! Int)

frame.size.width = WIDTH
frame.size.height = HEIGHT
Expand All @@ -78,9 +78,9 @@ extension ViewController {
// Issue: #19
// Note: do not use HEIGHT, WIDTH for some strange reason the window will be positioned 25px from bottom!
let ScreenHeight: CGFloat = (NSScreen.mainScreen()?.frame.size.width)!,
WindowHeight: CGFloat = CGFloat(WebShell().Settings["initialWindowWidth"] as! Int), // do not use HEIGHT!
WindowHeight: CGFloat = CGFloat(WebShellSettings["initialWindowWidth"] as! Int), // do not use HEIGHT!
ScreenWidth: CGFloat = (NSScreen.mainScreen()?.frame.size.height)!,
WindowWidth: CGFloat = CGFloat(WebShell().Settings["initialWindowHeight"] as! Int) // do not use WIDTH!
WindowWidth: CGFloat = CGFloat(WebShellSettings["initialWindowHeight"] as! Int) // do not use WIDTH!
frame.origin.x = (ScreenHeight / 2 - WindowHeight / 2)
frame.origin.y = (ScreenWidth / 2 - WindowWidth / 2)

Expand All @@ -91,7 +91,7 @@ extension ViewController {
mainWindow.frame = frame

// set window title
mainWindow.window?.title = WebShell().Settings["title"] as! String
mainWindow.window?.title = WebShellSettings["title"] as! String

// Force some preferences before loading...
mainWebview.preferences.javaScriptEnabled = true
Expand All @@ -100,7 +100,7 @@ extension ViewController {
}

func loadUrl(url: String) {
if ((WebShell().Settings["showLoadingBar"] as? Bool)!) {
if ((WebShellSettings["showLoadingBar"] as? Bool)!) {
progressBar.hidden = false
progressBar.startAnimation(self)
progressBar.maxValue = 100;
Expand Down
Loading

0 comments on commit 206721a

Please sign in to comment.