-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#15 Add Safari extension and ReaderTranslatorForMac project target.
- Loading branch information
Showing
32 changed files
with
1,783 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// AppDelegate.swift | ||
// ReaderTranlatorMac | ||
// | ||
// Created by Viktor Kushnerov on 9/30/19. | ||
// Copyright © 2019 Viktor Kushnerov. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
import SwiftUI | ||
|
||
@NSApplicationMain | ||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
|
||
var window: NSWindow! | ||
|
||
|
||
func applicationDidFinishLaunching(_ aNotification: Notification) { | ||
// Create the SwiftUI view that provides the window contents. | ||
let contentView = ContentView().environmentObject(Store.shared) | ||
|
||
|
||
// Create the window and set the content view. | ||
window = NSWindow( | ||
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300), | ||
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView], | ||
backing: .buffered, defer: false) | ||
window.center() | ||
window.setFrameAutosaveName("Main Window") | ||
window.contentView = NSHostingView(rootView: contentView) | ||
window.makeKeyAndOrderFront(nil) | ||
} | ||
|
||
func applicationWillTerminate(_ aNotification: Notification) { | ||
// Insert code here to tear down your application | ||
} | ||
|
||
|
||
} | ||
|
58 changes: 58 additions & 0 deletions
58
ReaderTranlatorMac/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "mac", | ||
"size" : "16x16", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "16x16", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "32x32", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "32x32", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "128x128", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "128x128", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "256x256", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "256x256", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "512x512", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "512x512", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIconFile</key> | ||
<string></string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSMinimumSystemVersion</key> | ||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string> | ||
<key>NSHumanReadableCopyright</key> | ||
<string>Copyright © 2019 Viktor Kushnerov. All rights reserved.</string> | ||
<key>NSMainStoryboardFile</key> | ||
<string>Main</string> | ||
<key>NSPrincipalClass</key> | ||
<string>NSApplication</string> | ||
<key>NSSupportsAutomaticTermination</key> | ||
<true/> | ||
<key>NSSupportsSuddenTermination</key> | ||
<true/> | ||
</dict> | ||
</plist> |
6 changes: 6 additions & 0 deletions
6
ReaderTranlatorMac/Preview Content/Preview Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.app-sandbox</key> | ||
<true/> | ||
<key>com.apple.security.files.user-selected.read-only</key> | ||
<true/> | ||
</dict> | ||
</plist> |
30 changes: 30 additions & 0 deletions
30
ReaderTranlatorSafari/Base.lproj/SafariExtensionViewController.xib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11134" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11134"/> | ||
</dependencies> | ||
<objects> | ||
<customObject id="-2" userLabel="File's Owner" customClass="SafariExtensionViewController" customModuleProvider="target"> | ||
<connections> | ||
<outlet property="view" destination="c22-O7-iKe" id="vwT-Xx-Aiz"/> | ||
</connections> | ||
</customObject> | ||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> | ||
<customObject id="-3" userLabel="Application" customClass="NSObject"/> | ||
<customView id="c22-O7-iKe"> | ||
<rect key="frame" x="0.0" y="0.0" width="330" height="119"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> | ||
<subviews> | ||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4Iy-aV-wGF"> | ||
<rect key="frame" x="103" y="82" width="124" height="17"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> | ||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="ReaderTranlatorSafari" id="2Ec-kd-q2K"> | ||
<font key="font" metaFont="system"/> | ||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> | ||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> | ||
</textFieldCell> | ||
</textField> | ||
</subviews> | ||
</customView> | ||
</objects> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleDisplayName</key> | ||
<string>ReaderTranlatorSafari</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSMinimumSystemVersion</key> | ||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.Safari.extension</string> | ||
<key>NSExtensionPrincipalClass</key> | ||
<string>$(PRODUCT_MODULE_NAME).SafariExtensionHandler</string> | ||
<key>SFSafariContentScript</key> | ||
<array> | ||
<dict> | ||
<key>Script</key> | ||
<string>script.js</string> | ||
</dict> | ||
</array> | ||
<key>SFSafariToolbarItem</key> | ||
<dict> | ||
<key>Action</key> | ||
<string>Command</string> | ||
<key>Identifier</key> | ||
<string>Button</string> | ||
<key>Image</key> | ||
<string>ToolbarItemIcon.pdf</string> | ||
<key>Label</key> | ||
<string>Your Button</string> | ||
</dict> | ||
<key>SFSafariWebsiteAccess</key> | ||
<dict> | ||
<key>Allowed Domains</key> | ||
<array> | ||
<string>*.webkit.org</string> | ||
</array> | ||
<key>Level</key> | ||
<string>Some</string> | ||
</dict> | ||
</dict> | ||
<key>NSHumanReadableCopyright</key> | ||
<string>Copyright © 2019 Viktor Kushnerov. All rights reserved.</string> | ||
<key>NSHumanReadableDescription</key> | ||
<string>This is a Safari Extension. You should tell us what your extension does here.</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.app-sandbox</key> | ||
<true/> | ||
<key>com.apple.security.files.user-selected.read-only</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// SafariExtensionHandler.swift | ||
// ReaderTranlatorSafari | ||
// | ||
// Created by Viktor Kushnerov on 9/30/19. | ||
// Copyright © 2019 Viktor Kushnerov. All rights reserved. | ||
// | ||
|
||
import SafariServices | ||
|
||
class SafariExtensionHandler: SFSafariExtensionHandler { | ||
|
||
override func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String : Any]?) { | ||
// This method will be called when a content script provided by your extension calls safari.extension.dispatchMessage("message"). | ||
page.getPropertiesWithCompletionHandler { properties in | ||
NSLog("The extension received a message (\(messageName)) from a script injected into (\(String(describing: properties?.url))) with userInfo (\(userInfo ?? [:]))") | ||
} | ||
} | ||
|
||
override func toolbarItemClicked(in window: SFSafariWindow) { | ||
// This method will be called when your toolbar item is clicked. | ||
NSLog("The extension's toolbar item was clicked") | ||
} | ||
|
||
override func validateToolbarItem(in window: SFSafariWindow, validationHandler: @escaping ((Bool, String) -> Void)) { | ||
// This is called when Safari's state changed in some way that would require the extension's toolbar item to be validated again. | ||
validationHandler(true, "") | ||
} | ||
|
||
override func popoverViewController() -> SFSafariExtensionViewController { | ||
return SafariExtensionViewController.shared | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// SafariExtensionViewController.swift | ||
// ReaderTranlatorSafari | ||
// | ||
// Created by Viktor Kushnerov on 9/30/19. | ||
// Copyright © 2019 Viktor Kushnerov. All rights reserved. | ||
// | ||
|
||
import SafariServices | ||
|
||
class SafariExtensionViewController: SFSafariExtensionViewController { | ||
|
||
static let shared: SafariExtensionViewController = { | ||
let shared = SafariExtensionViewController() | ||
shared.preferredContentSize = NSSize(width:320, height:240) | ||
return shared | ||
}() | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
document.addEventListener("DOMContentLoaded", function(event) { | ||
safari.extension.dispatchMessage("Hello World!"); | ||
}); |
Oops, something went wrong.