From 8c59642fc8a40e7e213b058d11439a3795d77422 Mon Sep 17 00:00:00 2001 From: Lee Jun Kit Date: Sat, 14 Aug 2021 18:49:19 +0800 Subject: [PATCH] add curl, move stuff around --- Spottie/Info.plist => Info.plist | 0 ...ottie.entitlements => Spottie.entitlements | 0 Spottie.xcodeproj/project.pbxproj | 56 +++++++++++++++++-- Spottie/Backend/CURL/spottie_curl.c | 16 ++++++ Spottie/Backend/CURL/spottie_curl.h | 17 ++++++ Spottie/PlayerCore/PlayerCore.swift | 31 ++++++++++ Spottie/PlayerCore/player_core.h | 20 +++++++ Spottie/Spottie-Bridging-Header.h | 6 ++ Spottie/SpottieApp.swift | 4 ++ 9 files changed, 146 insertions(+), 4 deletions(-) rename Spottie/Info.plist => Info.plist (100%) rename Spottie/Spottie.entitlements => Spottie.entitlements (100%) create mode 100644 Spottie/Backend/CURL/spottie_curl.c create mode 100644 Spottie/Backend/CURL/spottie_curl.h create mode 100644 Spottie/PlayerCore/PlayerCore.swift create mode 100644 Spottie/PlayerCore/player_core.h create mode 100644 Spottie/Spottie-Bridging-Header.h diff --git a/Spottie/Info.plist b/Info.plist similarity index 100% rename from Spottie/Info.plist rename to Info.plist diff --git a/Spottie/Spottie.entitlements b/Spottie.entitlements similarity index 100% rename from Spottie/Spottie.entitlements rename to Spottie.entitlements diff --git a/Spottie.xcodeproj/project.pbxproj b/Spottie.xcodeproj/project.pbxproj index 738f3a0..f6bfc92 100644 --- a/Spottie.xcodeproj/project.pbxproj +++ b/Spottie.xcodeproj/project.pbxproj @@ -80,6 +80,9 @@ 4764B3A526842ECA00AE471E /* WebAPIImageCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4764B3A426842ECA00AE471E /* WebAPIImageCollection.swift */; }; 4764B3A82684867600AE471E /* DurationFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4764B3A72684867600AE471E /* DurationFormatter.swift */; }; 47C56F602679A789003EA20A /* PlayerCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47C56F5F2679A789003EA20A /* PlayerCommands.swift */; }; + 47F77E5C26C7D04400FC882B /* spottie_curl.c in Sources */ = {isa = PBXBuildFile; fileRef = 47F77E5B26C7D04400FC882B /* spottie_curl.c */; }; + 47F77E5F26C7D19800FC882B /* libcurl.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 47F77E5E26C7D11D00FC882B /* libcurl.tbd */; }; + 47F77E6126C7D2E000FC882B /* PlayerCore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47F77E6026C7D2E000FC882B /* PlayerCore.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -158,6 +161,12 @@ 4764B3A426842ECA00AE471E /* WebAPIImageCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebAPIImageCollection.swift; sourceTree = ""; }; 4764B3A72684867600AE471E /* DurationFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DurationFormatter.swift; sourceTree = ""; }; 47C56F5F2679A789003EA20A /* PlayerCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerCommands.swift; sourceTree = ""; }; + 47F77E5926C7D04400FC882B /* Spottie-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Spottie-Bridging-Header.h"; sourceTree = ""; }; + 47F77E5A26C7D04400FC882B /* spottie_curl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = spottie_curl.h; sourceTree = ""; }; + 47F77E5B26C7D04400FC882B /* spottie_curl.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = spottie_curl.c; sourceTree = ""; }; + 47F77E5E26C7D11D00FC882B /* libcurl.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurl.tbd; path = usr/lib/libcurl.tbd; sourceTree = SDKROOT; }; + 47F77E6026C7D2E000FC882B /* PlayerCore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerCore.swift; sourceTree = ""; }; + 47F77E6326C7D39E00FC882B /* player_core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = player_core.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -165,6 +174,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 47F77E5F26C7D19800FC882B /* libcurl.tbd in Frameworks */, 470201C6265CF4560030ECA9 /* SDWebImageSwiftUI in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -176,7 +186,10 @@ isa = PBXGroup; children = ( 4730614C265656ED001E3A1F /* Spottie */, + 47306156265656EF001E3A1F /* Info.plist */, + 47306157265656EF001E3A1F /* Spottie.entitlements */, 4730614B265656ED001E3A1F /* Products */, + 47F77E5D26C7D11D00FC882B /* Frameworks */, ); sourceTree = ""; }; @@ -192,14 +205,14 @@ isa = PBXGroup; children = ( 4730616B26565EB8001E3A1F /* Backend */, + 47F77E6226C7D2E600FC882B /* PlayerCore */, 4764B3A62684865B00AE471E /* Utilities */, 4730617526588C40001E3A1F /* ViewModels */, 4730615D26565706001E3A1F /* Views */, 47C56F5E2679A779003EA20A /* Commands */, 4730614D265656ED001E3A1F /* SpottieApp.swift */, 47306151265656EF001E3A1F /* Assets.xcassets */, - 47306156265656EF001E3A1F /* Info.plist */, - 47306157265656EF001E3A1F /* Spottie.entitlements */, + 47F77E5926C7D04400FC882B /* Spottie-Bridging-Header.h */, 47306153265656EF001E3A1F /* Preview Content */, ); path = Spottie; @@ -247,6 +260,7 @@ 4730616B26565EB8001E3A1F /* Backend */ = { isa = PBXGroup; children = ( + 47F77E5826C7D01700FC882B /* CURL */, 4730617026566280001E3A1F /* Types */, 4730616C26565ED1001E3A1F /* HTTPClient.swift */, 4730617326587EF6001E3A1F /* WebsocketClient.swift */, @@ -373,6 +387,32 @@ path = Commands; sourceTree = ""; }; + 47F77E5826C7D01700FC882B /* CURL */ = { + isa = PBXGroup; + children = ( + 47F77E5A26C7D04400FC882B /* spottie_curl.h */, + 47F77E5B26C7D04400FC882B /* spottie_curl.c */, + ); + path = CURL; + sourceTree = ""; + }; + 47F77E5D26C7D11D00FC882B /* Frameworks */ = { + isa = PBXGroup; + children = ( + 47F77E5E26C7D11D00FC882B /* libcurl.tbd */, + ); + name = Frameworks; + sourceTree = ""; + }; + 47F77E6226C7D2E600FC882B /* PlayerCore */ = { + isa = PBXGroup; + children = ( + 47F77E6326C7D39E00FC882B /* player_core.h */, + 47F77E6026C7D2E000FC882B /* PlayerCore.swift */, + ); + path = PlayerCore; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -407,6 +447,7 @@ TargetAttributes = { 47306149265656ED001E3A1F = { CreatedOnToolsVersion = 12.5; + LastSwiftMigration = 1300; }; }; }; @@ -481,6 +522,7 @@ 4730618D26591E50001E3A1F /* ImageObject.swift in Sources */, 470201C8265CF8D90030ECA9 /* PlayerControls.swift in Sources */, 4730619B26591FFC001E3A1F /* TrackSeekedEvent.swift in Sources */, + 47F77E6126C7D2E000FC882B /* PlayerCore.swift in Sources */, 470201B1265B54720030ECA9 /* WebAPISimplifiedAlbumObject.swift in Sources */, 470201B5265B56350030ECA9 /* WebAPIImageObject.swift in Sources */, 47C56F602679A789003EA20A /* PlayerCommands.swift in Sources */, @@ -502,6 +544,7 @@ 4730619D26592023001E3A1F /* PlaybackPausedEvent.swift in Sources */, 475798D3266F12EB00AADF2F /* RecommendationsResponse.swift in Sources */, 475798D1266F103100AADF2F /* WebAPIPlaylistTrackObject.swift in Sources */, + 47F77E5C26C7D04400FC882B /* spottie_curl.c in Sources */, 475798CF266F101600AADF2F /* WebAPIPublicUserObject.swift in Sources */, 4730618F26591E9C001E3A1F /* ContextChangedEvent.swift in Sources */, 4764B3A1268407C600AE471E /* TrackListItem.swift in Sources */, @@ -644,12 +687,13 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Spottie/Spottie.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_ASSET_PATHS = "\"Spottie/Preview Content\""; ENABLE_PREVIEWS = YES; - INFOPLIST_FILE = Spottie/Info.plist; + INFOPLIST_FILE = Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", @@ -657,6 +701,8 @@ MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = ljk.Spottie; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Spottie/Spottie-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; }; name = Debug; @@ -666,12 +712,13 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Spottie/Spottie.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_ASSET_PATHS = "\"Spottie/Preview Content\""; ENABLE_PREVIEWS = YES; - INFOPLIST_FILE = Spottie/Info.plist; + INFOPLIST_FILE = Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", @@ -679,6 +726,7 @@ MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = ljk.Spottie; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Spottie/Spottie-Bridging-Header.h"; SWIFT_VERSION = 5.0; }; name = Release; diff --git a/Spottie/Backend/CURL/spottie_curl.c b/Spottie/Backend/CURL/spottie_curl.c new file mode 100644 index 0000000..3da1270 --- /dev/null +++ b/Spottie/Backend/CURL/spottie_curl.c @@ -0,0 +1,16 @@ +// +// spottie_curl.c +// Spottie +// +// Created by Lee Jun Kit on 14/8/21. +// + +#include "spottie_curl.h" + +CURLcode curl_easy_setopt_string(CURL *curl, CURLoption option, const char *param) { + return curl_easy_setopt(curl, option, param); +} + +CURLcode curl_easy_setopt_bool(CURL *curl, CURLoption option, bool param) { + return curl_easy_setopt(curl, option, param); +} diff --git a/Spottie/Backend/CURL/spottie_curl.h b/Spottie/Backend/CURL/spottie_curl.h new file mode 100644 index 0000000..2c5cc1f --- /dev/null +++ b/Spottie/Backend/CURL/spottie_curl.h @@ -0,0 +1,17 @@ +// +// spottie_curl.h +// Spottie +// +// Created by Lee Jun Kit on 14/8/21. +// + +#ifndef spottie_curl_h +#define spottie_curl_h + +#include +#include + +CURLcode curl_easy_setopt_string(CURL *curl, CURLoption option, const char *param); +CURLcode curl_easy_setopt_bool(CURL *curl, CURLoption option, bool param); + +#endif /* spottie_curl_h */ diff --git a/Spottie/PlayerCore/PlayerCore.swift b/Spottie/PlayerCore/PlayerCore.swift new file mode 100644 index 0000000..f0a34c9 --- /dev/null +++ b/Spottie/PlayerCore/PlayerCore.swift @@ -0,0 +1,31 @@ +// +// PlayerCore.swift +// Spottie +// +// Created by Lee Jun Kit on 14/8/21. +// + +import Foundation + +class PlayerCore { + func run() { + let t = Thread.init { + /* + librespot_init(f.toOpaque()) { user_data, ptr, len in + if let pointer = ptr { + let data = Data(bytes: pointer, count: Int(len)) + do { + let ff: Foo = Unmanaged.fromOpaque(user_data!).takeUnretainedValue(); + let json = try ff.rawDecode(data) + print(json) + } catch { + print("json error: \(error.localizedDescription)") + } + } + } + */ + } + t.name = "AnvilRust" + t.start() + } +} diff --git a/Spottie/PlayerCore/player_core.h b/Spottie/PlayerCore/player_core.h new file mode 100644 index 0000000..d0193bc --- /dev/null +++ b/Spottie/PlayerCore/player_core.h @@ -0,0 +1,20 @@ +// +// player_core.h +// Spottie +// +// Created by Lee Jun Kit on 14/8/21. +// + +#ifndef player_core_h +#define player_core_h + +#include +#include +#include +#include + +void librespot_init(const void *user_data, + void (*event_callback)(const void*, uint8_t*, uintptr_t)); + + +#endif /* player_core_h */ diff --git a/Spottie/Spottie-Bridging-Header.h b/Spottie/Spottie-Bridging-Header.h new file mode 100644 index 0000000..ce8ce5e --- /dev/null +++ b/Spottie/Spottie-Bridging-Header.h @@ -0,0 +1,6 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#include "player_core.h" +#include "spottie_curl.h" diff --git a/Spottie/SpottieApp.swift b/Spottie/SpottieApp.swift index e97a3ee..c623dde 100644 --- a/Spottie/SpottieApp.swift +++ b/Spottie/SpottieApp.swift @@ -10,6 +10,10 @@ import Combine @main struct SpottieApp: App { + init() { + + } + @StateObject private var playerViewModel = PlayerViewModel(EventBroker()) var body: some Scene {