Skip to content

Commit

Permalink
added option to disable "check for update on wake up"
Browse files Browse the repository at this point in the history
  • Loading branch information
D0miH committed Dec 27, 2019
1 parent 41070ca commit 14a624c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
8 changes: 7 additions & 1 deletion iGlance/iGlance/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
static var userWantsCPUUtil = false
static var userWantsCPUTemp = false
static var userWantsAutostart = false
static var userWantsCheckForUpdateOnWake = true
static var cpuColor = NSColor.green
static var cpuColor2 = NSColor.red
static var cpuUsageVisualization = VisualizationType.Bar
Expand Down Expand Up @@ -192,7 +193,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {

@objc func wakeUpListener(note: NSNotification)
{
checkForUpdate()
if UserSettings.userWantsCheckForUpdateOnWake {
checkForUpdate()
}
}

func matches(for regex: String, in text: String) -> [String] {
Expand Down Expand Up @@ -334,6 +337,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
if UserDefaults.standard.value(forKey: "userWantsAutostart") != nil {
UserSettings.userWantsAutostart = UserDefaults.standard.value(forKey: "userWantsAutostart") as! Bool
}
if UserDefaults.standard.value(forKey: "userWantsCheckForUpdateOnWake") != nil {
UserSettings.userWantsCheckForUpdateOnWake = UserDefaults.standard.value(forKey: "userWantsCheckForUpdateOnWake") as! Bool
}
if UserDefaults.standard.value(forKey: "updateInterval") != nil {
UserSettings.updateInterval = UserDefaults.standard.value(forKey: "updateInterval") as! Double
}
Expand Down
24 changes: 18 additions & 6 deletions iGlance/iGlance/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15505"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15702"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -874,15 +874,15 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="som-k2-a7S"/>
</imageView>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6Os-fs-yO4">
<rect key="frame" x="18" y="106" width="183" height="28"/>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="EaO-dI-zsX">
<rect key="frame" x="17" y="94" width="235" height="28"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Autostart on Boot" bezelStyle="regularSquare" imagePosition="left" inset="2" id="ANI-7M-y7r">
<buttonCell key="cell" type="check" title="Check for updates when waking up" bezelStyle="regularSquare" imagePosition="left" inset="2" id="qmn-jk-q1l">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="cbAutostart_clicked:" target="LmA-Zk-Axh" id="k94-mw-sEN"/>
<action selector="cbCheckForUpdatesOnWake_clicked:" target="LmA-Zk-Axh" id="SwX-Hy-Lmx"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="k3z-0j-Nsz">
Expand Down Expand Up @@ -928,11 +928,23 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="T9P-eV-wfG"/>
</imageView>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6Os-fs-yO4">
<rect key="frame" x="17" y="124" width="183" height="28"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Autostart on Boot" bezelStyle="regularSquare" imagePosition="left" inset="2" id="ANI-7M-y7r">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="cbAutostart_clicked:" target="LmA-Zk-Axh" id="k94-mw-sEN"/>
</connections>
</button>
</subviews>
</view>
<connections>
<outlet property="btnCheckUpdate" destination="d11-es-ZyP" id="MfG-9t-qOK"/>
<outlet property="cbAutostart" destination="6Os-fs-yO4" id="RVC-xw-FKl"/>
<outlet property="cbCheckForUpdatesOnWake" destination="EaO-dI-zsX" id="YRb-0l-8oJ"/>
<outlet property="ddUpdateInterval" destination="jWj-II-jS5" id="7GB-eF-8Ii"/>
<outlet property="imgLogo" destination="65M-BJ-jj2" id="qMX-hC-ghl"/>
</connections>
Expand Down
24 changes: 24 additions & 0 deletions iGlance/iGlance/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ class ViewController: NSViewController {
}
}
}

@IBOutlet var cbCheckForUpdatesOnWake: NSButton! {
didSet {
cbCheckForUpdatesOnWake.state = (AppDelegate.UserSettings.userWantsCheckForUpdateOnWake) ? NSButton.StateValue.on : NSButton.StateValue.off
}
}

@IBAction func cbCheckForUpdatesOnWake_clicked(_ sender: Any) {
AppDelegate.UserSettings.userWantsCheckForUpdateOnWake = (cbCheckForUpdatesOnWake.state == NSButton.StateValue.on)
if cbCheckForUpdatesOnWake.state == NSButton.StateValue.on {
if !SMLoginItemSetEnabled(NCConstants.launcherApplicationIdentifier as CFString, true) {
_ = AppDelegate.dialogOK(question: "Error", text: "Something went wrong, sorry")
cbCheckForUpdatesOnWake.state = NSButton.StateValue.off
} else {
UserDefaults.standard.set(true, forKey: "userWantsCheckForUpdateOnWake")
}
} else {
if !SMLoginItemSetEnabled(NCConstants.launcherApplicationIdentifier as CFString, false) {
_ = AppDelegate.dialogOK(question: "Error", text: "Something went wrong, sorry")
} else {
UserDefaults.standard.set(false, forKey: "userWantsCheckForUpdateOnWake")
}
}
}

// define the outlet to the logo
@IBOutlet var imgLogo: NSImageView! {
Expand Down

0 comments on commit 14a624c

Please sign in to comment.