Skip to content

Commit 3eb89fb

Browse files
committed
feat: add basic script and extensions ui
0 parents  commit 3eb89fb

File tree

33 files changed

+1803
-0
lines changed

33 files changed

+1803
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

TrackerApp/TrackerApp.xcodeproj/project.pbxproj

+844
Large diffs are not rendered by default.

TrackerApp/TrackerApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
uuid = "2BDE50D6-B4E4-412E-A5FB-B0A62C096505"
4+
type = "1"
5+
version = "2.0">
6+
</Bucket>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>TrackerApp.xcscheme_^#shared#^_</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
<key>TrackerWidgetExtension.xcscheme_^#shared#^_</key>
13+
<dict>
14+
<key>orderHint</key>
15+
<integer>1</integer>
16+
</dict>
17+
</dict>
18+
</dict>
19+
</plist>
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// AppDelegate.swift
3+
// TrackerApp
4+
//
5+
// Created by ezen on 08/08/2024.
6+
//
7+
8+
import UIKit
9+
10+
@main
11+
class AppDelegate: UIResponder, UIApplicationDelegate {
12+
13+
14+
15+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
16+
17+
return true
18+
}
19+
20+
// MARK: UISceneSession Lifecycle
21+
22+
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
23+
// Called when a new scene session is being created.
24+
// Use this method to select a configuration to create the new scene with.
25+
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
26+
}
27+
28+
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
29+
// Called when the user discards a scene session.
30+
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
31+
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
32+
}
33+
34+
35+
}
36+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"platform" : "ios",
6+
"size" : "1024x1024"
7+
}
8+
],
9+
"info" : {
10+
"author" : "xcode",
11+
"version" : 1
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
5+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<scenes>
9+
<!--View Controller-->
10+
<scene sceneID="EHf-IW-A2E">
11+
<objects>
12+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
13+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
14+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
15+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
16+
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
17+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
18+
</view>
19+
</viewController>
20+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
21+
</objects>
22+
<point key="canvasLocation" x="53" y="375"/>
23+
</scene>
24+
</scenes>
25+
</document>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<device id="retina6_12" orientation="portrait" appearance="dark"/>
4+
<dependencies>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
6+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
7+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
8+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9+
</dependencies>
10+
<scenes>
11+
<!--Main View Controller-->
12+
<scene sceneID="tne-QT-ifu">
13+
<objects>
14+
<viewController id="BYZ-38-t0r" customClass="MainViewController" customModule="TrackerApp" customModuleProvider="target" sceneMemberID="viewController">
15+
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
16+
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
17+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
19+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
20+
</view>
21+
</viewController>
22+
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
23+
</objects>
24+
<point key="canvasLocation" x="140" y="4"/>
25+
</scene>
26+
</scenes>
27+
<resources>
28+
<systemColor name="systemBackgroundColor">
29+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
30+
</systemColor>
31+
</resources>
32+
</document>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// BackendApi.swift
3+
// TrackerApp
4+
//
5+
// Created by ezen on 08/08/2024.
6+
//
7+
8+
import Foundation
9+
10+
@objc
11+
protocol BackendApiListener {
12+
@objc optional func onReceived(dataReceived data: String)
13+
@objc optional func onError(error: String)
14+
@objc optional func onConnected()
15+
@objc optional func onDisconnected()
16+
}
17+
18+
final class BackendApi: NSObject, URLSessionWebSocketDelegate {
19+
static let shared = BackendApi()
20+
21+
var API_URL: String = "ws://127.0.0.1:5173"
22+
23+
private var task: URLSessionWebSocketTask!
24+
25+
private var delegate: BackendApiListener!
26+
27+
func connect(with delegate: BackendApiListener) {
28+
self.delegate = delegate
29+
30+
if let url = URL(string: API_URL) {
31+
self.task = URLSession(configuration: .default, delegate: self, delegateQueue: .main).webSocketTask(with: url)
32+
self.task.resume()
33+
}
34+
}
35+
36+
func disconnect() {
37+
self.task.cancel(with: .goingAway, reason: "Closing connexion".data(using: .utf8))
38+
}
39+
40+
// MARK: - Private functions
41+
private func receive() {
42+
self.task.receive { _response in
43+
switch _response {
44+
case .success(let _msg):
45+
switch _msg {
46+
case .string(let text):
47+
self.delegate.onReceived?(dataReceived: text)
48+
default:
49+
break
50+
}
51+
52+
case .failure(let error):
53+
self.delegate.onError?(error: error.localizedDescription)
54+
}
55+
56+
self.receive()
57+
}
58+
}
59+
60+
private func ping() {
61+
self.task.sendPing { _error in
62+
if _error != nil {
63+
self.delegate.onError?(error: "Failed to connect to server")
64+
} else {
65+
DispatchQueue.global().asyncAfter(deadline: .now() + 10) {
66+
self.ping()
67+
}
68+
}
69+
}
70+
}
71+
72+
func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol protocol: String?) {
73+
self.delegate.onConnected?()
74+
self.ping()
75+
self.receive()
76+
}
77+
78+
func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didCloseWith closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) {
79+
self.delegate.onDisconnected?()
80+
}
81+
82+
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: (any Error)?) {
83+
self.delegate.onError?(error: error?.localizedDescription ?? "")
84+
}
85+
}

