Skip to content

Commit

Permalink
adapt code to new ndk & foreground service on android 14 type
Browse files Browse the repository at this point in the history
  • Loading branch information
frnandu committed Oct 1, 2024
1 parent 0b14f48 commit adf7887
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 67 deletions.
10 changes: 8 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
<!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
<data android:scheme="nostr" />
</intent-filter>
<!--Add this-->
<service
android:name="id.flutter.flutter_background_service.BackgroundService"
android:foregroundServiceType="dataSync"
/>
<!--end-->
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand All @@ -80,8 +86,8 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE"></uses-permission>-->
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA"></uses-permission>-->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"></uses-permission>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_TYPE_DATA_SYNC"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<!-- For apps with targetSDK=31 (Android 12) -->
Expand Down
2 changes: 2 additions & 0 deletions landing-page/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ <h2><a href="https://github.com/frnandu/yana/releases/latest" target="_blank">Do
<a href="https://github.com/frnandu/yana/releases/latest"><img src="images/ios.png" alt="ios" width="30"/></a>
<a href="https://github.com/frnandu/yana/releases/latest"><img src="images/linux.png" alt="linux" width="30"/></a>
<a href="zapstore://yana.nostr"><img style="height:40px;" src="https://blob.satellite.earth/84dde28e6b2f727ddbb85fdf31ce1fc6c2731edb571444e8fbe0cd0b4ebf2ee8"/></a>
<!--
<h2>or</h2>
<h2><a href="https://app.yana.do" target="_blank">Try the demo web app</a></h2>
-->

<!--End Call to Action-->

