Skip to content

Commit

Permalink
wip: add macos videoplayer support, use custom navstack for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
ErrorErrorError committed Nov 25, 2023
1 parent db684fc commit ceeb910
Show file tree
Hide file tree
Showing 67 changed files with 2,137 additions and 1,809 deletions.
26 changes: 8 additions & 18 deletions App/Mochi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
1396FE0529DF561C00B22132 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1396FE0029DF561C00B22132 /* Assets.xcassets */; };
1396FE0629DF561C00B22132 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1396FE0229DF561C00B22132 /* Preview Assets.xcassets */; };
1396FE0729DF561C00B22132 /* MochiApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1396FE0329DF561C00B22132 /* MochiApp.swift */; };
1396FE0C29DF58CA00B22132 /* App in Frameworks */ = {isa = PBXBuildFile; productRef = 1396FE0B29DF58CA00B22132 /* App */; };
13F11CC02B11617D006FFF63 /* App in Frameworks */ = {isa = PBXBuildFile; productRef = 13F11CBF2B11617D006FFF63 /* App */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -27,14 +27,15 @@
1396FE0229DF561C00B22132 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
1396FE0329DF561C00B22132 /* MochiApp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MochiApp.swift; sourceTree = "<group>"; };
13C18B9129CE6CC200C14F26 /* Mochi.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mochi.app; sourceTree = BUILT_PRODUCTS_DIR; };
13F11CC12B116431006FFF63 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.0.sdk/System/Library/Frameworks/Accelerate.framework; sourceTree = DEVELOPER_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
13C18B8E29CE6CC200C14F26 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1396FE0C29DF58CA00B22132 /* App in Frameworks */,
13F11CC02B11617D006FFF63 /* App in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -44,6 +45,7 @@
1337293829DF4E7200C086FA /* Frameworks */ = {
isa = PBXGroup;
children = (
13F11CC12B116431006FFF63 /* Accelerate.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -132,7 +134,7 @@
);
name = Mochi;
packageProductDependencies = (
1396FE0B29DF58CA00B22132 /* App */,
13F11CBF2B11617D006FFF63 /* App */,
);
productName = mochi;
productReference = 13C18B9129CE6CC200C14F26 /* Mochi.app */;
Expand Down Expand Up @@ -362,26 +364,19 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Shared/mochi.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 0;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = ..;
DEVELOPMENT_TEAM = A6HC4Y86NJ;
ENABLE_HARDENED_RUNTIME = YES;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Shared/mochi-info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.entertainment";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault;
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportsDocumentBrowser = YES;
Expand All @@ -392,6 +387,7 @@
MARKETING_VERSION = 0.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.errorerrorerror.mochi;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -407,26 +403,19 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Shared/mochi.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 0;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = ..;
DEVELOPMENT_TEAM = A6HC4Y86NJ;
ENABLE_HARDENED_RUNTIME = YES;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Shared/mochi-info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.entertainment";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault;
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportsDocumentBrowser = YES;
Expand All @@ -437,6 +426,7 @@
MARKETING_VERSION = 0.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.errorerrorerror.mochi;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -470,7 +460,7 @@
/* End XCConfigurationList section */

/* Begin XCSwiftPackageProductDependency section */
1396FE0B29DF58CA00B22132 /* App */ = {
13F11CBF2B11617D006FFF63 /* App */ = {
isa = XCSwiftPackageProductDependency;
productName = App;
};
Expand Down

This file was deleted.

8 changes: 2 additions & 6 deletions App/Shared/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
#else
import AppKit

class AppDelegate: NSObject, UIApplicationDelegate {
class AppDelegate: NSObject, NSApplicationDelegate {
let store = Store(
initialState: .init(),
reducer: { AppFeature() }
)

func application(
_: UIApplication,
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
func applicationDidFinishLaunching(_ notification: Notification) {

Check warning on line 56 in App/Shared/AppDelegate.swift

View workflow job for this annotation

GitHub Actions / run-swiftformat

Mark unused function arguments with _. (unusedArguments)
store.send(.internal(.appDelegate(.didFinishLaunching)))
return true
}

func applicationShouldTerminate(_: NSApplication) -> NSApplication.TerminateReply {
Expand Down
31 changes: 30 additions & 1 deletion App/Shared/MochiApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,45 @@

import App
import ComposableArchitecture
import Settings
import SwiftUI
import VideoPlayer

#if !os(iOS)
#if os(macOS)
@main
struct MochiApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self)
var appDelegate

var body: some Scene {
WindowGroup {
AppFeature.View(
store: appDelegate.store
)
.themeable()
.frame(
minWidth: 800,
maxWidth: .infinity,
minHeight: 625,
maxHeight: .infinity
)
}
.windowStyle(.titleBar)
.commands {
SidebarCommands()
ToolbarCommands()

CommandGroup(replacing: .newItem) {}
}

Settings {
SettingsFeature.View(
store: appDelegate.store.scope(
state: \.settings,
action: { .internal(.settings($0)) }
)
)
.themeable()
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions App/Shared/mochi.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ extension JSContext {
let ctx = JSContext.current()
let value = dataToText.withCString(JSStringCreateWithUTF8CString)
defer { JSStringRelease(value) }
return JSValue(jsValueRef: JSValueMakeFromJSONString(ctx?.jsGlobalContextRef, value), in: ctx)
return JSValue(
jsValueRef: JSValueMakeFromJSONString(ctx?.jsGlobalContextRef, value) ??

Check warning on line 134 in Sources/Clients/ModuleClient/JS+Bindings/JSContext+Request.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Lines should not have trailing whitespace (trailing_whitespace)
JSValueMakeUndefined(ctx?.jsGlobalContextRef) ,

Check warning on line 135 in Sources/Clients/ModuleClient/JS+Bindings/JSContext+Request.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

There should be no space before and one after any comma (comma)
in: ctx
)
} as @convention(block) () -> JSValue

let textFunction = {
Expand Down
9 changes: 7 additions & 2 deletions Sources/Clients/PlayerClient/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Copyright © 2023. All rights reserved.
//

@preconcurrency
import AVFoundation
import Dependencies
import Foundation
Expand All @@ -21,10 +20,15 @@ public struct PlayerClient: Sendable {
public var pause: @Sendable () async -> Void
public var seek: @Sendable (_ progress: Double) async -> Void
public var volume: @Sendable (_ amount: Double) async -> Void
public var setOption: @Sendable (_ option: MediaSelectionOption?, _ in: MediaSelectionGroup) async -> Void
public var clear: @Sendable () async -> Void
public var get: @Sendable () -> Status
public var observe: @Sendable () -> AsyncStream<Status>
var player: @Sendable () -> AVPlayer

// TODO: Create Custom AVPlayer and AVPlayerItems and each holds

Check warning on line 28 in Sources/Clients/PlayerClient/Client.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

TODOs should be resolved (Create Custom AVPlayer and AVP...) (todo)
// an item. Internally it should retrieve the contents when possible, rather than
// having an internal model doing it.
public var player: @Sendable () -> AVPlayer
}

// MARK: TestDependencyKey
Expand All @@ -37,6 +41,7 @@ extension PlayerClient: TestDependencyKey {
pause: unimplemented(),
seek: unimplemented(),
volume: unimplemented(),
setOption: unimplemented(),
clear: unimplemented(),
get: unimplemented(),
observe: unimplemented(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ import Foundation

// MARK: - MediaSelectionGroup

// Not sure if this brings performance improvements, if any
public struct MediaSelectionGroup: Hashable, Sendable {
fileprivate let _ref: AVMediaSelectionGroup
public var displayName: String
public private(set) var selected: MediaSelectionOption?

let _ref: AVMediaSelectionGroup

init(
name: String,
selected: MediaSelectionOption? = nil,
_ ref: AVMediaSelectionGroup
) {
self._ref = ref
self.displayName = name
self.selected = selected
}

public var allowsEmptySelection: Bool {
_ref.allowsEmptySelection
Expand All @@ -24,8 +36,8 @@ public struct MediaSelectionGroup: Hashable, Sendable {
_ref.options.map { .init($0) }
}

fileprivate init(_ ref: AVMediaSelectionGroup) {
self._ref = ref
public var defaultOption: MediaSelectionOption? {
_ref.defaultOption.flatMap { .init($0) }
}

public func hash(into hasher: inout Hasher) {
Expand All @@ -40,7 +52,11 @@ public struct MediaSelectionGroup: Hashable, Sendable {
// MARK: - MediaSelectionOption

public struct MediaSelectionOption: Hashable, Sendable {
fileprivate let _ref: AVMediaSelectionOption
let _ref: AVMediaSelectionOption

init(_ ref: AVMediaSelectionOption) {
self._ref = ref
}

public var mediaType: AVMediaType {
_ref.mediaType
Expand All @@ -54,10 +70,6 @@ public struct MediaSelectionOption: Hashable, Sendable {
_ref.isPlayable
}

fileprivate init(_ ref: AVMediaSelectionOption) {
self._ref = ref
}

public func hash(into hasher: inout Hasher) {
hasher.combine(_ref)
}
Expand Down
Loading

0 comments on commit ceeb910

Please sign in to comment.