UI layouting done
This commit is contained in:
+100
-6
@@ -11,16 +11,110 @@ import Cocoa
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
// MARK: - Things that have to be kept alive for the application lifetime
|
||||
// Status Item
|
||||
var statusItem: NSStatusItem = NSStatusItem()
|
||||
// URL Session for DOCSIS data and Internet check
|
||||
let urlSession: URLSession = URLSession(configuration: .default)
|
||||
// Preferences
|
||||
let pref: NSWindowController = NSWindowController(windowNibName: "SettingsWindowController")
|
||||
// Timers
|
||||
var timerFreqs: Timer = Timer()
|
||||
var timerFails: Timer = Timer()
|
||||
// Document content list
|
||||
var content: NSMutableDictionary = NSMutableDictionary()
|
||||
|
||||
|
||||
// MARK: - Application Lifecycle
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
// Insert code here to initialize your application
|
||||
// Show Preferneces if defaults are empty
|
||||
UserDefaults.standard.register(defaults: ["upstream" : "", "downstream" : ""])
|
||||
if UserDefaults.standard.string(forKey: "upstream") == nil || UserDefaults.standard.string(forKey: "downstream") == nil {
|
||||
pref.showWindow(nil)
|
||||
}
|
||||
|
||||
// Set status item
|
||||
statusItem = NSStatusBar.system().statusItem(withLength: -2)
|
||||
statusItem.title = "AL"
|
||||
// Create status item menu
|
||||
let menu: NSMenu = NSMenu.init()
|
||||
menu.autoenablesItems = false
|
||||
let menuAbout: NSMenuItem = NSMenuItem(title: "About Logger", action: #selector(NSApp.orderFrontStandardAboutPanel(_:)), keyEquivalent: "")
|
||||
let menuQuit: NSMenuItem = NSMenuItem.init(title: "Quit", action: #selector(NSApp.terminate(_:)), keyEquivalent: "q")
|
||||
let menuPref: NSMenuItem = NSMenuItem(title: "Preferences", action: #selector(self.preferences(_:)), keyEquivalent: "")
|
||||
menuPref.image = NSImage(named: NSImageNameActionTemplate)
|
||||
// Layout menu
|
||||
menu.addItem(menuAbout)
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(menuPref)
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(menuQuit)
|
||||
// Add menu
|
||||
statusItem.menu = menu
|
||||
|
||||
// Check if directory exists, creat or exit
|
||||
let fileManager = FileManager.default
|
||||
var directory: ObjCBool = ObjCBool(false)
|
||||
let exists: Bool = fileManager.fileExists(atPath: ("~/KDLog" as NSString).expandingTildeInPath, isDirectory: &directory)
|
||||
if exists && directory.boolValue {
|
||||
} else if exists {
|
||||
NSLog("FILE WITH NAME KDLog EXISTS, REMOVE IT")
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
do {
|
||||
try fileManager.createDirectory(atPath: ("~/KDLog" as NSString).expandingTildeInPath, withIntermediateDirectories: false, attributes: nil)
|
||||
}
|
||||
catch let error as NSError {
|
||||
NSLog("ERROR ON DIRECTORY CREATION: \(error.localizedDescription)")
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Init timers
|
||||
if UserDefaults.standard.string(forKey: "upstream") != nil || UserDefaults.standard.string(forKey: "downstream") != nil {
|
||||
initTimers()
|
||||
}
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ aNotification: Notification) {
|
||||
// Insert code here to tear down your application
|
||||
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplicationTerminateReply {
|
||||
urlSession.invalidateAndCancel()
|
||||
return .terminateNow
|
||||
}
|
||||
|
||||
// MARK: - Logging Functions
|
||||
|
||||
func logFreqs(_: Timer) {
|
||||
// let frequencyOperation: FrequencyOperation = FrequencyOperation()
|
||||
// OperationQueue.main.addOperation(frequencyOperation)
|
||||
}
|
||||
|
||||
func logFails(_: Timer) {
|
||||
// let connectionLossOperation: ConnectionLossOperation = ConnectionLossOperation()
|
||||
// OperationQueue.main.addOperation(connectionLossOperation)
|
||||
}
|
||||
|
||||
// MARK: - General functions
|
||||
|
||||
func preferences(_ sender: NSMenuItem) {
|
||||
timerFreqs.invalidate()
|
||||
timerFails.invalidate()
|
||||
|
||||
pref.showWindow(sender)
|
||||
pref.window?.makeKeyAndOrderFront(self)
|
||||
}
|
||||
|
||||
func initTimers() {
|
||||
timerFreqs.invalidate()
|
||||
timerFails.invalidate()
|
||||
|
||||
timerFreqs = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(logFreqs), userInfo: nil, repeats: true)
|
||||
timerFails = Timer.scheduledTimer(timeInterval: 60, target: self, selector: #selector(logFails), userInfo: nil, repeats: true)
|
||||
}
|
||||
|
||||
@IBAction func close(_ sender: NSButton){
|
||||
initTimers()
|
||||
sender.superview?.window?.close()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -15,9 +15,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<string>4.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<string>6</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>LSUIElement</key>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// SettingsWindowController.swift
|
||||
// Logger3
|
||||
//
|
||||
// Created by Kilian Hofmann on 15.08.16.
|
||||
// Copyright © 2016 Kilian Hofmann. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class SettingsWindowController: NSWindowController {
|
||||
|
||||
override func windowDidLoad() {
|
||||
super.windowDidLoad()
|
||||
|
||||
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11185.3" systemVersion="16A286a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="16G16b" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11185.3"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="SettingsWindowController" customModule="Logger3" customModuleProvider="target">
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="SettingsWindowController" customModule="Logger4" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
|
||||
</connections>
|
||||
@@ -15,14 +16,14 @@
|
||||
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="196" y="240" width="480" height="148"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/>
|
||||
<rect key="contentRect" x="196" y="240" width="480" height="123"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="800"/>
|
||||
<view key="contentView" wantsLayer="YES" id="se5-gp-TjO">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="148"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="123"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ANt-3h-Oyk">
|
||||
<rect key="frame" x="157" y="106" width="303" height="22"/>
|
||||
<textField verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ANt-3h-Oyk">
|
||||
<rect key="frame" x="157" y="81" width="303" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="ZEi-Jt-cuo">
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -33,8 +34,8 @@
|
||||
<binding destination="aHP-ZZ-xCK" name="value" keyPath="values.upstream" id="fxN-Gy-Szs"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ycn-ts-JLP">
|
||||
<rect key="frame" x="18" y="106" width="116" height="17"/>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ycn-ts-JLP">
|
||||
<rect key="frame" x="18" y="81" width="116" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Modem Upstream:" id="lAx-c4-sWO">
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -42,8 +43,8 @@
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="d4L-qo-4wS">
|
||||
<rect key="frame" x="18" y="74" width="133" height="17"/>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="d4L-qo-4wS">
|
||||
<rect key="frame" x="18" y="49" width="133" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Modem Downstream:" id="oeh-xU-Gg6">
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -51,8 +52,8 @@
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9gP-wv-Svk">
|
||||
<rect key="frame" x="157" y="74" width="303" height="22"/>
|
||||
<textField verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9gP-wv-Svk">
|
||||
<rect key="frame" x="157" y="49" width="303" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="rGM-TE-sjl">
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -63,40 +64,8 @@
|
||||
<binding destination="aHP-ZZ-xCK" name="value" keyPath="values.downstream" id="9uX-kn-Xc2"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="QL3-SH-xov">
|
||||
<rect key="frame" x="18" y="42" width="34" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Port:" id="olU-sy-AtO">
|
||||
<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>
|
||||
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="x6I-cX-Bo8">
|
||||
<rect key="frame" x="157" y="42" width="49" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="crU-qU-FJL">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<binding destination="aHP-ZZ-xCK" name="value" keyPath="values.port" id="RKt-4G-WHW"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9I9-2a-L2r">
|
||||
<rect key="frame" x="18" y="18" width="122" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Autostart Server" bezelStyle="regularSquare" imagePosition="left" inset="2" id="r84-bO-IHn">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<binding destination="aHP-ZZ-xCK" name="value" keyPath="values.autostart" id="bbv-6s-vsL"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vGB-sa-cDA">
|
||||
<rect key="frame" x="397" y="13" width="57" height="32"/>
|
||||
<rect key="frame" x="409" y="13" width="57" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="push" title="Ok" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="cDR-9m-MtM">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
@@ -106,23 +75,14 @@
|
||||
<action selector="close:" target="Lb6-Mc-rfv" id="Asm-ec-kwu"/>
|
||||
</connections>
|
||||
</button>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="YLU-XV-sDy">
|
||||
<rect key="frame" x="214" y="42" width="144" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Requires Server restart" id="EYY-im-3b0">
|
||||
<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>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="139" y="100"/>
|
||||
<point key="canvasLocation" x="139" y="87.5"/>
|
||||
</window>
|
||||
<customObject id="Lb6-Mc-rfv" customClass="AppDelegate" customModule="Logger3" customModuleProvider="target"/>
|
||||
<customObject id="Lb6-Mc-rfv" customClass="AppDelegate" customModule="Logger4" customModuleProvider="target"/>
|
||||
<userDefaultsController representsSharedInstance="YES" id="aHP-ZZ-xCK"/>
|
||||
</objects>
|
||||
</document>
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
//
|
||||
// ViewController.swift
|
||||
// Logger4
|
||||
//
|
||||
// Created by Kilian Hofmann on 15.06.17.
|
||||
// Copyright © 2017 Kilian Hofmann. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class ViewController: NSViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
}
|
||||
|
||||
override var representedObject: Any? {
|
||||
didSet {
|
||||
// Update the view, if already loaded.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
version 4.0
|
||||
build 1
|
||||
build 6
|
||||
|
||||
Reference in New Issue
Block a user