Skip to content

Commit 6f8f3ae

Browse files
authored
Merge pull request #2 from xuanzhi33:feat-cross-platform
feat: Cross Platform
2 parents 6c8fed4 + a9815bb commit 6f8f3ae

File tree

6 files changed

+138
-24
lines changed

6 files changed

+138
-24
lines changed

.github/release_util.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
import re
2-
from os import getenv, name
2+
import os
33
with open("./src/main.html", "r", encoding="utf-8") as f:
44
content = f.read()
55
pattern = re.compile(r'const VERSION = "([0-9.]+)";')
66
version = pattern.search(content).group(1)
77
print(f"Version: {version}")
88

9-
if name == "nt":
10-
os_name = "Windows"
11-
elif name == "posix":
12-
os_name = "Linux"
13-
elif name == "darwin":
14-
os_name = "macOS"
9+
10+
platforms = {
11+
"nt": "Windows",
12+
"posix": "Linux",
13+
"darwin": "macOS"
14+
}
15+
16+
def get_filename(os_name):
17+
name = platforms[os_name]
18+
return f"SMCL-{version}-{name}.zip"
1519

1620
envs = {
1721
"smcl_version": version,
18-
"smcl_filename": f"SMCL-{version}-{os_name}.zip"
22+
"smcl_filename": get_filename(os.name)
1923
}
2024

21-
download_url = f"https://github.com/xuanzhi33/smcl/releases/download/{version}/{envs['smcl_filename']}"
22-
download_mirror = "https://mirror.ghproxy.com/" + download_url
25+
DOWNLOAD_URL = "https://github.com/xuanzhi33/smcl/releases/download/"
26+
MIRROR = "https://mirror.ghproxy.com/"
27+
28+
download_md = ""
29+
for i in platforms:
30+
os_name = platforms[i]
31+
filename = get_filename(i)
32+
url = f"{MIRROR}{DOWNLOAD_URL}{version}/{filename}"
33+
download_md += f"- {os_name}: [{filename}]({url})\n"
2334

