Skip to content

Commit

Permalink
Merge pull request #5 from qwertyyb/feat/hotkey
Browse files Browse the repository at this point in the history
fix: check permission at launch;refactor code
  • Loading branch information
qwertyyb authored Oct 18, 2019
2 parents 85e82b3 + e9d64ea commit 8fa6f05
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 193 deletions.
22 changes: 18 additions & 4 deletions YPaste.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
4563DE7923255739003F2767 /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4563DE7823255739003F2767 /* PreferencesViewController.swift */; };
4596AE48232025A700F63EBF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4596AE47232025A700F63EBF /* AppDelegate.swift */; };
4596AE4A232025A700F63EBF /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4596AE49232025A700F63EBF /* ViewController.swift */; };
4596AE4D232025A700F63EBF /* YPaste.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 4596AE4B232025A700F63EBF /* YPaste.xcdatamodeld */; };
Expand All @@ -17,6 +16,8 @@
4596AE6923216E6C00F63EBF /* YPasteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4596AE6823216E6C00F63EBF /* YPasteTests.swift */; };
4596AE712322B5CB00F63EBF /* MainWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4596AE702322B5CB00F63EBF /* MainWindowController.swift */; };
4596AE732323CF5800F63EBF /* SummaryTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4596AE722323CF5800F63EBF /* SummaryTransformer.swift */; };
67136E302359E04F00EFB448 /* Preferences.xib in Resources */ = {isa = PBXBuildFile; fileRef = 67136E322359E04F00EFB448 /* Preferences.xib */; };
67C3262C2359D86300248CDE /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67C3262B2359D86300248CDE /* PreferencesWindowController.swift */; };
67CFA4872351F4FB0058CF29 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 67CFA4862351F4FB0058CF29 /* README.md */; };
67F313B32355E819008BAEB7 /* Key.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67F313B22355E819008BAEB7 /* Key.swift */; };
89E4606D59274DC83FCCFEB8 /* libPods-YPasteTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FB920036F40D7A752C57AFCF /* libPods-YPasteTests.a */; };
Expand All @@ -34,7 +35,6 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
4563DE7823255739003F2767 /* PreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewController.swift; sourceTree = "<group>"; };
4596AE44232025A700F63EBF /* YPaste.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = YPaste.app; sourceTree = BUILT_PRODUCTS_DIR; };
4596AE47232025A700F63EBF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
4596AE49232025A700F63EBF /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand All @@ -50,6 +50,9 @@
4596AE702322B5CB00F63EBF /* MainWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainWindowController.swift; sourceTree = "<group>"; };
4596AE722323CF5800F63EBF /* SummaryTransformer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SummaryTransformer.swift; sourceTree = "<group>"; };
5798607827522D99BA309E4B /* libPods-YPaste.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-YPaste.a"; sourceTree = BUILT_PRODUCTS_DIR; };
67136E332359E05E00EFB448 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/Preferences.xib; sourceTree = "<group>"; };
67136E372359E66C00EFB448 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Preferences.strings"; sourceTree = "<group>"; };
67C3262B2359D86300248CDE /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
67CFA4862351F4FB0058CF29 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
67F313B22355E819008BAEB7 /* Key.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Key.swift; sourceTree = "<group>"; };
67F313B62355F66B008BAEB7 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -119,14 +122,15 @@
4596AE49232025A700F63EBF /* ViewController.swift */,
4596AE4E232025A800F63EBF /* Assets.xcassets */,
4596AE50232025A800F63EBF /* Main.storyboard */,
4563DE7823255739003F2767 /* PreferencesViewController.swift */,
4596AE6023216A8500F63EBF /* YPaste.swift */,
4596AE53232025A800F63EBF /* Info.plist */,
4596AE54232025A800F63EBF /* YPaste.entitlements */,
4596AE4B232025A700F63EBF /* YPaste.xcdatamodeld */,
4596AE702322B5CB00F63EBF /* MainWindowController.swift */,
4596AE722323CF5800F63EBF /* SummaryTransformer.swift */,
67F313B22355E819008BAEB7 /* Key.swift */,
67136E322359E04F00EFB448 /* Preferences.xib */,
67C3262B2359D86300248CDE /* PreferencesWindowController.swift */,
);
path = YPaste;
sourceTree = "<group>";
Expand Down Expand Up @@ -244,6 +248,7 @@
files = (
67CFA4872351F4FB0058CF29 /* README.md in Resources */,
4596AE4F232025A800F63EBF /* Assets.xcassets in Resources */,
67136E302359E04F00EFB448 /* Preferences.xib in Resources */,
4596AE52232025A800F63EBF /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -349,7 +354,7 @@
4596AE4A232025A700F63EBF /* ViewController.swift in Sources */,
4596AE48232025A700F63EBF /* AppDelegate.swift in Sources */,
67F313B32355E819008BAEB7 /* Key.swift in Sources */,
4563DE7923255739003F2767 /* PreferencesViewController.swift in Sources */,
67C3262C2359D86300248CDE /* PreferencesWindowController.swift in Sources */,
4596AE712322B5CB00F63EBF /* MainWindowController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -382,6 +387,15 @@
name = Main.storyboard;
sourceTree = "<group>";
};
67136E322359E04F00EFB448 /* Preferences.xib */ = {
isa = PBXVariantGroup;
children = (
67136E332359E05E00EFB448 /* Base */,
67136E372359E66C00EFB448 /* zh-Hans */,
);
name = Preferences.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
Expand Down
12 changes: 7 additions & 5 deletions YPaste/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var app: YPaste = YPaste.shared

private var statusItem :NSStatusItem? = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
private var preferencesWindowController: NSWindowController?
private var preferencesWindowController = PreferencesWindowController.init(windowNibName: "Preferences")

@IBOutlet weak var menu: NSMenu!
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
statusItem?.button!.image = NSImage(named: "statusImage")
statusItem?.menu = menu

// check permission
let _ = app.checkAccess(prompt: true)

if UserDefaults.standard.bool(forKey: "launchAtLogin") {
app.autoLaunch(active: true)
}
Expand Down Expand Up @@ -66,9 +68,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}()

@IBAction func openPreferences(_ sender: AnyObject?) {
preferencesWindowController?.window?.orderFront(self)
preferencesWindowController?.window?.level = .popUpMenu
preferencesWindowController?.showWindow(self)
// preferencesWindowController.window.orderFront(self)
// preferencesWindowController.window.level = .popUpMenu
preferencesWindowController.showWindow(self)
}

// MARK: - Core Data Saving and Undo support
Expand Down
136 changes: 1 addition & 135 deletions YPaste/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</menuItem>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW">
<connections>
<segue destination="lIT-Ak-tl4" kind="modal" id="Vse-Qt-XsM"/>
<action selector="openPreferences:" target="Voe-Tx-rLC" id="EMF-mG-p7S"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
Expand Down Expand Up @@ -247,139 +247,5 @@
</objects>
<point key="canvasLocation" x="75" y="655"/>
</scene>
<!--Preferences Window Controller-->
<scene sceneID="sGg-qc-9Jt">
<objects>
<windowController storyboardIdentifier="preferences" showSeguePresentationStyle="single" id="lIT-Ak-tl4" userLabel="Preferences Window Controller" sceneMemberID="viewController">
<window key="window" identifier="preferencesWindow" title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" frameAutosaveName="" animationBehavior="default" id="J2L-Gm-BGd" userLabel="Preferences Window">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
</window>
<connections>
<segue destination="YFo-Sr-FRU" kind="relationship" relationship="window.shadowedContentViewController" id="Vgk-7H-9pl"/>
</connections>
</windowController>
<customObject id="GQK-bi-Ugo" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="752" y="213"/>
</scene>
<!--Preferences View Controller-->
<scene sceneID="lqm-pK-AsM">
<objects>
<viewController showSeguePresentationStyle="single" id="YFo-Sr-FRU" customClass="PreferencesViewController" customModule="YPaste" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="nhs-Po-xVi">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UVR-Lh-n2s">
<rect key="frame" x="18" y="218" width="119" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Launch at Login" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="XeA-Pa-vo1">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="onLaunchAtLogin:" target="YFo-Sr-FRU" id="mAT-By-FHt"/>
<binding destination="1Q6-QO-rfX" name="value" keyPath="values.launchAtLogin" id="xoO-Su-4L3"/>
</connections>
</button>
<stackView distribution="fill" orientation="horizontal" alignment="centerY" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" fixedFrame="YES" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1cJ-rR-LRM">
<rect key="frame" x="20" y="176" width="177" height="21"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Wdr-bN-S12" userLabel="Check Update">
<rect key="frame" x="-2" y="3" width="91" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Check Update" id="Hek-Ub-jcx">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kdv-NE-vNJ" userLabel="UpdateInterval">
<rect key="frame" x="93" y="-3" width="87" height="25"/>
<popUpButtonCell key="cell" type="push" title="Hourly" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" tag="3600" imageScaling="proportionallyDown" inset="2" selectedItem="TEO-zW-tiz" id="f9v-oo-5xT">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="pK6-QL-Sq5">
<items>
<menuItem title="Hourly" state="on" tag="3600" id="TEO-zW-tiz">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Daily" tag="86400" id="mBE-Ru-XPc">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Weekly" tag="604800" id="2Fh-Eg-6wM">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Monthly" tag="2629800" id="7dS-7V-KhE">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Never" id="9cf-2w-uyQ">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
<connections>
<binding destination="eI7-Ej-wLI" name="selectedTag" keyPath="updateCheckInterval" id="cN5-ft-LaO"/>
</connections>
</popUpButtonCell>
</popUpButton>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<stackView distribution="fill" orientation="horizontal" alignment="centerY" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" fixedFrame="YES" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2hH-Kc-emV">
<rect key="frame" x="20" y="136" width="142" height="21"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Ahh-JM-8gO">
<rect key="frame" x="-2" y="3" width="52" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Hot Key" id="dPA-yk-8qy">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Oz9-un-gxI">
<rect key="frame" x="50" y="-7" width="98" height="32"/>
<buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" image="NSRefreshTemplate" imagePosition="trailing" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="u83-rp-fdR">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="hotKeyClicked:" target="YFo-Sr-FRU" id="D4N-vm-EQZ"/>
<binding destination="1Q6-QO-rfX" name="title" keyPath="values" id="g8A-Iy-XiD"/>
</connections>
</button>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
</subviews>
</view>
<connections>
<outlet property="hotKey" destination="Oz9-un-gxI" id="3im-uO-838"/>
</connections>
</viewController>
<customObject id="INr-k0-CY4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<userDefaultsController id="1Q6-QO-rfX" userLabel="Shared User Defaults Controller"/>
<customObject id="eI7-Ej-wLI" customClass="SUUpdater"/>
</objects>
<point key="canvasLocation" x="752" y="670"/>
</scene>
</scenes>
<resources>
<image name="NSRefreshTemplate" width="11" height="15"/>
</resources>
</document>
Loading

0 comments on commit 8fa6f05

Please sign in to comment.