Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implementation of ActionView and ActionController #84

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ format:
dart format --line-length 120 .

build-apk:
flutter build apk
flutter build apk --no-tree-shake-icons
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider alternative approaches to icon management

Instead of disabling tree shaking completely, consider these alternatives:

  1. Explicitly register required icons in your app's initialization
  2. Use proper static icon references
  3. Configure tree shaking rules to preserve specific icons

Example approach for explicit icon registration:

// In your app's initialization
void registerIcons() {
  // Register specific icons that are getting incorrectly tree-shaken
  IconData.registerIcons([
    Icons.specific_icon_1,
    Icons.specific_icon_2,
  ]);
}


tests:
flutter test
Expand Down
7 changes: 1 addition & 6 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ plugins {
id "dev.flutter.flutter-gradle-plugin"
}

android {
ndkVersion = "27.0.12077973"
}


def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -30,7 +25,7 @@ if (flutterVersionName == null) {
android {
namespace "io.xconn.wick_ui"
compileSdk flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
ndkVersion "27.0.12077973"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using flutter.ndkVersion instead of hardcoded value

Hardcoding the NDK version to "27.0.12077973" could lead to maintenance issues and version conflicts. It's recommended to use flutter.ndkVersion to automatically stay in sync with Flutter's requirements.

Apply this diff to improve maintainability:

-    ndkVersion "27.0.12077973"
+    ndkVersion flutter.ndkVersion
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ndkVersion "27.0.12077973"
ndkVersion flutter.ndkVersion


compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
10 changes: 10 additions & 0 deletions lib/app/modules/action/action_binding.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import "package:get/get.dart";

import "package:wick_ui/app/modules/action/action_controller.dart";

class ActionBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<ActionController>(ActionController.new);
}
}
118 changes: 118 additions & 0 deletions lib/app/modules/action/action_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import "package:get/get.dart";
import "package:wick_ui/app/data/models/profile_model.dart";
import "package:wick_ui/utils/session_manager.dart";
import "package:xconn/xconn.dart";

class ActionController extends GetxController {
Rx<ProfileModel?> selectedProfile = Rx<ProfileModel?>(null);
RxString uri = "".obs;
RxString selectedWampMethod = "".obs;
RxString logsMessage = "".obs;

Future<void> setSelectedProfile(ProfileModel profile) async {
selectedProfile.value = profile;
}

String _getCurrentTimestamp() {
final now = DateTime.now();
return now.toIso8601String();
}

void _addLog(String message) {
logsMessage.value += "${_getCurrentTimestamp()} - $message\n";
}

Future<void> performAction(
String actionType,
String uri,
List<String> args,
Map<String, String> kwArgs,
) async {
if (selectedProfile.value != null) {
try {
Logs result;
switch (actionType) {
case "Call":
result = await performCallAction(uri, args, kwArgs);
case "Register":
result = await performRegisterAction(uri, args);
case "Subscribe":
result = await performSubscribeAction(uri);
case "Publish":
result = await performPublishAction(uri, args, kwArgs);
default:
result = Logs(error: "Select Action");
}

if (result.error != null) {
_addLog("Error: ${result.error}");
} else {
_addLog("Success: ${result.data}");
}
} on Exception catch (e) {
_addLog("An exception occurred: $e");
}
} else {
_addLog("Please select a profile first.");
}
}

Future<Logs> performCallAction(
String uri,
List<String> args,
Map<String, String> kwArgs,
) async {
try {
final session = await SessionManager.connect(selectedProfile.value!);
final result = await session.call(uri, args: args, kwargs: kwArgs);
return Logs(data: "args=${result.args}, kwargs=${result.kwargs}");
} on Exception catch (e) {
return Logs(error: "Failed to perform call: $e");
}
}

Future<Logs> performRegisterAction(String uri, List<String> args) async {
try {
final session = await SessionManager.connect(selectedProfile.value!);
final result = await session.register(uri, (Invocation inv) {
final response = Result(args: inv.args, kwargs: inv.kwargs);
_addLog("Register invoked with args=${inv.args}, kwargs=${inv.kwargs}");
return response;
});
return Logs(data: "Register action performed successfully: $result");
} on Exception catch (e) {
return Logs(error: "Failed to perform register: $e");
}
}
Comment on lines +74 to +86
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Unused parameter args in performRegisterAction

The args parameter in the performRegisterAction method is not utilized within the method body. This may lead to confusion or maintenance issues. Consider removing the unused parameter if it's not needed, or implement its usage if it serves a purpose.

Apply this diff to remove the unused parameter:

- Future<Logs> performRegisterAction(String uri, List<String> args) async {
+ Future<Logs> performRegisterAction(String uri) async {
    try {
      final session = await SessionManager.connect(selectedProfile.value!);
      final result = await session.register(uri, (Invocation inv) {
        final response = Result(args: inv.args, kwargs: inv.kwargs);
        _addLog("Register invoked with args=${inv.args}, kwargs=${inv.kwargs}");
        return response;
      });
      return Logs(data: "Register action performed successfully: $result");
    } on Exception catch (e) {
      return Logs(error: "Failed to perform register: $e");
    }
  }

Also, update the method call in performAction accordingly:

case "Register":
-   result = await performRegisterAction(uri, args);
+   result = await performRegisterAction(uri);
    break;

Committable suggestion skipped: line range outside the PR's diff.


Future<Logs> performSubscribeAction(String uri) async {
try {
final session = await SessionManager.connect(selectedProfile.value!);
await session.subscribe(uri, (event) {
_addLog(
"Subscribed event received: args=${event.args}, kwargs=${event.kwargs}",
);
});
return Logs(data: "Subscribed successfully");
} on Exception catch (e) {
return Logs(error: "Failed to subscribe: $e");
}
}

Future<Logs> performPublishAction(String uri, List<String> args, Map<String, String> kwArgs) async {
try {
final session = await SessionManager.connect(selectedProfile.value!);
await session.publish(uri, args: args, kwargs: kwArgs);
return Logs(data: "Publish action performed successfully");
} on Exception catch (e) {
return Logs(error: "Failed to publish: $e");
}
}
}

class Logs {
Logs({this.data, this.error});

final String? data;
final String? error;
}
Loading
Loading