Skip to content

Commit

Permalink
[Feat] Widget (#89)
Browse files Browse the repository at this point in the history
* [Feat] Widget

* Merge branch 'develop' into Widget
  • Loading branch information
insub4067 authored Oct 2, 2023
1 parent c4f20f1 commit 2b3a6fb
Show file tree
Hide file tree
Showing 12 changed files with 417 additions and 8 deletions.
231 changes: 223 additions & 8 deletions AsyncSwift.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"version" : "0.9.1"
}
},
{
"identity" : "cocoalumberjack",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CocoaLumberjack/CocoaLumberjack.git",
"state" : {
"revision" : "67ec5818a757aba4d7c534e21a905d878d128dbf",
"version" : "3.8.1"
}
},
{
"identity" : "codescanner",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -126,6 +135,24 @@
"version" : "2.2.3"
}
},
{
"identity" : "svgkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SVGKit/SVGKit.git",
"state" : {
"revision" : "58152b9f7c85eab239160b36ffdfd364aa43d666",
"version" : "3.0.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
Expand Down
4 changes: 4 additions & 0 deletions AsyncSwift/AsyncSwift.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
<array>
<string>applinks:asyncswift.info</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.kim.AsyncSwift</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
13 changes: 13 additions & 0 deletions AsyncSwiftWidget/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions AsyncSwiftWidget/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
60 changes: 60 additions & 0 deletions AsyncSwiftWidget/AsyncSwiftWidget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// AsyncSwiftWidget.swift
// AsyncSwiftWidget
//
// Created by 김인섭 on 2023/10/01.
//

import WidgetKit
import SwiftUI

struct Provider: TimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date(), imageData: getRemoteImage())
}

func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date(), imageData: getRemoteImage())
completion(entry)
}

func getTimeline(in context: Context, completion: @escaping (Timeline<SimpleEntry>) -> ()) {

let entry = SimpleEntry(date: Date(), imageData: getRemoteImage())
let nextUpdate = Calendar.current.date(byAdding: .minute, value: 15, to: Date())
let timeline = Timeline(entries: [entry], policy: .after(nextUpdate!))
completion(timeline)
}

func getRemoteImage() -> Data? {
let urlString = "https://raw.githubusercontent.com/Async-Swift/jsonstorage/a94eb982e9b9db90543de1d574a6dc5f0c637f5b/Images/widget-large.svg"
return try? Data(contentsOf: URL(string: urlString)!)
}
}

struct SimpleEntry: TimelineEntry {
var date: Date
let imageData: Data?
}

struct AsyncSwiftWidget: Widget {
let kind: String = "AsyncSwiftWidget"

var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
AsyncSwiftWidgetEntryView(entry: entry)
}
.configurationDisplayName("AsyncSwift")
.description("행사 정보를 확인하세요.")
.supportedFamilies(
[.systemLarge]
)
}
}

struct AsyncSwiftWidget_Previews: PreviewProvider {
static var previews: some View {
AsyncSwiftWidgetEntryView(entry: SimpleEntry(date: Date(), imageData: nil))
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}
16 changes: 16 additions & 0 deletions AsyncSwiftWidget/AsyncSwiftWidgetBundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// AsyncSwiftWidgetBundle.swift
// AsyncSwiftWidget
//
// Created by 김인섭 on 2023/10/01.
//

import WidgetKit
import SwiftUI

@main
struct AsyncSwiftWidgetBundle: WidgetBundle {
var body: some Widget {
AsyncSwiftWidget()
}
}
25 changes: 25 additions & 0 deletions AsyncSwiftWidget/AsyncSwiftWidgetEntryView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// AsyncSwiftWidgetEntryView.swift
// AsyncSwift
//
// Created by 김인섭 on 2023/10/01.
//

import SwiftUI
import WidgetKit
import SVGKit

struct AsyncSwiftWidgetEntryView : View {
var entry: Provider.Entry

var body: some View {
if let imageData = entry.imageData, let image = SVGKImage(data: imageData) {
Image(uiImage: image.uiImage)
.resizable()
.scaledToFill()
.offset(y: 10)
} else {
Text("다음 행사때 만나요. 🤗")
}
}
}
11 changes: 11 additions & 0 deletions AsyncSwiftWidget/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>
10 changes: 10 additions & 0 deletions AsyncSwiftWidgetExtension.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.kim.AsyncSwift</string>
</array>
</dict>
</plist>

0 comments on commit 2b3a6fb

Please sign in to comment.