Skip to content

Commit ba81fa0

Browse files
authored
Merge pull request #22 from sieren/add-live-activity
Add Live Activities
2 parents 7f9e45b + aa4f880 commit ba81fa0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+956
-62
lines changed

Icons/startIcon.png

55.8 KB
Loading

ReleaseConfig.xcconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright © 2023 Matthias Frick. All rights reserved.
2+
3+
// Configuration settings file format documentation can be found at:
4+
// https://help.apple.com/xcode/#/dev745c5c974
5+
6+
CURRENT_PROJECT_VERSION=69

midile-widget/AppIntent.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// AppIntent.swift
3+
// midile-widget
4+
//
5+
// Created by Matthias Frick on 29.10.23.
6+
// Copyright © 2023 Matthias Frick. All rights reserved.
7+
//
8+
9+
import WidgetKit
10+
import AppIntents
11+
12+
struct ConfigurationAppIntent: WidgetConfigurationIntent {
13+
static var title: LocalizedStringResource = "Configuration"
14+
static var description = IntentDescription("This is an example widget.")
15+
16+
// An example configurable parameter.
17+
@Parameter(title: "Favorite Emoji", default: "😃")
18+
var favoriteEmoji: String
19+
}
Lines changed: 11 additions & 0 deletions
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+
}
Lines changed: 13 additions & 0 deletions
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+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 11 additions & 0 deletions
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+
}

midile-widget/Info.plist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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>NSExtension</key>
6+
<dict>
7+
<key>NSExtensionPointIdentifier</key>
8+
<string>com.apple.widgetkit-extension</string>
9+
</dict>
10+
</dict>
11+
</plist>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// MIDIActivityAttribute.swift
3+
// midimittr
4+
//
5+
// Created by Matthias Frick on 29.10.23.
6+
// Copyright © 2023 Matthias Frick. All rights reserved.
7+
//
8+
9+
import Foundation

midile-widget/midile_widget.swift

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// midile_widget.swift
3+
// midile-widget
4+
//
5+
// Created by Matthias Frick on 29.10.23.
6+
// Copyright © 2023 Matthias Frick. All rights reserved.
7+
//
8+
9+
import WidgetKit
10+
import SwiftUI
11+
12+
struct Provider: AppIntentTimelineProvider {
13+
func placeholder(in context: Context) -> SimpleEntry {
14+
SimpleEntry(date: Date(), configuration: ConfigurationAppIntent())
15+
}
16+
17+
func snapshot(for configuration: ConfigurationAppIntent, in context: Context) async -> SimpleEntry {
18+
SimpleEntry(date: Date(), configuration: configuration)
19+
}
20+
21+
func timeline(for configuration: ConfigurationAppIntent, in context: Context) async -> Timeline<SimpleEntry> {
22+
var entries: [SimpleEntry] = []
23+
24+
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
25+
let currentDate = Date()
26+
for hourOffset in 0 ..< 5 {
27+
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
28+
let entry = SimpleEntry(date: entryDate, configuration: configuration)
29+
entries.append(entry)
30+
}
31+
32+
return Timeline(entries: entries, policy: .atEnd)
33+
}
34+
}
35+
36+
struct SimpleEntry: TimelineEntry {
37+
let date: Date
38+
let configuration: ConfigurationAppIntent
39+
}
40+
41+
struct midile_widgetEntryView : View {
42+
var entry: Provider.Entry
43+
44+
var body: some View {
45+
VStack {
46+
Text("Time:")
47+
Text(entry.date, style: .time)
48+
49+
Text("Favorite Emoji:")
50+
Text(entry.configuration.favoriteEmoji)
51+
}
52+
}
53+
}
54+
55+
struct midile_widget: Widget {
56+
let kind: String = "midile_widget"
57+
58+
var body: some WidgetConfiguration {
59+
AppIntentConfiguration(kind: kind, intent: ConfigurationAppIntent.self, provider: Provider()) { entry in
60+
midile_widgetEntryView(entry: entry)
61+
.containerBackground(.fill.tertiary, for: .widget)
62+
}
63+
}
64+
}
65+
66+
extension ConfigurationAppIntent {
67+
fileprivate static var smiley: ConfigurationAppIntent {
68+
let intent = ConfigurationAppIntent()
69+
intent.favoriteEmoji = "😀"
70+
return intent
71+
}
72+
73+
fileprivate static var starEyes: ConfigurationAppIntent {
74+
let intent = ConfigurationAppIntent()
75+
intent.favoriteEmoji = "🤩"
76+
return intent
77+
}
78+
}
79+
80+
#Preview(as: .systemSmall) {
81+
midile_widget()
82+
} timeline: {
83+
SimpleEntry(date: .now, configuration: .smiley)
84+
SimpleEntry(date: .now, configuration: .starEyes)
85+
}

0 commit comments

Comments
 (0)