Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from mribeiro/feature/option_to_hide_dock_icon
Browse files Browse the repository at this point in the history
Added possibility to hide dock icon.
  • Loading branch information
mribeiro committed Apr 11, 2020
2 parents 2cd04a7 + cfcad23 commit 193abc6
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 7 deletions.
18 changes: 18 additions & 0 deletions Timetracker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
A947677E6E5D59CD5BAA648E /* Pods_TimetrackerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E72C3BE4F172AA9F004B0C77 /* Pods_TimetrackerTests.framework */; };
E612F3411CD2293800FC1D85 /* TaskPingReceiver.swift in Sources */ = {isa = PBXBuildFile; fileRef = E612F3401CD2293800FC1D85 /* TaskPingReceiver.swift */; };
E6281D2524420F4900CD467C /* AppDelegate+NSMenuDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6281D2424420F4900CD467C /* AppDelegate+NSMenuDelegate.swift */; };
E6281D2824421A4900CD467C /* PreferenceMiscViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6281D2724421A4900CD467C /* PreferenceMiscViewController.swift */; };
E6281D2B24421C1D00CD467C /* PreferenceMiscView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E6281D2A24421C1D00CD467C /* PreferenceMiscView.xib */; };
E6281D2D24422BD200CD467C /* DockIconManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6281D2C24422BD200CD467C /* DockIconManager.swift */; };
E65ED058223DAF23004C22C9 /* PreferenceBuilderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E65ED057223DAF23004C22C9 /* PreferenceBuilderViewController.swift */; };
E65EF088224E85F50023A7B5 /* LogManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = E65EF087224E85F50023A7B5 /* LogManager.swift */; };
E662723B1CD8E84300B50E38 /* TabSeparatedValuesExporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E662723A1CD8E84300B50E38 /* TabSeparatedValuesExporter.swift */; };
Expand Down Expand Up @@ -66,6 +69,9 @@
DE08661C18BDE41076AA0836 /* Pods-TimetrackerTests.debug prod.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TimetrackerTests.debug prod.xcconfig"; path = "Target Support Files/Pods-TimetrackerTests/Pods-TimetrackerTests.debug prod.xcconfig"; sourceTree = "<group>"; };
E612F3401CD2293800FC1D85 /* TaskPingReceiver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskPingReceiver.swift; sourceTree = "<group>"; };
E6281D2424420F4900CD467C /* AppDelegate+NSMenuDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+NSMenuDelegate.swift"; sourceTree = "<group>"; };
E6281D2724421A4900CD467C /* PreferenceMiscViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferenceMiscViewController.swift; sourceTree = "<group>"; };
E6281D2A24421C1D00CD467C /* PreferenceMiscView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PreferenceMiscView.xib; sourceTree = "<group>"; };
E6281D2C24422BD200CD467C /* DockIconManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DockIconManager.swift; sourceTree = "<group>"; };
E65ED057223DAF23004C22C9 /* PreferenceBuilderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferenceBuilderViewController.swift; sourceTree = "<group>"; };
E65EF087224E85F50023A7B5 /* LogManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogManager.swift; sourceTree = "<group>"; };
E662723A1CD8E84300B50E38 /* TabSeparatedValuesExporter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TabSeparatedValuesExporter.swift; path = Exporters/TabSeparatedValuesExporter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -199,13 +205,15 @@
E6910F461CCE5CFF003CBA90 /* Main.storyboard */,
E6D964CD223DB4AC00B1C534 /* PreferenceBuilderView.xib */,
E6F788D422579BA000AE3DF3 /* PreferenceLogView.xib */,
E6281D2A24421C1D00CD467C /* PreferenceMiscView.xib */,
E6910F491CCE5CFF003CBA90 /* Info.plist */,
E6910F411CCE5CFF003CBA90 /* Timetracker.xcdatamodeld */,
E6E1B4501CD899C300FE24CD /* Builder.swift */,
E6E1B4521CD899EA00FE24CD /* JackTheMonkey.swift */,
E6E1B4541CD89CE900FE24CD /* MoonPhases.swift */,
E6FE83971CDB6D8300794723 /* ErrorView.xib */,
E6D964CF223E795200B1C534 /* BuilderManager.swift */,
E6281D2C24422BD200CD467C /* DockIconManager.swift */,
);
path = Timetracker;
sourceTree = "<group>";
Expand Down Expand Up @@ -253,6 +261,7 @@
E6FE83951CDB6AF300794723 /* ErrorViewController.swift */,
E65ED057223DAF23004C22C9 /* PreferenceBuilderViewController.swift */,
E6F788D622579BBB00AE3DF3 /* PreferenceLogViewController.swift */,
E6281D2724421A4900CD467C /* PreferenceMiscViewController.swift */,
);
name = ViewControllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -377,6 +386,7 @@
E6910F451CCE5CFF003CBA90 /* Assets.xcassets in Resources */,
E6910F481CCE5CFF003CBA90 /* Main.storyboard in Resources */,
E6F788D522579BA000AE3DF3 /* PreferenceLogView.xib in Resources */,
E6281D2B24421C1D00CD467C /* PreferenceMiscView.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -472,7 +482,9 @@
E6910F5E1CCE65B5003CBA90 /* CoreDataTaskProvider.swift in Sources */,
E6D680651CD5018F00C45179 /* TaskListViewController.swift in Sources */,
E6D964D0223E795200B1C534 /* BuilderManager.swift in Sources */,
E6281D2824421A4900CD467C /* PreferenceMiscViewController.swift in Sources */,
E6FE83941CDB5D5F00794723 /* NSDate+Utils.swift in Sources */,
E6281D2D24422BD200CD467C /* DockIconManager.swift in Sources */,
E6F788D722579BBB00AE3DF3 /* PreferenceLogViewController.swift in Sources */,
E6FE83901CDB34C900794723 /* TaskRunnerWindowController.swift in Sources */,
E6910F681CCE6F1E003CBA90 /* Client.swift in Sources */,
Expand Down Expand Up @@ -640,13 +652,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5;
DB_NAME = DEV;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
IDLE_SECONDS = 3;
INFOPLIST_FILE = Timetracker/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.5;
PRODUCT_BUNDLE_IDENTIFIER = org.aribeiro.Timetracker;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -662,13 +676,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5;
DB_NAME = release;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
IDLE_SECONDS = 300;
INFOPLIST_FILE = Timetracker/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.5;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.aribeiro.Timetracker;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -771,13 +787,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5;
DB_NAME = PRD;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
IDLE_SECONDS = 300;
INFOPLIST_FILE = Timetracker/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.5;
PRODUCT_BUNDLE_IDENTIFIER = org.aribeiro.Timetracker;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
4 changes: 3 additions & 1 deletion Timetracker/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, TaskPingReceiver, NSUserNoti
let preferencesWindowController = PreferencesWindowController(
viewControllers: [
PreferenceBuilderViewController(),
PreferenceLogViewController()
PreferenceLogViewController(),
PreferenceMiscViewController()
]
)

