Skip to content

Commit

Permalink
bump core again
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBeastLT committed Nov 11, 2023
1 parent 409dd35 commit 085acd8
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 63 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/commonMain/rust/bridge/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl FromProtobuf<Action> for runtime::Action {
Some(action_ctx::Args::InstallTraktAddon(_args)) => {
Action::Ctx(ActionCtx::InstallTraktAddon)
}
Some(action_ctx::Args::LogoutTrakt(_args)) => Action::Ctx(ActionCtx::LogoutTrakt),
Some(action_ctx::Args::UpgradeAddon(descriptor)) => {
Action::Ctx(ActionCtx::UpgradeAddon(descriptor.from_protobuf()))
}
Expand All @@ -49,6 +50,12 @@ impl FromProtobuf<Action> for runtime::Action {
Some(action_ctx::Args::RewindLibraryItem(id)) => {
Action::Ctx(ActionCtx::RewindLibraryItem(id.to_owned()))
}
Some(action_ctx::Args::ToggleLibraryItemNotifications(args)) => Action::Ctx(
ActionCtx::ToggleLibraryItemNotifications(args.id.to_owned(), args.toggle),
),
Some(action_ctx::Args::DismissNotificationItem(id)) => {
Action::Ctx(ActionCtx::DismissNotificationItem(id.to_owned()))
}
Some(action_ctx::Args::PushUserToApi(_args)) => {
Action::Ctx(ActionCtx::PushUserToAPI)
}
Expand All @@ -64,6 +71,9 @@ impl FromProtobuf<Action> for runtime::Action {
Some(action_ctx::Args::SyncLibraryWithApi(_args)) => {
Action::Ctx(ActionCtx::SyncLibraryWithAPI)
}
Some(action_ctx::Args::PullNotifications(_args)) => {
Action::Ctx(ActionCtx::PullNotifications)
}
None => unimplemented!("ActionCtx missing"),
},
Some(runtime::action::Type::Link(action_link)) => match &action_link.args {
Expand Down Expand Up @@ -211,6 +221,13 @@ impl FromProtobuf<Action> for runtime::Action {
Action::Load(ActionLoad::Player(Box::new(selected.from_protobuf())))
}
Some(action_load::Args::Link(_args)) => Action::Load(ActionLoad::Link),
Some(action_load::Args::DataExport(_args)) => Action::Load(ActionLoad::DataExport),
Some(action_load::Args::Notifications(_args)) => {
Action::Load(ActionLoad::Notifications)
}
Some(action_load::Args::LocalSearch(_args)) => {
Action::Load(ActionLoad::LocalSearch)
}
None => unimplemented!("ActionLoad missing"),
},
Some(runtime::action::Type::Unload(_args)) => Action::Unload,
Expand Down
34 changes: 34 additions & 0 deletions src/commonMain/rust/bridge/loadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,40 @@ impl
}
}

impl
ToProtobuf<
models::loadable_stream::Content,
(&Ctx, &String, &ResourceRequest, Option<&ResourceRequest>),
> for Loadable<Option<Stream>, ResourceError>
{
fn to_protobuf(
&self,
(ctx, addon_name, stream_request, meta_request): &(
&Ctx,
&String,
&ResourceRequest,
Option<&ResourceRequest>,
),
) -> models::loadable_stream::Content {
match &self {
Loadable::Ready(ready) => {
models::loadable_stream::Content::Ready(models::OptionStream {
stream: ready.to_protobuf(&(
Some(*ctx),
Some(*addon_name),
Some(*stream_request),
*meta_request,
)),
})
}
Loadable::Err(error) => models::loadable_stream::Content::Error(models::Error {
message: error.to_string(),
}),
Loadable::Loading => models::loadable_stream::Content::Loading(models::Loading {}),
}
}
}