2435
release_notes = f"""
2536
# SMCL {version}
2637
2738
## Download / 下载
28-
- Windows: [{envs['smcl_filename']}]({download_mirror})
29-
39+
{download_md}
3040
## Notes / 说明
3141
- Zip Password / 解压密码: `smcl`
3242
- Please extract and run smcl.exe / 下载后请解压并运行 smcl.exe
@@ -36,7 +46,7 @@
3646
with open("release_notes.md", "w", encoding="utf-8") as f:
3747
f.write(release_notes)
3848

39-
gh_env = getenv("GITHUB_ENV")
49+
gh_env = os.getenv("GITHUB_ENV")
4050

4151
if gh_env is not None:
4252
print(f"Writing: {gh_env}")

.github/workflows/build.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ on:
66

77
jobs:
88
build-and-publish:
9-
runs-on: windows-latest
9+
strategy:
10+
matrix:
11+
os: [windows-latest, ubuntu-latest, macos-latest]
12+
runs-on: ${{ matrix.os }}
1013
permissions:
1114
contents: write
1215
steps:

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ Still under development / 仍在开发中,功能不完善
1212
- [x] Multi-language support / 多语言支持
1313
- [x] Game version management / 游戏版本管理
1414
- [ ] Mod management / 模组管理
15-
- [ ] Cross-platform / 跨平台
16-
- [ ] Java version management / Java 版本管理
15+
- [x] Cross-platform / 跨平台
1716
- [ ] Auto-update / 自动更新
1817

1918
Based on [CMCL](https://github.com/MrShieh-X/console-minecraft-launcher)

smcl.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
SRC_DIR = path.join(PATH, "src")
1414
GUI_MAIN = path.join(SRC_DIR, "main.html")
1515
CMCL_CONFIG = path.join(SRC_DIR, "cmcl.json")
16-
CMCL = path.join(SRC_DIR, "cmcl.exe")
16+
CMCL_PATH = path.join(SRC_DIR, "cmcl.jar")
17+
CMCL_CMD = ["java", "-jar", CMCL_PATH]
1718

1819
SIZE = (800, 450)
1920
DEBUG = True
@@ -49,7 +50,7 @@ def cmd_result(self, result):
4950
resultJson = json.dumps(result)
5051
self.run_js(f"window.cmdResult({resultJson});")
5152
def cmcl_waiting(self, cmd):
52-
args = [CMCL]
53+
args = CMCL_CMD
5354
if cmd is not None:
5455
self.log(f"CMCL: {cmd}")
5556
args += cmd
@@ -98,7 +99,7 @@ def confirm_dialog(self, message, title="SMCL"):
9899
return self._window.create_confirmation_dialog(title, message)
99100
def cmcl(self, args):
100101
self.log(f"CMCL: {args}")
101-
p = sp_run([CMCL] + args, capture_output=True, text=True, startupinfo=self.startupinfo)
102+
p = sp_run(CMCL_CMD + args, capture_output=True, text=True, startupinfo=self.startupinfo)
102103
result = p.stdout
103104
self.log(result)
104105
return result
@@ -150,6 +151,8 @@ def __init__(self) -> None:
150151
self.api = Api()
151152
def start(self):
152153
self.api.log(f"SMCL is starting, DEBUG: {self.isDebug()}")
154+
webview.settings['ALLOW_DOWNLOADS'] = True
155+
153156
window = webview.create_window('SMCL', GUI_MAIN,
154157
width=SIZE[0], height=SIZE[1],
155158
js_api=self.api)

src/cmcl.exe src/cmcl.jar

3.38 MB
Binary file not shown.

src/main.html

+104-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
:init="init"></version-list>
3838
<text-input v-else-if="ui === 'input'" @finish="input.resolveFunc" @close="goBack" :title="input.title"
3939
:desc="input.desc" :placeholder="input.placeholder"></text-input>
40+
<install-java v-else-if="ui === 'installJava'" :show-warning="showWarning"
41+
:ui-init="uiInit"></install-java>
4042
<div v-else-if="ui === 'main'">
4143
<button class="ctrl button account-menu" @click="changeUI('playerList')">
4244
<div style="font-size: 1.2rem; font-weight: bold;">
@@ -366,14 +368,62 @@
366368
</transition>
367369
</template>
368370

371+
<template id="install-java">
372+
<ui-container>
373+
<template #title>
374+
<i class="fa fa-coffee"></i>
375+
{{ $t('javaNotFound') }}
376+
</template>
377+
<template #content>
378+
<div>
379+
{{ $t('tips') }}
380+
</div>
381+
<div class="btn-group mt-2">
382+
<a href="https://download.oracle.com/java/22/latest/jdk-22_windows-x64_bin.exe"
383+
class="btn btn-info">
384+
<i class="fa fa-download"></i>
385+
Windows <br>
386+
</a>
387+
<a href="https://download.oracle.com/java/22/latest/jdk-22_macos-x64_bin.dmg"
388+
class="btn btn-info">
389+
<i class="fa fa-download"></i>
390+
macOS <br>
391+
(Intel)
392+
</a>
393+
<a href="https://download.oracle.com/java/22/latest/jdk-22_macos-aarch64_bin.dmg"
394+
class="btn btn-info">
395+
<i class="fa fa-download"></i>
396+
macOS <br>
397+
(Apple Silicon)
398+
</a>
399+
<a href="https://download.oracle.com/java/22/latest/jdk-22_linux-x64_bin.rpm"
400+
class="btn btn-info">
401+
<i class="fa fa-download"></i>
402+
Linux <br>
403+
(x64)
404+
</a>
405+
<a href="https://download.oracle.com/java/22/latest/jdk-22_linux-aarch64_bin.rpm"
406+
class="btn btn-info">
407+
<i class="fa fa-download"></i>
408+
Linux <br>
409+
(ARM64)
410+
</a>
411+
</div>
412+
<button class="btn btn-success btn-block mt-2" @click="retry">
413+
<i class="fa fa-check"></i> {{ $t('retry') }}
414+
</button>
415+
</template>
416+
</ui-container>
417+
</template>
418+
369419

370420
<!-- TODO: Component templates -->
371421

372422
<script src="./vue.global.prod.js"></script>
373423
<script src="./vue-i18n.global.prod.js"></script>
374424
<script type="module">
375425
// TODO: Version
376-
const VERSION = "0.3.0";
426+
const VERSION = "0.4.0";
377427
const { createApp } = Vue;
378428
const { createI18n } = VueI18n;
379429
let api = null;
@@ -823,6 +873,45 @@
823873
}
824874
};
825875

876+
const InstallJava = {
877+
components: {
878+
UiContainer
879+
},
880+
props: {
881+
uiInit: {
882+
type: Function
883+
},
884+
showWarning: {
885+
type: Function
886+
}
887+
},
888+
template: "#install-java",
889+
methods: {
890+
async retry() {
891+
const res = await this.uiInit();
892+
if (!res) {
893+
this.showWarning(this.$t("javaNotFound"), this.$t("stillFail"));
894+
}
895+
}
896+
},
897+
i18n: {
898+
messages: {
899+
en: {
900+
javaNotFound: "Java not detected",
901+
tips: "Minecraft requires Java Runtime. Please click the button below to download Java installer for your system.",
902+
retry: "I have downloaded and installed Java",
903+
stillFail: "Java still not detected, please try again or restart SMCL"
904+
},
905+
zh: {
906+
javaNotFound: "未检测到 Java",
907+
tips: "Minecraft 需要 Java 运行环境,请点击下方的按钮下载对应的 Java 安装包。",
908+
retry: "我已经下载并安装了 Java",
909+
stillFail: "仍然无法检测到 Java,请再次尝试,或重启 SMCL"
910+
}
911+
}
912+
}
913+
};
914+
826915
// TODO: Components
827916
const app = createApp({
828917
components: {
@@ -831,7 +920,8 @@
831920
Settings,
832921
PlayerList,
833922
VersionList,
834-
TextInput
923+
TextInput,
924+
InstallJava
835925
},
836926
data() {
837927
// TODO: data
@@ -1018,6 +1108,17 @@
10181108
this.downloadSource = config.downloadSource;
10191109
this.gameDir = config.gameDir;
10201110
await api.set_title(`SMCL ${VERSION} - Minecraft: ${curVer} - ${this.$t('player')}: ${playerName} - by xuanzhi33`);
1111+
},
1112+
async uiInit() {
1113+
try {
1114+
await api.init_cmcl();
1115+
await this.init();
1116+
this.ui = "main";
1117+
return true;
1118+
} catch (e) {
1119+
this.ui = "installJava";
1120+
return false;
1121+
}
10211122
}
10221123
},
10231124
watch: {
@@ -1036,9 +1137,7 @@
10361137
},
10371138
async mounted() {
10381139
await this.init_api();
1039-
await api.init_cmcl();
1040-
await this.init();
1041-
this.ui = "main";
1140+
await this.uiInit();
10421141
},
10431142
template: "#main"
10441143
});

0 commit comments

Comments
 (0)