Skip to content

Commit ee09043

Browse files
committed
Ability to run the project
Now you can provide Run Configurations for each platform in the solution JSON
1 parent 4032108 commit ee09043

File tree

2 files changed

+75
-9
lines changed

2 files changed

+75
-9
lines changed

lib/editor.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class _EditorPageState extends State<EditorPage> {
165165
void openFile(String filepath) async {
166166
var filename = path.basename(filepath);
167167
var content = await File(filepath).readAsString();
168-
debugPrint(content);
168+
//debugPrint(content);
169169
content = content.replaceAll("\t", " ");
170170
setState(() {
171171
var language = 'javascript';
@@ -211,6 +211,11 @@ class _EditorPageState extends State<EditorPage> {
211211
title: null,
212212
centerTitle: false,
213213
actions: [
214+
IconButton(
215+
onPressed: () => {project.run()},
216+
icon: const Icon(FontAwesomeIcons.play),
217+
tooltip: "Run Project",
218+
),
214219
IconButton(
215220
onPressed: () => {Navigator.pop(context)},
216221
icon: const Icon(FontAwesomeIcons.timesCircle),

lib/util/cc_project_structure.dart

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import 'dart:convert';
32
import 'dart:io';
43
import 'dart:ui';
@@ -12,29 +11,59 @@ import 'modules_manager.dart';
1211
class CCSolution {
1312
final String name, desc, author, identifier, slnPath, slnFolderPath;
1413
DateTime dateModified;
15-
Widget? get image{
14+
List<RunConfiguration> runConfig;
15+
int currentRunConfig = 0;
16+
17+
Widget? get image {
1618
var module = ModulesManager.getModuleByIdentifier(identifier);
17-
if(module != null) {
19+
if (module != null) {
1820
return module.icon;
1921
}
2022
}
23+
2124
Map<String, String> folders = {};
2225
List<CCProject> projects = [];
2326

2427
static const decoder = JsonDecoder();
2528

2629
CCSolution(this.name, this.desc, this.author, this.identifier, this.slnPath,
27-
this.slnFolderPath, this.dateModified);
30+
this.slnFolderPath, this.dateModified, this.runConfig);
2831

29-
static Future<CCSolution?> loadFromFile(String filepath) async{
32+
void run() async {
33+
34+
if (Platform.isWindows) {
35+
debugPrint(
36+
"[CC Debug] starting project on windows config `${runConfig[currentRunConfig].executable}` on $slnFolderPath");
37+
if (runConfig[currentRunConfig].type == "process") {
38+
var result = await Process.run(
39+
runConfig[currentRunConfig].executable, runConfig[currentRunConfig].arguments,
40+
workingDirectory: slnFolderPath);
41+
debugPrint("[STDOUT] ${result.stdout}");
42+
debugPrint("[STDERR] ${result.stderr}");
43+
}
44+
}
45+
}
46+
47+
static Future<CCSolution?> loadFromFile(String filepath) async {
3048
var file = File(filepath);
3149
if (await file.exists()) {
3250
var stat = await file.stat();
3351
String input = await file.readAsString();
3452
try {
3553
var obj = decoder.convert(input);
36-
var result = CCSolution(obj["name"], obj["description"] ?? "",
37-
obj["author"], obj["identifier"], filepath, file.parent.path, stat.modified);
54+
List<RunConfiguration> runConfigs = [];
55+
if(obj["run_config"] is Map) {
56+
runConfigs = RunConfiguration.loadFromJSON(obj["run_config"]);
57+
}
58+
var result = CCSolution(
59+
obj["name"],
60+
obj["description"] ?? "",
61+
obj["author"],
62+
obj["identifier"],
63+
filepath,
64+
file.parent.path,
65+
stat.modified,
66+
runConfigs);
3867

3968
/// Add the solution project folders
4069
var folders = (obj["folders"] as Map);
@@ -55,6 +84,38 @@ class CCSolution {
5584

5685
class CCProject {
5786
final String name, desc, author, identifier, slnPath, slnFolderPath, projPath;
87+
5888
CCProject(this.name, this.desc, this.author, this.identifier, this.slnPath,
5989
this.slnFolderPath, this.projPath);
60-
}
90+
}
91+
92+
class RunConfiguration {
93+
String name, type, executable;
94+
List<String> arguments;
95+
96+
RunConfiguration(this.name, this.type, this.executable, this.arguments);
97+
98+
static List<RunConfiguration> loadFromJSON(Map json) {
99+
var result = <RunConfiguration>[];
100+
if (json.containsKey("windows") && Platform.isWindows) {
101+
try {
102+
for (var obj in json["windows"] as List) {
103+
var name = obj["name"] ?? "runConfig.name";
104+
var type = obj["type"] ?? "unknown";
105+
var executable = obj["executable"] ?? "runConfig.executable";
106+
var _args = (obj["args"] ?? []) as List;
107+
var args = <String>[];
108+
for(var arg in _args){
109+
args.add(arg);
110+
}
111+
result.add(RunConfiguration(name, type, executable, args));
112+
}
113+
} catch (err) {
114+
debugPrint(err.toString());
115+
}
116+
}
117+
118+
//TODO: implement android run config
119+
return result;
120+
}
121+
}

0 commit comments

Comments
 (0)