impl ToProtobuf<models::loadable_subtitles::Content, Option<&String>>
for Loadable<Vec<Subtitles>, ResourceError>
{
Expand Down
55 changes: 31 additions & 24 deletions src/commonMain/rust/bridge/resource_loadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use stremio_core::types::addon::{DescriptorPreview, ResourceRequest};
use stremio_core::types::library::LibraryItem;
use stremio_core::types::resource::{MetaItem, MetaItemPreview, Stream, Subtitles};
use stremio_watched_bitfield::WatchedBitField;
use url::Url;

use crate::bridge::ToProtobuf;
use crate::protobuf::stremio::core::models;
Expand Down Expand Up @@ -54,14 +55,7 @@ impl ToProtobuf<models::LoadableMetaItem, (&Ctx, Option<&LibraryItem>, Option<&W
&self,
(ctx, library_item, watched): &(&Ctx, Option<&LibraryItem>, Option<&WatchedBitField>),
) -> models::LoadableMetaItem {
let addon_name = ctx
.profile
.addons
.iter()
.find(|addon| addon.transport_url == self.request.base)
.map(|addon| &addon.manifest.name)
.cloned()
.unwrap_or_default();
let addon_name = get_addon_name(ctx, &self.request.base);
models::LoadableMetaItem {
title: addon_name.to_string(),
request: self.request.to_protobuf(&()),
Expand All @@ -82,14 +76,7 @@ impl ToProtobuf<models::LoadableStreams, (&Ctx, Option<&ResourceRequest>)>
&self,
(ctx, meta_request): &(&Ctx, Option<&ResourceRequest>),
) -> models::LoadableStreams {
let addon_name = ctx
.profile
.addons
.iter()
.find(|addon| addon.transport_url == self.request.base)
.map(|addon| &addon.manifest.name)
.cloned()
.unwrap_or_default();
let addon_name = get_addon_name(ctx, &self.request.base);
models::LoadableStreams {
title: addon_name.to_owned(),
request: self.request.to_protobuf(&()),
Expand All @@ -100,16 +87,26 @@ impl ToProtobuf<models::LoadableStreams, (&Ctx, Option<&ResourceRequest>)>
}
}

impl ToProtobuf<models::LoadableStream, (&Ctx, Option<&ResourceRequest>)>
for ResourceLoadable<Option<Stream>>
{
fn to_protobuf(
&self,
(ctx, meta_request): &(&Ctx, Option<&ResourceRequest>),
) -> models::LoadableStream {
let addon_name = get_addon_name(ctx, &self.request.base);
models::LoadableStream {
request: self.request.to_protobuf(&()),
content: self
.content
.to_protobuf(&(ctx, &addon_name, &self.request, *meta_request)),
}
}
}

impl ToProtobuf<models::LoadableSubtitles, Ctx> for ResourceLoadable<Vec<Subtitles>> {
fn to_protobuf(&self, ctx: &Ctx) -> models::LoadableSubtitles {
let addon_name = ctx
.profile
.addons
.iter()
.find(|addon| addon.transport_url == self.request.base)
.map(|addon| &addon.manifest.name)
.cloned()
.unwrap_or_default();
let addon_name = get_addon_name(ctx, &self.request.base);
models::LoadableSubtitles {
title: addon_name.to_owned(),
request: self.request.to_protobuf(&()),
Expand All @@ -135,3 +132,13 @@ impl ToProtobuf<models::LoadableDescriptor, Ctx> for DescriptorLoadable {
}
}
}

fn get_addon_name(ctx: &Ctx, addon_url: &Url) -> String {
ctx.profile
.addons
.iter()
.find(|addon| &addon.transport_url == addon_url)
.map(|addon| &addon.manifest.name)
.cloned()
.unwrap_or_default()
}
25 changes: 1 addition & 24 deletions src/commonMain/rust/model/fields/meta_details.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use boolinator::Boolinator;
use stremio_core::deep_links::MetaItemDeepLinks;
use stremio_core::models::common::Loadable;
use stremio_core::models::ctx::Ctx;
use stremio_core::models::meta_details::{MetaDetails, Selected};
use stremio_core::runtime::Env;
Expand Down Expand Up @@ -218,23 +217,6 @@ impl ToProtobuf<models::MetaDetails, Ctx> for MetaDetails {
})
.unwrap_or_else(|| meta_item.preview.name.to_owned())
});
let suggested_stream_request =
self.suggested_stream.as_ref().and_then(|suggested_stream| {
streams
.iter()
.find(|resource| match &resource.content {
Some(Loadable::Ready(streams)) => streams.contains(suggested_stream),
_ => false,
})
.map(|resource| &resource.request)
});
let suggested_stream_addon_name = suggested_stream_request.and_then(|stream_request| {
ctx.profile
.addons
.iter()
.find(|addon| addon.transport_url == stream_request.base)
.map(|addon| &addon.manifest.name)
});
models::MetaDetails {
selected: self.selected.to_protobuf(&()),
title,
Expand All @@ -244,12 +226,7 @@ impl ToProtobuf<models::MetaDetails, Ctx> for MetaDetails {
self.watched.as_ref(),
)),
streams: streams.to_protobuf(&(ctx, meta_request)),
suggested_stream: self.suggested_stream.to_protobuf(&(
Some(ctx),
suggested_stream_addon_name,
suggested_stream_request,
meta_request,
)),
suggested_stream: self.suggested_stream.to_protobuf(&(ctx, meta_request)),
}
}
}
15 changes: 14 additions & 1 deletion src/main/proto/stremio/core/models/meta_details.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ message MetaDetails {
optional string title = 2;
optional LoadableMetaItem meta_item = 3;
repeated LoadableStreams streams = 4;
optional stremio.core.types.Stream suggested_stream = 5;
optional LoadableStream suggested_stream = 5;

message Selected {
required stremio.core.types.ResourcePath meta_path = 1;
Expand Down Expand Up @@ -45,4 +45,17 @@ message LoadableStreams {

message Streams {
repeated stremio.core.types.Stream streams = 1;
}

message LoadableStream {
required stremio.core.types.ResourceRequest request = 1;
oneof content {
Loading loading = 2;
Error error = 3;
OptionStream ready = 4;
}
}

message OptionStream {
optional stremio.core.types.Stream stream = 1;
}
31 changes: 20 additions & 11 deletions src/main/proto/stremio/core/runtime/action_ctx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@ message ActionCtx {
google.protobuf.Empty logout = 2;
stremio.core.types.Descriptor install_addon = 3;
google.protobuf.Empty install_trakt_addon = 4;
stremio.core.types.Descriptor upgrade_addon = 5;
stremio.core.types.Descriptor uninstall_addon = 6;
stremio.core.types.Profile.Settings update_settings = 7;
stremio.core.types.MetaItemPreview add_to_library = 8;
string remove_from_library = 9;
string rewind_library_item = 10;
google.protobuf.Empty push_user_to_api = 11;
google.protobuf.Empty pull_user_from_api = 12;
google.protobuf.Empty push_addons_to_api = 13;
google.protobuf.Empty pull_addons_from_api = 14;
google.protobuf.Empty sync_library_with_api = 15;
google.protobuf.Empty logout_trakt = 5;
stremio.core.types.Descriptor upgrade_addon = 6;
stremio.core.types.Descriptor uninstall_addon = 7;
stremio.core.types.Profile.Settings update_settings = 8;
stremio.core.types.MetaItemPreview add_to_library = 9;
string remove_from_library = 10;
string rewind_library_item = 11;
LibraryItemToggle toggle_library_item_notifications = 12;
string dismiss_notification_item = 13;
google.protobuf.Empty push_user_to_api = 14;
google.protobuf.Empty pull_user_from_api = 15;
google.protobuf.Empty push_addons_to_api = 16;
google.protobuf.Empty pull_addons_from_api = 17;
google.protobuf.Empty sync_library_with_api = 18;
google.protobuf.Empty pull_notifications = 19;
}

message LibraryItemToggle {
required string id = 1;
required bool toggle = 2;
}
}
3 changes: 3 additions & 0 deletions src/main/proto/stremio/core/runtime/action_load.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ message ActionLoad {
stremio.core.models.MetaDetails.Selected meta_details = 7;
stremio.core.models.Player.Selected player = 8;
google.protobuf.Empty link = 9;
google.protobuf.Empty data_export = 10;
google.protobuf.Empty notifications = 11;
google.protobuf.Empty local_search = 12;
}
}

0 comments on commit 085acd8

Please sign in to comment.