Skip to content

Commit

Permalink
#12 (widget)
Browse files Browse the repository at this point in the history
- Adding Turn Touch code, WIP.
  • Loading branch information
Dejal committed Apr 29, 2020
1 parent c0a6ac9 commit 6846612
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 16 deletions.
8 changes: 8 additions & 0 deletions Turn Touch iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
170C8DC6245906150089B2C0 /* WidgetDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 170C8DC5245906150089B2C0 /* WidgetDelegate.swift */; };
170C8DC7245907A70089B2C0 /* TTModeDirection.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFB41B7A1CEEA9E300CD5F09 /* TTModeDirection.swift */; };
170C8DC8245907B40089B2C0 /* TTModeMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFB41B831CF5342100CD5F09 /* TTModeMap.swift */; };
17AE44062458FF9C00D06762 /* NotificationCenter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17AE44052458FF9C00D06762 /* NotificationCenter.framework */; };
17AE44092458FF9C00D06762 /* WidgetExtensionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17AE44082458FF9C00D06762 /* WidgetExtensionViewController.swift */; };
17AE440C2458FF9C00D06762 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 17AE440A2458FF9C00D06762 /* MainInterface.storyboard */; };
Expand Down Expand Up @@ -909,6 +912,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
170C8DC5245906150089B2C0 /* WidgetDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetDelegate.swift; sourceTree = "<group>"; };
17AE44042458FF9C00D06762 /* Turn Touch Widget.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Turn Touch Widget.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
17AE44052458FF9C00D06762 /* NotificationCenter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NotificationCenter.framework; path = System/Library/Frameworks/NotificationCenter.framework; sourceTree = SDKROOT; };
17AE44082458FF9C00D06762 /* WidgetExtensionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetExtensionViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1420,6 +1424,7 @@
isa = PBXGroup;
children = (
17AE44082458FF9C00D06762 /* WidgetExtensionViewController.swift */,
170C8DC5245906150089B2C0 /* WidgetDelegate.swift */,
17AE440A2458FF9C00D06762 /* MainInterface.storyboard */,
17AE440D2458FF9C00D06762 /* Info.plist */,
);
Expand Down Expand Up @@ -3083,6 +3088,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
170C8DC6245906150089B2C0 /* WidgetDelegate.swift in Sources */,
170C8DC8245907B40089B2C0 /* TTModeMap.swift in Sources */,
170C8DC7245907A70089B2C0 /* TTModeDirection.swift in Sources */,
17AE44092458FF9C00D06762 /* WidgetExtensionViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
17 changes: 3 additions & 14 deletions Widget Extension/Base.lproj/MainInterface.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
Expand All @@ -9,23 +10,10 @@
<!--Widget Extension View Controller-->
<scene sceneID="cwh-vc-ff4">
<objects>
<viewController id="M4Y-Lb-cyx" customClass="WidgetExtensionViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="M4Y-Lb-cyx" customClass="WidgetExtensionViewController" customModule="Turn_Touch_Widget" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" simulatedAppContext="notificationCenter" id="S3S-Oj-5AN">
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="top" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Hello World" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="280" translatesAutoresizingMaskIntoConstraints="NO" id="GcN-lo-r42">
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="ssy-KU-ocm" firstAttribute="bottom" secondItem="GcN-lo-r42" secondAttribute="bottom" constant="20" symbolic="YES" id="0Q0-KW-PJ6"/>
<constraint firstItem="GcN-lo-r42" firstAttribute="leading" secondItem="ssy-KU-ocm" secondAttribute="leading" constant="20" symbolic="YES" id="6Vq-gs-PHe"/>
<constraint firstItem="ssy-KU-ocm" firstAttribute="trailing" secondItem="GcN-lo-r42" secondAttribute="trailing" constant="20" symbolic="YES" id="L8K-9R-egU"/>
<constraint firstItem="GcN-lo-r42" firstAttribute="top" secondItem="ssy-KU-ocm" secondAttribute="top" constant="20" symbolic="YES" id="mYS-Cv-VNx"/>
</constraints>
<viewLayoutGuide key="safeArea" id="ssy-KU-ocm"/>
</view>
<extendedEdge key="edgesForExtendedLayout"/>
Expand All @@ -34,6 +22,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="vXp-U4-Rya" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="139" y="138"/>
</scene>
</scenes>
</document>
88 changes: 88 additions & 0 deletions Widget Extension/WidgetDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// WidgetDelegate.swift
// Widget Extension
//
// Created by David Sinclair on 2020-04-28.
// Copyright © 2020 Turn Touch. All rights reserved.
//

import UIKit

class WidgetDelegate: UIResponder {
/// Singleton shared instance.
static let shared = WidgetDelegate()

var window: UIWindow?
// var modeMap: TTModeMap!
// @IBOutlet var mainViewController: WidgetExtensionViewController!

override init() {
super.init()

// self.erasePreferences()
self.loadPreferences()

// modeMap = TTModeMap()
// modeMap.setupModes()
// modeMap.activateModes()
}

func redrawMainLayout() {
// modeMap.setupModes()
// mainViewController.layoutStackview()
// modeMap.activateModes()
}

func loadPreferences() {
let prefs = UserDefaults.standard
let defaultPrefsFile = Bundle.main.path(forResource: "Preferences", ofType: "plist")
let defaultPrefs = NSDictionary(contentsOfFile: defaultPrefsFile!) as! [String: AnyObject]
prefs.register(defaults: defaultPrefs)

self.processDefaultSettings()

prefs.set(Bundle.main.infoDictionary!["CFBundleShortVersionString"], forKey: "version")
prefs.set(Bundle.main.infoDictionary!["CFBundleVersion"], forKey: "build_number")

prefs.synchronize()
}

func processDefaultSettings() {
let defaults = UserDefaults.standard
defaults.synchronize()

guard let settingsBundle = Bundle.main.path(forResource: "Settings", ofType: "bundle") as NSString? else {
NSLog("Could not find Settings.bundle");
return;
}

if let settings = NSDictionary(contentsOfFile: settingsBundle.appendingPathComponent("Root.plist")) {
// print(" ---> Settings: \(settings)")
if let preferences = settings.object(forKey: "PreferenceSpecifiers") as? [[String: Any]] {

var defaultsToRegister = [String: Any](minimumCapacity: preferences.count)

for prefSpecification in preferences {
if let key = prefSpecification["Key"] as? String {
if !key.contains("") {
let currentObject = defaults.object(forKey: key)
if currentObject == nil {
let objectToSet = prefSpecification["DefaultValue"]
defaultsToRegister[key] = objectToSet!

NSLog("Setting object \(String(describing: objectToSet)) for key \(key)")
}
}
}
}

defaults.register(defaults: defaultsToRegister)
defaults.synchronize()
}
}
}
}

func appDelegate() -> WidgetDelegate {
return WidgetDelegate.shared
}
Loading

0 comments on commit 6846612

Please sign in to comment.