Skip to content

Commit

Permalink
Fixed #39
Browse files Browse the repository at this point in the history
  • Loading branch information
0xWDG committed Jan 15, 2016
1 parent b83e07d commit 720c436
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
3 changes: 2 additions & 1 deletion WebShell.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
isa = PBXGroup;
children = (
25B222591C25328E00F848B7 /* WebShell */,
25B222581C25328E00F848B7 /* Products */,
);
sourceTree = "<group>";
};
Expand All @@ -50,6 +49,7 @@
25B222571C25328E00F848B7 /* WebShell.app */,
);
name = Products;
path = ..;
sourceTree = "<group>";
};
25B222591C25328E00F848B7 /* WebShell */ = {
Expand All @@ -61,6 +61,7 @@
25B2225E1C25328E00F848B7 /* Assets.xcassets */,
25B222601C25328E00F848B7 /* Main.storyboard */,
25B222631C25328E00F848B7 /* Info.plist */,
25B222581C25328E00F848B7 /* Products */,
);
path = WebShell;
sourceTree = "<group>";
Expand Down
4 changes: 3 additions & 1 deletion WebShell/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
NSApplication.sharedApplication().dockTile.badgeLabel = ""
NSNotificationCenter.defaultCenter().postNotificationName("clearNotificationCount", object: nil)
}

@IBAction func printThisPage(sender: AnyObject) {
NSNotificationCenter.defaultCenter().postNotificationName("printThisPage", object: nil)
}
@IBAction func goHome(sender: AnyObject) {
NSNotificationCenter.defaultCenter().postNotificationName("goHome", object: nil)
}
Expand Down
7 changes: 6 additions & 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="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15E27e" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
<plugIn identifier="com.apple.WebKitIBPlugin" version="9531"/>
Expand Down Expand Up @@ -69,6 +69,11 @@
<action selector="reload:" target="Voe-Tx-rLC" id="6qi-i1-yDo"/>
</connections>
</menuItem>
<menuItem title="Print" keyEquivalent="p" id="dlv-gu-35p">
<connections>
<action selector="printThisPage:" target="Voe-Tx-rLC" id="Jy5-eU-rLh"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="7ie-IE-K6N"/>
<menuItem title="Copy current URL" id="F42-Mv-oVO">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down
Empty file modified WebShell/Battery.swift
100644 → 100755
Empty file.
26 changes: 25 additions & 1 deletion WebShell/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ViewController: NSViewController, WebFrameLoadDelegate, WebUIDelegate, Web

func addObservers() {
// add menu action observers
let observers = ["goHome", "reload", "copyUrl", "clearNotificationCount"]
let observers = ["goHome", "reload", "copyUrl", "clearNotificationCount", "printThisPage"]

for observer in observers{
NSNotificationCenter.defaultCenter().addObserver(self, selector: NSSelectorFromString(observer), name: observer, object: nil)
Expand Down Expand Up @@ -346,6 +346,12 @@ class ViewController: NSViewController, WebFrameLoadDelegate, WebUIDelegate, Web
// _blank internal
jsContext.objectForKeyedSubscript("app").setObject(unsafeBitCast(openNow, AnyObject.self), forKeyedSubscript:"openInternal")

// @wdg Add Print Support
// Issue: #39
// window.print()
let printMe: @convention(block) (NSString?) -> Void = { (url:NSString?) in self.printThisPage() }
jsContext.objectForKeyedSubscript("window").setObject(unsafeBitCast(printMe, AnyObject.self), forKeyedSubscript: "print")

// navigator.getBattery()
jsContext.objectForKeyedSubscript("navigator").setObject(BatteryManager.self, forKeyedSubscript: "battery")

Expand All @@ -372,6 +378,7 @@ class ViewController: NSViewController, WebFrameLoadDelegate, WebUIDelegate, Web
debugMenu.addItem(NSMenuItem.init(title: "Print arguments", action: Selector("_debugDumpArguments:"), keyEquivalent: ""))
debugMenu.addItem(NSMenuItem.init(title: "Open URL", action: Selector("_openURL:"), keyEquivalent: ""))
debugMenu.addItem(NSMenuItem.init(title: "Report an issue on this page", action: Selector("_reportThisPage:"), keyEquivalent: ""))
debugMenu.addItem(NSMenuItem.init(title: "Print this page", action: Selector("printThisPage:"), keyEquivalent: ""))

let item = NSMenuItem.init(title: "Debug", action: Selector("_doNothing:"), keyEquivalent: "")
item.submenu = debugMenu
Expand Down Expand Up @@ -431,6 +438,23 @@ class ViewController: NSViewController, WebFrameLoadDelegate, WebUIDelegate, Web
NSWorkspace.sharedWorkspace().openURL(NSURL(string: (url as String))!)
}

// @wdg Add Print Support
// Issue: #39
func printThisPage() {
let url = mainWebview.mainFrame.dataSource?.request?.URL?.absoluteString

let operation:NSPrintOperation = NSPrintOperation.init(view: mainWebview)
operation.jobTitle = "Printing \(url!)"

// If want to print landscape
operation.printInfo.orientation = NSPaperOrientation.Landscape
operation.printInfo.scalingFactor = 0.7

if operation.runOperation() {
print("Printed?")
}
}

// Function to call for the window.open (popup)
func openNewWindow(url: String, height: String, width: String) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
Expand Down
Empty file modified contributing.md
100644 → 100755
Empty file.

0 comments on commit 720c436

Please sign in to comment.