-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adding Turn Touch code, WIP.
- Loading branch information
Showing
4 changed files
with
314 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.