Expand All @@ -50,6 +51,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, TaskPingReceiver, NSUserNoti
NSUserNotificationCenter.default.removeScheduledNotification($0)
}
self.scheduleNotification(appJustOpened: true)
DockIconManager.setIconPerConfiguration()

}

Expand Down
34 changes: 34 additions & 0 deletions Timetracker/DockIconManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// DockerIconManager.swift
// Timetracker
//
// Created by Antonio Ribeiro on 11/04/2020.
// Copyright © 2020 Antonio Ribeiro. All rights reserved.
//

import Foundation
import Cocoa

class DockIconManager {

class func shouldHideIcon() -> Bool {
return UserDefaults().bool(forKey: "hide_dock_icon")
}

class func set(hideIcon: Bool) {
UserDefaults().set(hideIcon, forKey: "hide_dock_icon")
let policy: NSApplication.ActivationPolicy = hideIcon ? .accessory : .regular
NSApplication.shared.setActivationPolicy(policy)
}

class func setIconPerConfiguration() {
let hideIcon = shouldHideIcon()
iconHidden(hideIcon)
}

private class func iconHidden(_ hideIcon: Bool) {
let policy: NSApplication.ActivationPolicy = hideIcon ? .accessory : .regular
NSApplication.shared.setActivationPolicy(policy)
}

}
12 changes: 6 additions & 6 deletions Timetracker/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDLE_SECONDS</key>
<string>${IDLE_SECONDS}</string>
<key>DB_NAME</key>
<string>${DB_NAME}</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -21,11 +17,15 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>DB_NAME</key>
<string>${DB_NAME}</string>
<key>IDLE_SECONDS</key>
<string>${IDLE_SECONDS}</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
35 changes: 35 additions & 0 deletions Timetracker/PreferenceMiscView.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16096" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16096"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="PreferenceMiscViewController" customModule="Timetracker" customModuleProvider="target">
<connections>
<outlet property="checkboxHideDockIcon" destination="FIw-kP-UfD" id="DU9-Hl-0tY"/>
<outlet property="view" destination="c22-O7-iKe" id="FVV-sG-ed5"/>
</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="480" height="272"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="FIw-kP-UfD">
<rect key="frame" x="18" y="236" width="113" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Hide dock icon" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="30b-cz-svK">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="hideDockIconChanged:" target="-2" id="4Zh-Ka-NXK"/>
</connections>
</button>
</subviews>
<point key="canvasLocation" x="124" y="154"/>
</customView>
</objects>
</document>
35 changes: 35 additions & 0 deletions Timetracker/PreferenceMiscViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// PreferenceMiscViewController.swift
// Timetracker
//
// Created by Antonio Ribeiro on 11/04/2020.
// Copyright © 2020 Antonio Ribeiro. All rights reserved.
//

import Foundation
import AppKit
import Preferences

class PreferenceMiscViewController: NSViewController, Preferenceable {
@IBOutlet weak var checkboxHideDockIcon: NSButton!

var toolbarItemTitle: String = "Misc"

var toolbarItemIcon: NSImage = NSImage(named: "log")!

override var nibName: NSNib.Name? {
return "PreferenceMiscView"
}

override func viewWillAppear() {
self.checkboxHideDockIcon.state = DockIconManager.shouldHideIcon() ? .on : .off
}

@IBAction func hideDockIconChanged(_ sender: NSButtonCell) {
DockIconManager.set(hideIcon: sender.state == .on)
}




}

0 comments on commit 193abc6

Please sign in to comment.