masakih

OSXを起動したらそこには『艦隊これくしょん -艦これ-』の世界が広がっていたのです!?

  • R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythongamewindowsbathyscaphephpguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

Commit MetaInfo

修订版f50eabbc0ef47a37de07bdd0e2fbec5c9868533e (tree)
时间2018-04-18 00:37:26
作者masakih <masakih@user...>
Commitermasakih

Log Message

WKWebViewを導入

更改概述

差异

--- a/KanColleBrowserForOSX.xcodeproj/project.pbxproj
+++ b/KanColleBrowserForOSX.xcodeproj/project.pbxproj
@@ -164,14 +164,16 @@
164164 F4EF18A71B4D36E60021BF8D /* Project object */ = {
165165 isa = PBXProject;
166166 attributes = {
167- LastUpgradeCheck = 0640;
167+ LastUpgradeCheck = 0810;
168168 ORGANIZATIONNAME = "Hori,Masaki";
169169 TargetAttributes = {
170170 F4EF18AE1B4D36E60021BF8D = {
171171 CreatedOnToolsVersion = 6.4;
172+ LastSwiftMigration = 0810;
172173 };
173174 F4EF18BE1B4D36E60021BF8D = {
174175 CreatedOnToolsVersion = 6.4;
176+ LastSwiftMigration = 0810;
175177 TestTargetID = F4EF18AE1B4D36E60021BF8D;
176178 };
177179 };
@@ -278,6 +280,7 @@
278280 isa = XCBuildConfiguration;
279281 buildSettings = {
280282 ALWAYS_SEARCH_USER_PATHS = NO;
283+ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
281284 CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
282285 CLANG_CXX_LIBRARY = "libc++";
283286 CLANG_ENABLE_MODULES = YES;
@@ -287,14 +290,17 @@
287290 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
288291 CLANG_WARN_EMPTY_BODY = YES;
289292 CLANG_WARN_ENUM_CONVERSION = YES;
293+ CLANG_WARN_INFINITE_RECURSION = YES;
290294 CLANG_WARN_INT_CONVERSION = YES;
291295 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
296+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
292297 CLANG_WARN_UNREACHABLE_CODE = YES;
293298 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
294299 CODE_SIGN_IDENTITY = "-";
295300 COPY_PHASE_STRIP = NO;
296301 DEBUG_INFORMATION_FORMAT = dwarf;
297302 ENABLE_STRICT_OBJC_MSGSEND = YES;
303+ ENABLE_TESTABILITY = YES;
298304 GCC_C_LANGUAGE_STANDARD = gnu99;
299305 GCC_DYNAMIC_NO_PIC = NO;
300306 GCC_NO_COMMON_BLOCKS = YES;
@@ -310,7 +316,7 @@
310316 GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
311317 GCC_WARN_UNUSED_FUNCTION = YES;
312318 GCC_WARN_UNUSED_VARIABLE = YES;
313- MACOSX_DEPLOYMENT_TARGET = 10.10;
319+ MACOSX_DEPLOYMENT_TARGET = 10.12;
314320 MTL_ENABLE_DEBUG_INFO = YES;
315321 ONLY_ACTIVE_ARCH = YES;
316322 SDKROOT = macosx;
@@ -322,6 +328,7 @@
322328 isa = XCBuildConfiguration;
323329 buildSettings = {
324330 ALWAYS_SEARCH_USER_PATHS = NO;
331+ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
325332 CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
326333 CLANG_CXX_LIBRARY = "libc++";
327334 CLANG_ENABLE_MODULES = YES;
@@ -331,8 +338,10 @@
331338 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
332339 CLANG_WARN_EMPTY_BODY = YES;
333340 CLANG_WARN_ENUM_CONVERSION = YES;
341+ CLANG_WARN_INFINITE_RECURSION = YES;
334342 CLANG_WARN_INT_CONVERSION = YES;
335343 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
344+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
336345 CLANG_WARN_UNREACHABLE_CODE = YES;
337346 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
338347 CODE_SIGN_IDENTITY = "-";
@@ -348,9 +357,10 @@
348357 GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
349358 GCC_WARN_UNUSED_FUNCTION = YES;
350359 GCC_WARN_UNUSED_VARIABLE = YES;
351- MACOSX_DEPLOYMENT_TARGET = 10.10;
360+ MACOSX_DEPLOYMENT_TARGET = 10.12;
352361 MTL_ENABLE_DEBUG_INFO = NO;
353362 SDKROOT = macosx;
363+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
354364 };
355365 name = Release;
356366 };
@@ -361,7 +371,9 @@
361371 COMBINE_HIDPI_IMAGES = YES;
362372 INFOPLIST_FILE = KanColleBrowserForOSX/Info.plist;
363373 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
374+ PRODUCT_BUNDLE_IDENTIFIER = "com.masakih.$(PRODUCT_NAME:rfc1034identifier)";
364375 PRODUCT_NAME = "$(TARGET_NAME)";
376+ SWIFT_VERSION = 3.0;
365377 };
366378 name = Debug;
367379 };
@@ -372,7 +384,9 @@
372384 COMBINE_HIDPI_IMAGES = YES;
373385 INFOPLIST_FILE = KanColleBrowserForOSX/Info.plist;
374386 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
387+ PRODUCT_BUNDLE_IDENTIFIER = "com.masakih.$(PRODUCT_NAME:rfc1034identifier)";
375388 PRODUCT_NAME = "$(TARGET_NAME)";
389+ SWIFT_VERSION = 3.0;
376390 };
377391 name = Release;
378392 };
@@ -391,7 +405,9 @@
391405 );
392406 INFOPLIST_FILE = KanColleBrowserForOSXTests/Info.plist;
393407 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
408+ PRODUCT_BUNDLE_IDENTIFIER = "com.masakih.$(PRODUCT_NAME:rfc1034identifier)";
394409 PRODUCT_NAME = "$(TARGET_NAME)";
410+ SWIFT_VERSION = 3.0;
395411 TEST_HOST = "$(BUILT_PRODUCTS_DIR)/KanColleBrowserForOSX.app/Contents/MacOS/KanColleBrowserForOSX";
396412 };
397413 name = Debug;
@@ -407,7 +423,9 @@
407423 );
408424 INFOPLIST_FILE = KanColleBrowserForOSXTests/Info.plist;
409425 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
426+ PRODUCT_BUNDLE_IDENTIFIER = "com.masakih.$(PRODUCT_NAME:rfc1034identifier)";
410427 PRODUCT_NAME = "$(TARGET_NAME)";
428+ SWIFT_VERSION = 3.0;
411429 TEST_HOST = "$(BUILT_PRODUCTS_DIR)/KanColleBrowserForOSX.app/Contents/MacOS/KanColleBrowserForOSX";
412430 };
413431 name = Release;
@@ -431,6 +449,7 @@
431449 F4EF18CB1B4D36E60021BF8D /* Release */,
432450 );
433451 defaultConfigurationIsVisible = 0;
452+ defaultConfigurationName = Release;
434453 };
435454 F4EF18CC1B4D36E60021BF8D /* Build configuration list for PBXNativeTarget "KanColleBrowserForOSXTests" */ = {
436455 isa = XCConfigurationList;
@@ -439,6 +458,7 @@
439458 F4EF18CE1B4D36E60021BF8D /* Release */,
440459 );
441460 defaultConfigurationIsVisible = 0;
461+ defaultConfigurationName = Release;
442462 };
443463 /* End XCConfigurationList section */
444464 };
--- a/KanColleBrowserForOSX/AppDelegate.swift
+++ b/KanColleBrowserForOSX/AppDelegate.swift
@@ -13,8 +13,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1313
1414 var mainWindowController: KCBFOMainWindowController!
1515
16- func applicationDidFinishLaunching(aNotification: NSNotification) {
17- mainWindowController = KCBFOMainWindowController.new()
16+ func applicationDidFinishLaunching(_ aNotification: Notification) {
17+ mainWindowController = KCBFOMainWindowController.makeInstance()
1818 mainWindowController.showWindow(nil)
1919 }
2020 }
--- a/KanColleBrowserForOSX/Info.plist
+++ b/KanColleBrowserForOSX/Info.plist
@@ -9,7 +9,7 @@
99 <key>CFBundleIconFile</key>
1010 <string></string>
1111 <key>CFBundleIdentifier</key>
12- <string>com.masakih.$(PRODUCT_NAME:rfc1034identifier)</string>
12+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1313 <key>CFBundleInfoDictionaryVersion</key>
1414 <string>6.0</string>
1515 <key>CFBundleName</key>
@@ -22,6 +22,8 @@
2222 <string>????</string>
2323 <key>CFBundleVersion</key>
2424 <string>%%%%REVISION%%%%</string>
25+ <key>LSHasLocalizedDisplayName</key>
26+ <true/>
2527 <key>LSMinimumSystemVersion</key>
2628 <string>$(MACOSX_DEPLOYMENT_TARGET)</string>
2729 <key>NSHumanReadableCopyright</key>
@@ -30,7 +32,10 @@
3032 <string>MainMenu</string>
3133 <key>NSPrincipalClass</key>
3234 <string>NSApplication</string>
33- <key>LSHasLocalizedDisplayName</key>
34- <true/>
35+ <key>NSAppTransportSecurity</key>
36+ <dict>
37+ <key>NSAllowsArbitraryLoadsInWebContent</key>
38+ <true/>
39+ </dict>
3540 </dict>
3641 </plist>
--- a/KanColleBrowserForOSX/KCBFOMainWindowController.swift
+++ b/KanColleBrowserForOSX/KCBFOMainWindowController.swift
@@ -12,101 +12,80 @@ import WebKit
1212 class KCBFOMainWindowController: NSWindowController {
1313
1414 @IBOutlet var clipView: NSClipView!
15- @IBOutlet var webView: WebView!
15+ var webView: WKWebView!
1616
17- var flashTopLeft: NSPoint = NSMakePoint(2600, 145);
17+ var flashTopLeft: NSPoint = NSPoint(x: 600, y: 77)
1818
1919 let gamePageURL = "http://www.dmm.com/netgame/social/-/gadgets/=/app_id=854854/"
20-
21- override class func new() -> KCBFOMainWindowController {
22- return KCBFOMainWindowController(windowNibName: "KCBFOMainWindowController")
23- }
24-
20+
21+ class func makeInstance() -> KCBFOMainWindowController {
22+ return KCBFOMainWindowController(windowNibName: "KCBFOMainWindowController")
23+ }
24+
25+
2526 override func windowDidLoad() {
2627 super.windowDidLoad()
28+
29+ let pref = WKPreferences()
30+ pref.plugInsEnabled = true
31+ let config = WKWebViewConfiguration()
32+ config.preferences = pref
33+ config.applicationNameForUserAgent = "Version/11.1 Safari/605.1.15"
34+
35+ let js = """
36+ var style = document.createElement('style');
37+ style.innerHTML = 'html { overflow: hidden; }';
38+ document.head.appendChild(style);
39+"""
40+ let script = WKUserScript(source: js, injectionTime: .atDocumentEnd, forMainFrameOnly: false)
41+ config.userContentController.addUserScript(script)
42+
43+ let frame = CGRect(x: 0, y: 0, width: 2000, height: 2_000)
44+ webView = WKWebView(frame: frame, configuration: config)
45+ webView.navigationDelegate = self
2746
2847 clipView.documentView = webView
2948
3049 adjustFlash()
3150
32- webView.mainFrame.frameView.allowsScrolling = false
33- webView.applicationNameForUserAgent = "Version/8.0.6 Safari/600.6.3"
34- webView.mainFrameURL = gamePageURL
51+ webView.allowsBackForwardNavigationGestures = false
52+ webView.allowsMagnification = false
53+ webView.allowsLinkPreview = false
54+
55+ loadURLString(urlString: gamePageURL)
56+ }
57+
58+ func loadURLString(urlString: String) {
59+ guard let url = URL(string: urlString) else { return }
60+ let req = URLRequest(url: url)
61+ webView.load(req)
3562 }
63+
3664
37- @IBAction func reloadContent(sender: AnyObject?) {
38- if webView.mainFrameURL != gamePageURL {
39- adjustFlash()
40- webView.mainFrameURL = gamePageURL
41- return
42- }
43- adjustFlash()
44- webView.reload(nil)
45- }
46- @IBAction func reloadAndRecache(sender: AnyObject?) {
47- NSURLCache.sharedURLCache().removeAllCachedResponses()
65+ @IBAction func reloadContent(_ sender: AnyObject?) {
66+ guard let _ = webView.url
67+ else {
68+ loadURLString(urlString: gamePageURL)
69+ return
70+ }
71+ // ゲームページでない場合はゲームページを表示する
72+ if let url = webView?.url, url.absoluteString != gamePageURL {
73+ loadURLString(urlString: gamePageURL)
74+ return
75+ }
76+
77+ adjustFlash()
78+
79+ webView.reload(sender)
80+
81+ }
82+ @IBAction func reloadAndRecache(_ sender: AnyObject?) {
83+ URLCache.shared.removeAllCachedResponses()
4884 reloadContent(sender)
4985 }
5086
5187 func adjustFlash() {
52- clipView.scrollToPoint(flashTopLeft)
53- }
54-
55- // MARK: - WebFrameLoadDelegate
56- func handler(c: JSContext! , e: JSValue!) {
57- println("caught exception in evaluateScript: -> \(e)")
58- }
59- func adjustIFrame(frame: WebFrame) {
60- let context = frame.javaScriptContext!
61- context.exceptionHandler = handler
62- context.evaluateScript(
63- [ "var emb = document.getElementById('flashWrap');",
64- "var rect = emb.getBoundingClientRect();",
65- "var atop = rect.top;",
66- "var aleft = rect.left;"
67- ].reduce(""){ $0 + $1 }
68- )
69- let top = context.objectForKeyedSubscript("atop")
70- let left = context.objectForKeyedSubscript("aleft")
71- let x = CGFloat(left.toDouble())
72- let y = webView.frame.size.height - CGFloat(top.toDouble()) - 480
73- flashTopLeft = NSMakePoint(x, y)
74- }
75- func adjustGameFrame(frame: WebFrame) {
76- let context = frame.javaScriptContext!
77- context.exceptionHandler = handler
78- context.evaluateScript(
79- [ "var iframe = document.getElementById('game_frame');",
80- "var validIframe = 0;",
81- "if(iframe) {",
82- " validIframe = 1;",
83- " var rect = iframe.getBoundingClientRect();",
84- " var atop = rect.top;",
85- " var aleft = rect.left;",
86- "}"
87- ].reduce(""){ $0 + $1 }
88- )
89- if let validIframe = context.objectForKeyedSubscript("validIframe")?.toInt32() {
90- if validIframe == 0 { return }
91-
92- let top = context.objectForKeyedSubscript("atop")
93- let left = context.objectForKeyedSubscript("aleft")
94- let x = flashTopLeft.x + CGFloat(left.toDouble())
95- let y = flashTopLeft.y - CGFloat(top.toDouble())
96- flashTopLeft = NSMakePoint(x, y)
97- adjustFlash()
98- }
99- }
100- override func webView(sender: WebView!, didFinishLoadForFrame frame: WebFrame!) {
101- if let path = frame.dataSource?.initialRequest.URL?.path {
102- if path.hasSuffix("gadgets/ifr") {
103- adjustIFrame(frame)
104- }
105-
106- if path.hasSuffix("app_id=854854") {
107- adjustGameFrame(frame)
108- }
109- }
88+ clipView.scroll(to: flashTopLeft)
11089 }
11190
11291 // MARK: - WebUIDelegate
@@ -119,12 +98,64 @@ class KCBFOMainWindowController: NSWindowController {
11998 WebMenuItemTagStop,
12099 WebMenuItemTagReload]
121100
122- override func webView(sender: WebView!, contextMenuItemsForElement element: [NSObject : AnyObject]!, defaultMenuItems: [AnyObject]!) -> [AnyObject]! {
101+ func webView(_ sender: WebView!, contextMenuItemsForElement element: [AnyHashable: Any]!, defaultMenuItems: [AnyObject]!) -> [Any]! {
123102 return defaultMenuItems.flatMap() {
124- if contains(ignoreTags, $0.tag()) {
103+ if ignoreTags.contains($0.tag) {
125104 return []
126105 }
127106 return [$0]
128107 }
129108 }
130109 }
110+
111+extension KCBFOMainWindowController: WKNavigationDelegate {
112+ func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
113+
114+ webView.evaluateJavaScript(
115+ ["var iframe = document.getElementById('game_frame');",
116+ "var validIframe = 0;",
117+ "var atop = 0;",
118+ "var aleft = 0;",
119+ "var aWidth = 0;",
120+ "if(iframe) {",
121+ " validIframe = 1;",
122+ " var rect = iframe.getBoundingClientRect();",
123+ " atop = rect.top;",
124+ " aleft = rect.left;",
125+ " aWidth = rect.width;",
126+ "}",
127+ "var dict = {valid:validIframe, top:atop, left:aleft, width:aWidth};",
128+ "dict;"]
129+ .reduce("", +)
130+ ) { (dict, error) in
131+ error.map { print($0) }
132+
133+ guard let param = dict as? [String: Any] else {
134+
135+ print("can not get dict")
136+ return
137+ }
138+ guard let valid = param["valid"] as? Int else {
139+
140+ print("can not get invalid")
141+ return
142+ }
143+ guard valid == 1 else {
144+
145+ return
146+ }
147+ guard let top = param["top"] as? Int,
148+ let left = param["left"] as? Int,
149+ let width = param["width"] as? Int
150+ else { return }
151+
152+ DispatchQueue.main.async { [weak self] in
153+ guard let `self` = self else { return }
154+
155+ self.flashTopLeft = NSPoint(x: CGFloat(left + (width - 800) / 2),
156+ y: CGFloat(top + 16))
157+ self.adjustFlash()
158+ }
159+ }
160+ }
161+}
--- a/KanColleBrowserForOSX/ja.lproj/KCBFOMainWindowController.xib
+++ b/KanColleBrowserForOSX/ja.lproj/KCBFOMainWindowController.xib
@@ -1,14 +1,14 @@
1-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
1+<?xml version="1.0" encoding="UTF-8"?>
2+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
33 <dependencies>
4- <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
5- <plugIn identifier="com.apple.WebKitIBPlugin" version="7706"/>
4+ <deployment identifier="macosx"/>
5+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
6+ <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
67 </dependencies>
78 <objects>
89 <customObject id="-2" userLabel="File's Owner" customClass="KCBFOMainWindowController" customModule="KanColleBrowserForOSX" customModuleProvider="target">
910 <connections>
1011 <outlet property="clipView" destination="CE2-tS-wOP" id="e59-4N-ABH"/>
11- <outlet property="webView" destination="9oP-vl-4d9" id="S8P-5p-uZ0"/>
1212 <outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
1313 </connections>
1414 </customObject>
@@ -20,7 +20,7 @@
2020 <rect key="contentRect" x="196" y="240" width="800" height="480"/>
2121 <rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
2222 <view key="contentView" id="se5-gp-TjO">
23- <rect key="frame" x="0.0" y="6" width="800" height="480"/>
23+ <rect key="frame" x="0.0" y="0.0" width="800" height="480"/>
2424 <autoresizingMask key="autoresizingMask"/>
2525 <subviews>
2626 <customView id="CE2-tS-wOP" customClass="NSClipView">
@@ -34,15 +34,5 @@
3434 </connections>
3535 <point key="canvasLocation" x="422" y="234"/>
3636 </window>
37- <webView id="9oP-vl-4d9">
38- <rect key="frame" x="0.0" y="0.0" width="6000" height="700"/>
39- <autoresizingMask key="autoresizingMask"/>
40- <webPreferences key="preferences" defaultFontSize="12" defaultFixedFontSize="12"/>
41- <connections>
42- <outlet property="UIDelegate" destination="-2" id="vms-hm-oFJ"/>
43- <outlet property="frameLoadDelegate" destination="-2" id="Qaq-jw-LUu"/>
44- </connections>
45- <point key="canvasLocation" x="199" y="1063"/>
46- </webView>
4737 </objects>
4838 </document>
--- a/KanColleBrowserForOSXTests/Info.plist
+++ b/KanColleBrowserForOSXTests/Info.plist
@@ -7,7 +7,7 @@
77 <key>CFBundleExecutable</key>
88 <string>$(EXECUTABLE_NAME)</string>
99 <key>CFBundleIdentifier</key>
10- <string>com.masakih.$(PRODUCT_NAME:rfc1034identifier)</string>
10+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1111 <key>CFBundleInfoDictionaryVersion</key>
1212 <string>6.0</string>
1313 <key>CFBundleName</key>
--- a/KanColleBrowserForOSXTests/KanColleBrowserForOSXTests.swift
+++ b/KanColleBrowserForOSXTests/KanColleBrowserForOSXTests.swift
@@ -28,7 +28,7 @@ class KanColleBrowserForOSXTests: XCTestCase {
2828
2929 func testPerformanceExample() {
3030 // This is an example of a performance test case.
31- self.measureBlock() {
31+ self.measure() {
3232 // Put the code you want to measure the time of here.
3333 }
3434 }