Subversion Repositories Mobile Apps.GyroMouse

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
//
2
//  AppDelegate.swift
3
//  GyroMouse
4
//
5
//  Created by Matteo Riva on 07/08/15.
6
//  Copyright © 2015 Matteo Riva. All rights reserved.
7
//
8
 
9
import UIKit
10
 
7 pmbaty 11
let GyroMouseShouldRefreshServerListNotification = Notification.Name("GyroMouseShouldRefreshServerList")
12
let GyroMouseConnectionSuccessNotification = Notification.Name("GyroMouseConnectionSuccess")
13
let GyroMouseConnectionFailedNotification = Notification.Name("GyroMouseConnectionFailed")
14
let GyroMouseDisconnectedNotification = Notification.Name("GyroMouseDisconnected")
15
let GyroMouseGoingBackgroundNotification = Notification.Name("GyroMouseGoingBackground")
1 pmbaty 16
 
7 pmbaty 17
extension String {
18
    var localized: String {
19
        return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
20
    }
21
}
1 pmbaty 22
 
23
@UIApplicationMain
24
class AppDelegate: UIResponder, UIApplicationDelegate {
25
 
26
    var window: UIWindow?
27
 
28
    let client = ClientHandler()
29
 
30
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
31
        if !UserDefaults.standard.bool(forKey: "firstBoot") {
32
            UserDefaults.standard.set(10, forKey: "moveVelocity")
33
            UserDefaults.standard.set(1, forKey: "scrollVelocity")
34
            UserDefaults.standard.set(true, forKey: "shakeToReset")
35
            UserDefaults.standard.set(true, forKey: "keepScreenActive")
36
        }
37
 
38
        application.isIdleTimerDisabled = UserDefaults.standard.bool(forKey: "keepScreenActive")
39
 
40
        client.startBrowsing()
41
        return true
42
    }
43
 
44
    func applicationWillResignActive(_ application: UIApplication) {
45
        client.stopBrowsing()
7 pmbaty 46
        NotificationCenter.default.post(name: GyroMouseGoingBackgroundNotification, object: nil)
1 pmbaty 47
    }
48
 
49
    func applicationDidEnterBackground(_ application: UIApplication) {
50
        /// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
51
        /// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
52
    }
53
 
54
    func applicationWillEnterForeground(_ application: UIApplication) {
55
        client.startBrowsing()
56
    }
57
 
58
    func applicationDidBecomeActive(_ application: UIApplication) {
59
        client.startBrowsing()
60
    }
61
 
62
    func applicationWillTerminate(_ application: UIApplication) {
63
        /// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
64
    }
65
 
66
}
67
/*
68
@main
69
struct MyMain {
70
    static func main() -> Void {
71
        bootstrap_console()
72
         UIApplicationMain(
73
             CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(AppDelegate.self)
74
         )
75
    }
76
}
77
*/