-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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()) { | ||||||
|
@@ -30,7 +25,7 @@ if (flutterVersionName == null) { | |||||
android { | ||||||
namespace "io.xconn.wick_ui" | ||||||
compileSdk flutter.compileSdkVersion | ||||||
ndkVersion flutter.ndkVersion | ||||||
ndkVersion "27.0.12077973" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Apply this diff to improve maintainability: - ndkVersion "27.0.12077973"
+ ndkVersion flutter.ndkVersion 📝 Committable suggestion
Suggested change
|
||||||
|
||||||
compileOptions { | ||||||
sourceCompatibility JavaVersion.VERSION_1_8 | ||||||
|
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); | ||
} | ||
} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Unused parameter The 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 case "Register":
- result = await performRegisterAction(uri, args);
+ result = await performRegisterAction(uri);
break;
|
||
|
||
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; | ||
} |
There was a problem hiding this comment.
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:
Example approach for explicit icon registration: