Skip to content

Commit 547f713

Browse files
authored
Merge pull request #4 from xuanzhi33:feat-addons
feat: auto-install Forge, Fabric, OptiFine
2 parents edaf2e1 + 7fb2315 commit 547f713

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ Simple Minecraft Launcher
44

55
Still under development / 仍在开发中,功能不完善
66

7+
## Downloads / 下载
8+
9+
Please go to / 请前往 [Releases](https://github.com/xuanzhi33/smcl/releases)
10+
711
## Features / 特性
812

913
- [x] Beautiful UI / 精美的界面
1014
- [x] Launch Minecraft / 快速启动 Minecraft
1115
- [x] Account management / 游戏账号管理
1216
- [x] Multi-language support / 多语言支持
1317
- [x] Game version management / 游戏版本管理
18+
- [x] Install Forge, Fabric, OptiFine with one click / 一键安装 Forge, Fabric, OptiFine
1419
- [ ] Mod management / 模组管理
1520
- [x] Cross-platform / 跨平台
1621
- [ ] Auto-update / 自动更新

smcl.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ def log(self, message):
101101
def confirm_dialog(self, message, title="SMCL"):
102102
self.log(f"ALERT: {title} - {message}")
103103
return self._window.create_confirmation_dialog(title, message)
104-
def cmcl(self, args):
104+
def cmcl(self, args, stdin = None):
105105
self.log(f"CMCL: {args}")
106-
p = sp_run(CMCL_CMD + args, capture_output=True, text=True, startupinfo=self.startupinfo)
106+
if stdin is not None:
107+
self.log(f"stdin: {stdin}")
108+
p = sp_run(CMCL_CMD + args, capture_output=True, input=stdin,
109+
text=True, startupinfo=self.startupinfo)
107110
result = p.stdout
108111
self.log(result)
109112
return result

src/main.html

+48-11
Original file line numberDiff line numberDiff line change
@@ -293,18 +293,18 @@
293293
</div>
294294
<div class="float-right">
295295
<div class="btn-group btn-group-sm">
296-
<!-- <button class="btn btn-info" @click="$emit('installFunc', 'forge', ver)">
297-
<i class="fa fa-cloud-download"></i>
298-
Forge
299-
</button>
300296
<button class="btn btn-info" @click="$emit('installFunc', 'fabric', ver)">
301297
<i class="fa fa-cloud-download"></i>
302298
Fabric
303299
</button>
300+
<button class="btn btn-info" @click="$emit('installFunc', 'forge', ver)">
301+
<i class="fa fa-cloud-download"></i>
302+
Forge
303+
</button>
304304
<button class="btn btn-info" @click="$emit('installFunc', 'optifine', ver)">
305305
<i class="fa fa-cloud-download"></i>
306306
OptiFine
307-
</button> -->
307+
</button>
308308
<button class="btn btn-danger" @click="deleteVersion(ver)">
309309
<i class="fa fa-trash"></i>
310310
</button>
@@ -423,7 +423,7 @@
423423
<script src="./vue-i18n.global.prod.js"></script>
424424
<script type="module">
425425
// TODO: Version
426-
const VERSION = "0.4.2";
426+
const VERSION = "0.5.0";
427427
const { createApp } = Vue;
428428
const { createI18n } = VueI18n;
429429
let api = null;
@@ -457,7 +457,9 @@
457457
install: "Install Game",
458458
installing: "Installing {ver}...",
459459
downloadingResource: "Downloading resources...",
460-
versionNotFound: "Version not found, please reinstall"
460+
versionNotFound: "Version not found, please reinstall",
461+
installFunc: "Install {type} for {ver}",
462+
installFailed: "Installation Failed"
461463
// TODO: i18n en
462464
},
463465
zh: {
@@ -486,7 +488,9 @@
486488
install: "安装游戏",
487489
installing: "正在安装 {ver}...",
488490
downloadingResource: "正在下载资源文件...",
489-
versionNotFound: "未找到此版本,请重新安装"
491+
versionNotFound: "未找到此版本,请重新安装",
492+
installFunc: "为 {ver} 安装 {type}",
493+
installFailed: "安装失败"
490494
// TODO: i18n zh
491495
}
492496
}
@@ -846,7 +850,7 @@
846850
snapshot: "Snapshot",
847851
oldAlpha: "Old Alpha",
848852
oldBeta: "Old Beta",
849-
deleteConfirm: "Are you sure to delete this version?",
853+
deleteConfirm: "Are you sure to delete this version? This will not affect saves, mods, etc.",
850854
deleteVersion: "Delete Version",
851855
gameFolder: "Game",
852856
savesFolder: "Saves",
@@ -863,7 +867,7 @@
863867
snapshot: "快照版",
864868
oldAlpha: "远古 Alpha 版",
865869
oldBeta: "远古 Beta 版",
866-
deleteConfirm: "确定要删除这个版本吗?",
870+
deleteConfirm: "确定要删除这个版本吗?这不会影响地图、模组等数据。",
867871
deleteVersion: "删除版本",
868872
gameFolder: "游戏",
869873
savesFolder: "地图",
@@ -980,10 +984,43 @@
980984
});
981985
const res = await api.cmcl_waiting(["install", ver]);
982986
await this.finishLoading();
987+
const resList = res.split("\n");
988+
if (resList.length == 2) {
989+
const warn = resList[0];
990+
this.showWarning(this.$t("installFailed"), warn);
991+
}
983992
},
984993

985-
// TODO: Install xxx
994+
// TODO: InstallFunc
995+
async installFunc(type, ver) {
986996

997+
await this.startLoading(this.$t("installFunc", { type, ver }),
998+
this.$t("installing", { ver: type }), (result, loading) => {
999+
1000+
const msg = result.replace(/\u0008/g, "").replace(/\(\d+%\)/g, "");
1001+
console.log(msg);
1002+
1003+
1004+
loading.log = msg;
1005+
loading.progress += 5;
1006+
1007+
});
1008+
1009+
const res = await api.cmcl(["version", ver, `--${type}`], "");
1010+
console.log(res);
1011+
const reg = /\(.+(\d+\.\d+\.\d+)\)/;
1012+
const match = reg.exec(res);
1013+
if (!match) {
1014+
this.finishLoading();
1015+
this.showWarning(this.$t("installFailed"), res);
1016+
return;
1017+
}
1018+
1019+
const version = match[1];
1020+
await api.cmcl_waiting(["version", ver, `--${type}=${version}`]);
1021+
1022+
await this.finishLoading();
1023+
},
9871024

9881025
async addOfflineAccount() {
9891026
const name = await this.requestInput(

0 commit comments

Comments
 (0)