Skip to content

Commit

Permalink
tvOS Top Shelf (libretro#16302)
Browse files Browse the repository at this point in the history
This puts the History and Favorites playlists (up to five items each)
in the Top Shelf menu. In order for this to be enabled you must build
it yourself and change the app identifiers for the TV app and Top
Shelf extension, and add both of them to an app group.
  • Loading branch information
warmenhoven authored Feb 28, 2024
1 parent 0df031a commit 7379d33
Show file tree
Hide file tree
Showing 18 changed files with 457 additions and 1 deletion.
3 changes: 3 additions & 0 deletions menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -5941,6 +5941,9 @@ static int action_ok_delete_entry(const char *path,
{
playlist_delete_index(playlist, menu->rpl_entry_selection_ptr);
playlist_write_file(playlist);
#if TARGET_OS_TV
update_topshelf();
#endif
}

new_selection_ptr = menu_st->selection_ptr;
Expand Down
3 changes: 3 additions & 0 deletions menu/menu_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -8700,6 +8700,9 @@ static void general_write_handler(rarch_setting_t *setting)
* playlist file (to update maximum capacity) */
retroarch_favorites_deinit();
retroarch_favorites_init();
#if TARGET_OS_TV
update_topshelf();
#endif
}
}
break;
Expand Down
17 changes: 17 additions & 0 deletions pkg/apple/RetroArchTopShelfExtension/ContentProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ContentProvider.h
// RetroArchTopShelfExtension
//
// Created by Eric Warmenhoven on 2/17/24.
// Copyright © 2024 RetroArch. All rights reserved.
//

#import <TVServices/TVServices.h>

#define kRetroArchAppGroup @"group.com.libretro.dist.tvos.RetroArchAppGroup"

@interface ContentProvider : TVTopShelfContentProvider


@end

43 changes: 43 additions & 0 deletions pkg/apple/RetroArchTopShelfExtension/ContentProvider.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// ContentProvider.m
// RetroArchTopShelfExtension
//
// Created by Eric Warmenhoven on 2/17/24.
// Copyright © 2024 RetroArch. All rights reserved.
//

#import "ContentProvider.h"

@implementation ContentProvider

- (void)loadTopShelfContentWithCompletionHandler:(void (^) (id<TVTopShelfContent> content))completionHandler
{
NSUserDefaults *ud = [[NSUserDefaults alloc] initWithSuiteName:kRetroArchAppGroup];

NSDictionary *contentDict = [ud objectForKey:@"topshelf"];

NSMutableArray *collections = [NSMutableArray arrayWithCapacity:[contentDict count]];
for (NSString *key in [contentDict allKeys])
{
NSArray *contentArray = [contentDict objectForKey:key];
NSMutableArray *items = [NSMutableArray arrayWithCapacity:[contentArray count]];

for (NSDictionary *item in contentArray)
{
TVTopShelfSectionedItem *tsitem = [[TVTopShelfSectionedItem alloc] initWithIdentifier:item[@"id"]];
tsitem.title = item[@"title"];
[tsitem setImageURL:[NSURL URLWithString:item[@"img"]] forTraits:(TVTopShelfItemImageTraitScreenScale1x | TVTopShelfItemImageTraitScreenScale2x)];
[tsitem setImageShape:TVTopShelfSectionedItemImageShapeSquare];
[tsitem setDisplayAction:[[TVTopShelfAction alloc] initWithURL:[NSURL URLWithString:item[@"play"]]]];
[items addObject:tsitem];
}

TVTopShelfItemCollection<TVTopShelfSectionedItem *> *collection = [[TVTopShelfItemCollection alloc] initWithItems:items];
collection.title = key;
[collections addObject:collection];
}
TVTopShelfSectionedContent *content = [[TVTopShelfSectionedContent alloc] initWithSections:collections];
completionHandler(content);
}

@end
13 changes: 13 additions & 0 deletions pkg/apple/RetroArchTopShelfExtension/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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.tv-top-shelf</string>
<key>NSExtensionPrincipalClass</key>
<string>ContentProvider</string>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?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/>
</plist>
Loading

0 comments on commit 7379d33

Please sign in to comment.