import 'package:electronic_assistant/resource/assets.gen.dart';
import 'package:electronic_assistant/resource/string.gen.dart';
import 'package:electronic_assistant/utils/desktop_shortcut_utils.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:shortcut/shortcut.dart';

class AndroidShortCut {
  AndroidShortCut._();

  final _flutterPinnedShortcutPlugin = FlutterShortcut();

  FlutterShortcut get flutterPinnedShortcutPlugin =>
      _flutterPinnedShortcutPlugin;

  void addRecordShortcut() {
    _flutterPinnedShortcutPlugin.createShortcut(
        id: "electronic_1",
        label: StringName.desktopShortcutRecordName.tr,
        action: LaunchAction.recordAudioAction,
        iconAssetName: Assets.images.logoRecordShortcut.path);
  }

  void register() {
    _flutterPinnedShortcutPlugin.actionStream().listen((action) {
      debugPrint('actionStream: $action');
      switch (action) {
        case LaunchAction.recordAudioAction:
          DesktopShortcutUtils.setRouteAction(LaunchAction.recordAudioAction);
          break;
      }
    });
    _flutterPinnedShortcutPlugin.getLaunchAction((action) {
      debugPrint('getLaunchAction: $action');
      switch (action) {
        case LaunchAction.recordAudioAction:
          DesktopShortcutUtils.setLaunchAction(LaunchAction.recordAudioAction);
          break;
      }
    });
  }
}

final androidShortCut = AndroidShortCut._();
