Skip to content

Commit

Permalink
Change the way a window is moved. Fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
steve228uk committed Jul 1, 2018
1 parent d6789b4 commit 5624491
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 10 deletions.
16 changes: 14 additions & 2 deletions YT Music.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
281F979920E9588A0033D930 /* WindowMovableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 281F979820E9588A0033D930 /* WindowMovableView.swift */; };
286AD73F20D9061400B2F45F /* custom.css in Resources */ = {isa = PBXBuildFile; fileRef = 286AD73E20D9061400B2F45F /* custom.css */; };
286AD74120D909AB00B2F45F /* CustomWebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 286AD74020D909AB00B2F45F /* CustomWebView.swift */; };
286AD74320D90E1B00B2F45F /* CustomWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 286AD74220D90E1B00B2F45F /* CustomWindow.swift */; };
Expand All @@ -18,6 +19,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
281F979820E9588A0033D930 /* WindowMovableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowMovableView.swift; sourceTree = "<group>"; };
286AD73E20D9061400B2F45F /* custom.css */ = {isa = PBXFileReference; lastKnownFileType = text.css; path = custom.css; sourceTree = "<group>"; };
286AD74020D909AB00B2F45F /* CustomWebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomWebView.swift; sourceTree = "<group>"; };
286AD74220D90E1B00B2F45F /* CustomWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomWindow.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -45,6 +47,16 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
281F979A20E958C00033D930 /* Views */ = {
isa = PBXGroup;
children = (
286AD74020D909AB00B2F45F /* CustomWebView.swift */,
286AD74220D90E1B00B2F45F /* CustomWindow.swift */,
281F979820E9588A0033D930 /* WindowMovableView.swift */,
);
path = Views;
sourceTree = "<group>";
};
28DA92A920D90169004B2A6D = {
isa = PBXGroup;
children = (
Expand All @@ -66,10 +78,9 @@
28DA92B420D90169004B2A6D /* YT Music */ = {
isa = PBXGroup;
children = (
281F979A20E958C00033D930 /* Views */,
288C970E20D91A8B001672E1 /* YT Music.entitlements */,
28DA92B520D90169004B2A6D /* AppDelegate.swift */,
286AD74020D909AB00B2F45F /* CustomWebView.swift */,
286AD74220D90E1B00B2F45F /* CustomWindow.swift */,
28DA92B720D90169004B2A6D /* ViewController.swift */,
28DA92B920D9016A004B2A6D /* Assets.xcassets */,
28DA92BB20D9016A004B2A6D /* Main.storyboard */,
Expand Down Expand Up @@ -214,6 +225,7 @@
buildActionMask = 2147483647;
files = (
286AD74320D90E1B00B2F45F /* CustomWindow.swift in Sources */,
281F979920E9588A0033D930 /* WindowMovableView.swift in Sources */,
28DA92B820D90169004B2A6D /* ViewController.swift in Sources */,
28DA92B620D90169004B2A6D /* AppDelegate.swift in Sources */,
286AD74120D909AB00B2F45F /* CustomWebView.swift in Sources */,
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions YT Music/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.3</string>
<string>1.0.4</string>
<key>CFBundleVersion</key>
<string>4</string>
<string>5</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.music</string>
<key>LSMinimumSystemVersion</key>
Expand Down
11 changes: 11 additions & 0 deletions YT Music/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import MediaKeyTap
class ViewController: NSViewController {

var webView: CustomWebView!
var movableView: WindowMovableView!
var mediaKeyTap: MediaKeyTap?
var backButton: NSButton!
var forwardButton: NSButton!
Expand Down Expand Up @@ -45,12 +46,15 @@ class ViewController: NSViewController {
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = CustomWebView(frame: .zero, configuration: webConfiguration)
webView.wantsLayer = true
webView.layerContentsRedrawPolicy = .onSetNeedsDisplay
webView.frame = NSRect(x: 0, y: 0, width: 1024, height: 768)
webView.allowsBackForwardNavigationGestures = true
webView.uiDelegate = self
webView.navigationDelegate = self
webView.customUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.1 Safari/605.1.15"

addMovableView()
addNavigationButtons()

view = webView
Expand Down Expand Up @@ -78,6 +82,7 @@ class ViewController: NSViewController {
view.addSubview(btn)
}

movableView.frame = CGRect(x: 0, y: 0, width: webView.frame.width, height: 20)

}

Expand Down Expand Up @@ -131,6 +136,12 @@ class ViewController: NSViewController {
webView.goForward()
}

func addMovableView() {
movableView = WindowMovableView(frame: .zero)
movableView.frame = CGRect(x: 0, y: 0, width: webView.frame.width, height: 20)
webView.addSubview(movableView)
}

}

// MARK: - Delegates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ import WebKit

class CustomWebView: WKWebView {

override var mouseDownCanMoveWindow: Bool {
return true
}

override var isOpaque: Bool {
return true
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CustomWindow: NSWindow {

titleVisibility = .hidden
titlebarAppearsTransparent = true
styleMask.insert(.fullSizeContentView)
// styleMask.insert(.fullSizeContentView)

identifier = NSUserInterfaceItemIdentifier(rawValue: "main")
backgroundColor = NSColor(hue:0.00, saturation:0.00, brightness:0.07, alpha:1.00)
Expand Down
34 changes: 34 additions & 0 deletions YT Music/Views/WindowMovableView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// WindowMovableView.swift
// YT Music
//
// Created by Stephen Radford on 01/07/2018.
// Copyright © 2018 Cocoon Development Ltd. All rights reserved.
//

import Cocoa

class WindowMovableView: NSView {

override var mouseDownCanMoveWindow: Bool {
return true
}

override var isOpaque: Bool {
return false
}

override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
return true
}

override func mouseDragged(with event: NSEvent) {
window?.performDrag(with: event)
}

override func mouseUp(with event: NSEvent) {
guard event.clickCount == 2, let window = window else { return }
window.setIsZoomed(!window.isZoomed)
}

}

0 comments on commit 5624491

Please sign in to comment.