Expand Down
6 changes: 3 additions & 3 deletions lib/provider/metadata_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class MetadataProvider extends ChangeNotifier with LaterFunction {
RelaySet? relaySet = settingProvider.gossip == 1 && feedRelaySet != null ? feedRelaySet : myInboxRelaySet;
if (relaySet != null) {
loading = true;
List<Metadata> loaded = await ndk.metadatas.loadMetadatas(_needUpdateMetadatas, relaySet, onLoad: (metadata) {
List<Metadata> loaded = await ndk.metadata.loadMetadatas(_needUpdateMetadatas, relaySet, onLoad: (metadata) {
_needUpdateMetadatas.remove(metadata.pubKey);
notifyListeners();
});
Expand Down Expand Up @@ -126,12 +126,12 @@ class MetadataProvider extends ChangeNotifier with LaterFunction {
if (metadata!=null) {
if (StringUtil.isNotBlank(lud16) && StringUtil.isBlank(metadata.lud16)) {
metadata.lud16 = lud16;
await ndk.metadatas.broadcastMetadata(
await ndk.metadata.broadcastMetadata(
metadata, myInboxRelaySet!.urls, loggedUserSigner!);
}
} else {
metadata ??= Metadata(pubKey: loggedUserSigner!.getPublicKey(), lud16: lud16);
metadata = await ndk.metadatas.broadcastMetadata(metadata, DEFAULT_BOOTSTRAP_RELAYS, loggedUserSigner!);
metadata = await ndk.metadata.broadcastMetadata(metadata, DEFAULT_BOOTSTRAP_RELAYS, loggedUserSigner!);
await cacheManager.saveMetadata(metadata);
notifyListeners();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/new_notifications_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class NewNotificationsProvider extends ChangeNotifier
relaySet: myInboxRelaySet!)
.stream) {
// TODO fix this since it was screwing over received events to handle (metadata mixed)
handleEvent(event, await ndk.metadatas.loadMetadata(event.pubKey));
handleEvent(event, await ndk.metadata.loadMetadata(event.pubKey));
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/router/profile_editor/profile_editor_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class _ProfileEditorRouter extends CustState<ProfileEditorRouter> {
if (cached!=null && cached.refreshedTimestamp!=null && cached.refreshedTimestamp! > (DateTime.now().subtract(REFRESH_METADATA_BEFORE_EDIT_DURATION).millisecondsSinceEpoch ~/ 1000)) {
metadata = cached;
} else {
ndk.metadatas.loadMetadata(
ndk.metadata.loadMetadata(
loggedUserSigner!.getPublicKey(), forceRefresh: true).then((
metadata) {
setState(() {
Expand Down Expand Up @@ -321,7 +321,7 @@ class _ProfileEditorRouter extends CustState<ProfileEditorRouter> {
metadata!.lud16 = lud16Controller.text;
metadata!.lud06 = lud06Controller.text;

await ndk.metadatas.broadcastMetadata(metadata!, myOutboxRelaySet!.urls, loggedUserSigner!);
await ndk.metadata.broadcastMetadata(metadata!, myOutboxRelaySet!.urls, loggedUserSigner!);
metadataProvider.notifyListeners();
setState(() {
broadcasting = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/router/search/search_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class _SearchRouter extends CustState<SearchRouter>
searchAbles.add(SearchActions.openPubkey);
metadatasFromSearch.clear();

ndk.metadatas.loadMetadata(Nip19.decode(text)).then((metadata) {
ndk.metadata.loadMetadata(Nip19.decode(text)).then((metadata) {
setState(() {
if (metadata != null) {
metadatasFromSearch = [metadata];
Expand Down
4 changes: 2 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import package_info_plus
import pasteboard
import path_provider_foundation
import photo_manager
import protocol_handler_macos
import protocol_handler
import screen_retriever
import share_plus
import shared_preferences_foundation
Expand All @@ -45,7 +45,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PasteboardPlugin.register(with: registry.registrar(forPlugin: "PasteboardPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
PhotoManagerPlugin.register(with: registry.registrar(forPlugin: "PhotoManagerPlugin"))
ProtocolHandlerMacosPlugin.register(with: registry.registrar(forPlugin: "ProtocolHandlerMacosPlugin"))
ProtocolHandlerPlugin.register(with: registry.registrar(forPlugin: "ProtocolHandlerPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
Expand Down
56 changes: 8 additions & 48 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ packages:
dependency: "direct main"
description:
name: bip340
sha256: "2a92f6ed68959f75d67c9a304c17928b9c9449587d4f75ee68f34152f7f69e87"
sha256: b7bcd70a860e605046006adaa72bc4f7453f4d31d7ba74a4ad9d5de387a0fc0b
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.3.0"
bolt11_decoder:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1306,10 +1306,10 @@ packages:
dependency: "direct main"
description:
name: ndk
sha256: add1328a9279beca49a3be69a879d1bd8673bccb9808f8eb2f7100e1f250f0f4
sha256: c77f66332020e66b220d835a71b8270da2c25cee971966947169b00a8b0439ab
url: "https://pub.dev"
source: hosted
version: "0.1.0-dev995"
version: "0.1.1"
nested:
dependency: transitive
description:
Expand Down Expand Up @@ -1546,50 +1546,10 @@ packages:
dependency: "direct main"
description:
name: protocol_handler
sha256: dc2e2dcb1e0e313c3f43827ec3fa6d98adee6e17edc0c3923ac67efee87479a9
url: "https://pub.dev"
source: hosted
version: "0.2.0"
protocol_handler_android:
dependency: transitive
description:
name: protocol_handler_android
sha256: "82eb860ca42149e400328f54b85140329a1766d982e94705b68271f6ca73895c"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
protocol_handler_ios:
dependency: transitive
description:
name: protocol_handler_ios
sha256: "0d3a56b8c1926002cb1e32b46b56874759f4dcc8183d389b670864ac041b6ec2"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
protocol_handler_macos:
dependency: transitive
description:
name: protocol_handler_macos
sha256: "6eb8687a84e7da3afbc5660ce046f29d7ecf7976db45a9dadeae6c87147dd710"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
protocol_handler_platform_interface:
dependency: transitive
description:
name: protocol_handler_platform_interface
sha256: "53776b10526fdc25efdf1abcf68baf57fdfdb75342f4101051db521c9e3f3e5b"
sha256: fb1882bd6cf767114f46b4708d1794fcd662e0a9b9b4512519adeaff3f931d7d
url: "https://pub.dev"
source: hosted
version: "0.2.0"
protocol_handler_windows:
dependency: transitive
description:
name: protocol_handler_windows
sha256: d8f3a58938386aca2c76292757392f4d059d09f11439d6d896d876ebe997f2c4
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.1.6"
provider:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1650,10 +1610,10 @@ packages:
dependency: transitive
description:
name: rust_lib_ndk
sha256: "6d4c296204bc57982a2927030212c706a72f924a0383b1910b84518a66a4b8ab"
sha256: f71e61e1a295fbdcac250a88b315518aca1d7a5533684b32e7c9c1b58e989ae7
url: "https://pub.dev"
source: hosted
version: "0.0.4-dev002"
version: "0.1.1"
rxdart:
dependency: transitive
description:
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.15.2+3009
version: 0.15.1+3008
versionCode: 3000

environment:
Expand All @@ -43,7 +43,7 @@ dependencies:
shared_preferences: ^2.1.1
bot_toast: ^4.0.4
flutter_quill: ^8.6.3
bip340: ^0.2.0
bip340: ^0.3.0
string_validator: ^1.0.0
http: ^1.1.0
get_time_ago: ^1.2.2
Expand Down Expand Up @@ -110,7 +110,7 @@ dependencies:
scrollable_positioned_list: ^0.3.8
#js: ^0.6.7
flutter_svg: ^2.0.7
protocol_handler: ^0.2.0
protocol_handler: ^0.1.5
flutter_spinkit: ^5.2.0
isar: ^4.0.0-dev.14
isar_flutter_libs: ^4.0.0-dev.14
Expand All @@ -125,7 +125,7 @@ dependencies:
lottie: ^3.1.2
bolt11_decoder: ^1.0.2

ndk: ^0.1.0
ndk: ^0.1.1
# ndk:
# git:
# url: https://github.com/relaystr/dart_ndk.git
Expand Down
6 changes: 3 additions & 3 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <local_auth_windows/local_auth_plugin.h>
#include <pasteboard/pasteboard_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <protocol_handler_windows/protocol_handler_windows_plugin_c_api.h>
#include <protocol_handler/protocol_handler_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>
Expand All @@ -43,8 +43,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("PasteboardPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
ProtocolHandlerWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ProtocolHandlerWindowsPluginCApi"));
ProtocolHandlerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ProtocolHandlerPlugin"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
Expand Down
2 changes: 1 addition & 1 deletion windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
local_auth_windows
pasteboard
permission_handler_windows
protocol_handler_windows
protocol_handler
screen_retriever
share_plus
url_launcher_windows
Expand Down

0 comments on commit adf7887

Please sign in to comment.