-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: Simple launch function implement
- Loading branch information
Showing
8 changed files
with
85 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:nyalcf/utils/state.dart'; | ||
import 'package:nyalcf/utils/templates/command_implement.dart'; | ||
import 'package:nyalcf_core/utils/logger.dart'; | ||
import 'package:nyalcf_core/storages/stores/frpc_storage.dart'; | ||
|
||
class Start implements CommandImplement { | ||
@override | ||
Future<void> main(List<String> args) async { | ||
if (args.isNotEmpty) { | ||
final user = await userInfo; | ||
if (user != null) { | ||
for (var proxyId in args) { | ||
final frpcPath = await FrpcStorage().getFilePath(); | ||
final runPath = await FrpcStorage().getRunPath(); | ||
|
||
if (frpcPath != null) { | ||
final process = await Process.start( | ||
frpcPath, | ||
[ | ||
'-u', | ||
user.frpToken, | ||
'-p', | ||
proxyId, | ||
], | ||
workingDirectory: runPath, | ||
); | ||
process.stdout.forEach((List<int> element) { | ||
final RegExp regex = RegExp(r'\x1B\[[0-9;]*[mK]'); | ||
final String fmtStr = utf8.decode(element).trim().replaceAll(regex, ''); | ||
Logger.frpcInfo(proxyId, fmtStr); | ||
}); | ||
process.stderr.forEach((List<int> element) { | ||
final RegExp regex = RegExp(r'\x1B\[[0-9;]*[mK]'); | ||
final String fmtStr = utf8.decode(element).trim().replaceAll(regex, ''); | ||
Logger.frpcError(proxyId, fmtStr); | ||
}); | ||
Logger.info('Started proxy: $proxyId'); | ||
} else { | ||
Logger.error('You have no frpc installed yet!'); | ||
} | ||
} | ||
} else { | ||
Logger.error('You have no login session yet!'); | ||
} | ||
} else { | ||
Logger.error('No valid arguments provided.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:nyalcf_core/models/user_info_model.dart'; | ||
import 'package:nyalcf_core/storages/stores/user_info_storage.dart'; | ||
import 'package:nyalcf_inject/path_provider.dart'; | ||
|
||
bool verbose = false; | ||
|
||
Future<UserInfoModel?> get userInfo async => | ||
await File('$appSupportPath/session.json').exists() | ||
? await UserInfoStorage.read() | ||
: null; |
6 changes: 0 additions & 6 deletions
6
...lib/utils/template/command_implement.dart → ...ib/utils/templates/command_implement.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
abstract class CommandImplement { | ||
|
||
bool result = false; | ||
|
||
/// 入口函数 | ||
void main(List<String> args); | ||
|
||
/// 执行完毕结果 | ||
bool end(); | ||
} |