import 'dart:async';

import 'package:oto/oto/application.dart';
import 'package:oto/oto/commands/command.dart';
import 'package:oto/oto/data/command_data.dart';

class ExecuteApp extends Command {
  @override
  Future execute(DataCommand command) async {
    var data = DataExecuteApp.fromJson(command.param);

    var exe = replaceTag(data.executable);
    var desktop = replaceTag(data.desktopServicePath);
    Application.log('Process Start: $exe');
    var content = 'start "" "$exe" & exit';

    var buffer = StringBuffer(content);
    var processData = await runtime.run(buffer, workspace: desktop);
    return complete(processData.exitCode, command);
  }
}
