Skip to content

Commit

Permalink
iOS 14 widget for debug view of active recorders
Browse files Browse the repository at this point in the history
  • Loading branch information
sobri909 committed Jul 2, 2020
1 parent 0a97fa0 commit 1ad2dfb
Show file tree
Hide file tree
Showing 11 changed files with 472 additions and 9 deletions.
207 changes: 202 additions & 5 deletions Arc Mini.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
<key>Arc Mini RELEASE.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>7</integer>
<integer>1</integer>
</dict>
<key>RecordersWidgetExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>8</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand Down
6 changes: 3 additions & 3 deletions Arc Mini.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/mxcl/PromiseKit",
"state": {
"branch": null,
"revision": "f14f16cc2602afec1030e4f492100d6d43dca544",
"version": "6.13.1"
"revision": "f6b15b7626a4399864ffa1d5ec2ed9cf0cea5556",
"version": "6.13.2"
}
},
{
Expand Down Expand Up @@ -51,7 +51,7 @@
"repositoryURL": "https://github.com/timbersoftware/SwiftUI-Introspect.git",
"state": {
"branch": "master",
"revision": "18c8c7fb0f22a3b86b34d68cb3a5f4e7351774e1",
"revision": "07ec9bb46181e58cc0ea04b3191329ff8249df3c",
"version": null
}
}
Expand Down
11 changes: 11 additions & 0 deletions RecordersWidget/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
98 changes: 98 additions & 0 deletions RecordersWidget/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions RecordersWidget/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
}
}
29 changes: 29 additions & 0 deletions RecordersWidget/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>RecordersWidget</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>
82 changes: 82 additions & 0 deletions RecordersWidget/RecordersWidget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// RecordersWidget.swift
// RecordersWidget
//
// Created by Matt Greenfield on 28/6/20.
// Copyright © 2020 Matt Greenfield. All rights reserved.
//

import WidgetKit
import SwiftUI
import LocoKit

struct Provider: TimelineProvider {
public typealias Entry = SimpleEntry

let appGroup = AppGroup(appName: .arcMini, suiteName: "group.ArcApp", readOnly: true)

public func snapshot(with context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date(), sortedApps: appGroup.sortedApps)
completion(entry)
}

public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
let appGroup = AppGroup(appName: .arcMini, suiteName: "group.ArcApp", readOnly: true)
let entries: [SimpleEntry] = [SimpleEntry(date: Date(), sortedApps: appGroup.sortedApps)]
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
}

struct SimpleEntry: TimelineEntry {
public let date: Date
public let sortedApps: [LocoKit.AppGroup.AppState]
}

struct PlaceholderView: View {
var body: some View {
Text("Placeholder View")
}
}

struct RecordersWidgetEntryView: View {
var entry: Provider.Entry

let appGroup = AppGroup(appName: .arcMini, suiteName: "group.ArcApp", readOnly: true)

var body: some View {
VStack {
Text(entry.date, style: .time)
ForEach(appGroup.sortedApps, id: \.updated) { appState in
self.row(
leftText: appState.appName.rawValue,
rightText: "\(appState.recordingState.rawValue) (\(String(duration: appState.updated.age)) ago)",
highlight: appState.isAliveAndRecording, fade: !appState.isAlive
).frame(height: 20)
}
}.padding([.leading, .trailing], 20)
}

func row(leftText: String, rightText: String, highlight: Bool = false, fade: Bool = false) -> some View {
let font = highlight ? Font.system(.footnote).bold() : Font.system(.footnote)
return HStack {
Text(leftText).font(font).opacity(fade ? 0.6 : 1)
Spacer()
Text(rightText).font(font).opacity(0.6).opacity(fade ? 0.6 : 1)
}
}

}

@main
struct RecordersWidget: Widget {
private let kind: String = "RecordersWidget"

public var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider(), placeholder: PlaceholderView()) { entry in
RecordersWidgetEntryView(entry: entry)
}
.configurationDisplayName("Arc Recorders")
.description("The currently alive Arc recorders.")
}
}
14 changes: 14 additions & 0 deletions RecordersWidget/WidgetState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// WidgetState.swift
// Arc Mini
//
// Created by Matt Greenfield on 28/6/20.
// Copyright © 2020 Matt Greenfield. All rights reserved.
//

import SwiftUI
import LocoKit

class WidgetState: ObservableObject {
var appGroup = AppGroup(appName: .arcMini, suiteName: "group.ArcApp")
}
10 changes: 10 additions & 0 deletions RecordersWidgetExtension.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.ArcApp</string>
</array>
</dict>
</plist>

0 comments on commit 1ad2dfb

Please sign in to comment.