Skip to content

Commit

Permalink
Update group identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmuslos committed Jan 5, 2024
1 parent 0c55f18 commit 878d24b
Show file tree
Hide file tree
Showing 17 changed files with 541 additions and 23 deletions.
247 changes: 227 additions & 20 deletions AmpFin.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
123 changes: 123 additions & 0 deletions AmpFin.xcodeproj/xcshareddata/xcschemes/Widget Extension.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1510"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3A442BE22B483C0B008FECE2"
BuildableName = "widget Extension.appex"
BlueprintName = "widget Extension"
ReferencedContainer = "container:AmpFin.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3ABAFCA92AA7D6C40011BFD6"
BuildableName = "iOS.app"
BlueprintName = "iOS"
ReferencedContainer = "container:AmpFin.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0"
askForAppToLaunch = "Yes"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "2">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.springboard">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3A442BE22B483C0B008FECE2"
BuildableName = "widget Extension.appex"
BlueprintName = "widget Extension"
ReferencedContainer = "container:AmpFin.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3ABAFCA92AA7D6C40011BFD6"
BuildableName = "iOS.app"
BlueprintName = "iOS"
ReferencedContainer = "container:AmpFin.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "_XCWidgetKind"
value = ""
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "_XCWidgetDefaultView"
value = "timeline"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "_XCWidgetFamily"
value = "systemMedium"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3ABAFCA92AA7D6C40011BFD6"
BuildableName = "iOS.app"
BlueprintName = "iOS"
ReferencedContainer = "container:AmpFin.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>iOS.xcscheme_^#shared#^_</key>
<key>Widget Extension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>iOS.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>3A442BE22B483C0B008FECE2</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>3AB897902B02969100AF783D</key>
<dict>
<key>primary</key>
Expand Down
36 changes: 35 additions & 1 deletion AmpFinKit/Sources/AFBaseKit/HTTP/JellyfinClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public class JellyfinClient {
#endif

let logger = Logger(subsystem: "io.rfk.ampfin", category: "Download")
static let defaults = UserDefaults(suiteName: "group.io.rfk.shelfplayer")!
static let defaults = UserDefaults(suiteName: JellyfinClient.groupIdentifier)!

init(serverUrl: URL!, token: String?, userId: String?) {
logger.info("Using group identifier \(Self.groupIdentifier)")

self.serverUrl = serverUrl
self.token = token
self.userId = userId
Expand Down Expand Up @@ -87,6 +89,38 @@ extension JellyfinClient {
}
}

extension JellyfinClient {
public static var groupIdentifier: String {
let fallback = "group.io.rfk.ampfin"
let queryLoad: [String: AnyObject] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: "bundleSeedID" as AnyObject,
kSecAttrService as String: "AmpFin" as AnyObject,
kSecReturnAttributes as String: kCFBooleanTrue,
]

var result: AnyObject?
var status = withUnsafeMutablePointer(to: &result) {
SecItemCopyMatching(queryLoad as CFDictionary, UnsafeMutablePointer($0))
}

if status == errSecItemNotFound {
status = withUnsafeMutablePointer(to: &result) {
SecItemAdd(queryLoad as CFDictionary, UnsafeMutablePointer($0))
}
}

if status == noErr,
let resultDict = result as? [String: Any], let accessGroup = resultDict[kSecAttrAccessGroup as String] as? String,
let seedID = accessGroup.components(separatedBy: ".").first,
seedID != "N8AA4S3S96" {
return "\(fallback).\(seedID)"
}

return fallback
}
}

// MARK: Singleton

extension JellyfinClient {
Expand Down
3 changes: 2 additions & 1 deletion AmpFinKit/Sources/AFOfflineKit/PersistenceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import SwiftData
import AFBaseKit

public struct PersistenceManager {
public let modelContainer: ModelContainer = {
Expand All @@ -19,7 +20,7 @@ public struct PersistenceManager {
OfflinePlay.self,
OfflineFavorite.self,
])
let modelConfiguration = ModelConfiguration("AmpFin", schema: schema, isStoredInMemoryOnly: false, allowsSave: true, groupContainer: .identifier("group.io.rfk.ampfin"))
let modelConfiguration = ModelConfiguration("AmpFin", schema: schema, isStoredInMemoryOnly: false, allowsSave: true, groupContainer: .identifier(JellyfinClient.groupIdentifier))

do {
return try ModelContainer(for: schema, configurations: [modelConfiguration])
Expand Down
1 change: 1 addition & 0 deletions iOS/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
}
},
"developedBy" : {
"extractionState" : "stale",
"localizations" : {
"de" : {
"stringUnit" : {
Expand Down
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 widget Extension/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 widget Extension/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
}
}
49 changes: 49 additions & 0 deletions widget Extension/DebugTokenWidget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// DebugTokenTimelineProvider.swift
// widget Extension
//
// Created by Rasmus Krämer on 05.01.24.
//

import SwiftUI
import WidgetKit
import AFBaseKit

struct DebugTokenWidget: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: "io.rfk.ampfin.debug.token",
provider: DebugTokenTimelineProvider()) { entry in
Text(entry.token)
.containerBackground(.ultraThickMaterial, for: .widget)
}
.configurationDisplayName(String(localized: "debug.title"))
.description(String(localized: "debug.description"))
}
}

struct DebugTokenTimelineProvider: TimelineProvider {
typealias Entry = DebugTokenEntry

func placeholder(in context: Context) -> DebugTokenEntry {
DebugTokenEntry(date: Date())
}

func getSnapshot(in context: Context, completion: @escaping (Entry) -> Void) {
completion(DebugTokenEntry(date: Date()))
}
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) {
completion(Timeline(entries: [DebugTokenEntry(date: Date())], policy: .never))
}
}

struct DebugTokenEntry: TimelineEntry {
var date: Date
let token = JellyfinClient.shared.token ?? String(localized: "token.missing")
}

#Preview(as: .systemSmall) {
DebugTokenWidget()
} timeline: {
DebugTokenEntry(date: Date())
}
10 changes: 10 additions & 0 deletions widget Extension/Entitlements.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.io.rfk.ampfin</string>
</array>
</dict>
</plist>
11 changes: 11 additions & 0 deletions widget Extension/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>
15 changes: 15 additions & 0 deletions widget Extension/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"sourceLanguage" : "en",
"strings" : {
"debug.description" : {

},
"debug.title" : {

},
"token.missing" : {

}
},
"version" : "1.0"
}
16 changes: 16 additions & 0 deletions widget Extension/WidgetExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// widgetsBundle.swift
// widgets
//
// Created by Rasmus Krämer on 05.01.24.
//

import WidgetKit
import SwiftUI

@main
struct WidgetExtension: WidgetBundle {
var body: some Widget {
DebugTokenWidget()
}
}

0 comments on commit 878d24b

Please sign in to comment.