TrackerApp/TrackerApp/Info.plist

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>UIApplicationSceneManifest</key>
6+
<dict>
7+
<key>UIApplicationSupportsMultipleScenes</key>
8+
<false/>
9+
<key>UISceneConfigurations</key>
10+
<dict>
11+
<key>UIWindowSceneSessionRoleApplication</key>
12+
<array>
13+
<dict>
14+
<key>UISceneConfigurationName</key>
15+
<string>Default Configuration</string>
16+
<key>UISceneDelegateClassName</key>
17+
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
18+
<key>UISceneStoryboardFile</key>
19+
<string>Main</string>
20+
</dict>
21+
</array>
22+
</dict>
23+
</dict>
24+
</dict>
25+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//
2+
// ViewController.swift
3+
// TrackerApp
4+
//
5+
// Created by ezen on 08/08/2024.
6+
//
7+
8+
import UIKit
9+
import SwiftUI
10+
11+
class MainViewController: UIViewController {
12+
var vm: MainViewModel!
13+
14+
override func viewDidLoad() {
15+
super.viewDidLoad()
16+
17+
self.vm = MainViewModel(host: self)
18+
19+
let _view = MainView(vm: self.vm)
20+
21+
let _vc = UIHostingController(rootView: _view)
22+
_vc.view.translatesAutoresizingMaskIntoConstraints = false
23+
_vc.view.backgroundColor = .clear
24+
25+
addChild(_vc)
26+
view.addSubview(_vc.view)
27+
_vc.didMove(toParent: self)
28+
29+
NSLayoutConstraint.activate([
30+
NSLayoutConstraint(item: _vc.view!, attribute: .top, relatedBy: .equal, toItem: view.safeAreaLayoutGuide, attribute: .top, multiplier: 1, constant: 0),
31+
NSLayoutConstraint(item: _vc.view!, attribute: .bottom, relatedBy: .equal, toItem: view.safeAreaLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0),
32+
NSLayoutConstraint(item: _vc.view!, attribute: .leading, relatedBy: .equal, toItem: view.safeAreaLayoutGuide, attribute: .leading, multiplier: 1, constant: 0),
33+
NSLayoutConstraint(item: _vc.view!, attribute: .trailing, relatedBy: .equal, toItem: view.safeAreaLayoutGuide, attribute: .trailing, multiplier: 1, constant: 0)
34+
])
35+
}
36+
}
37+
38+
struct MainView: View {
39+
@StateObject var vm: MainViewModel
40+
41+
var body: some View {
42+
ScrollView(showsIndicators: false) {
43+
LazyVStack(spacing: 15) {
44+
HStack(spacing: 3) {
45+
Text("Updates")
46+
.font(.headline)
47+
Rectangle()
48+
.fill(vm.isConnected ? .green : .red)
49+
.frame(width: 6, height: 6)
50+
.cornerRadius(3)
51+
.offset(CGSize(width: 0.0, height: -5.0))
52+
Spacer()
53+
if vm.isConnected {
54+
Button("Connected") {
55+
//
56+
}
57+
.buttonStyle(BorderedButtonStyle())
58+
.accentColor(.green)
59+
} else {
60+
Button("Connect") {
61+
vm.onConnect()
62+
}
63+
.buttonStyle(BorderedButtonStyle())
64+
}
65+
}
66+
.frame(maxWidth: .infinity, alignment: .leading)
67+
.padding(15)
68+
.background(Color.white.opacity(0.1))
69+
.cornerRadius(10)
70+
71+
ForEach(Array(vm.data.enumerated()), id: \.0) { _, item in
72+
Text(item)
73+
.frame(maxWidth: .infinity, alignment: .leading)
74+
.padding(15)
75+
.background(Color.white.opacity(0.05))
76+
.cornerRadius(10)
77+
}
78+
.padding(.top, 15)
79+
80+
Spacer()
81+
}
82+
.frame(maxWidth: .infinity)
83+
.padding(15)
84+
.padding(.bottom, 100)
85+
}
86+
}
87+
}
88+
89+
#Preview {
90+
MainView(vm: MainViewModel(host: UIViewController()))
91+
}

0 commit comments

Comments
 (0)