-
Notifications
You must be signed in to change notification settings - Fork 789
切换语言后提示用户重启软件 #4380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
切换语言后提示用户重启软件 #4380
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
d2dbd96
封装重启功能
hmr-BH cf90ede
实现语言切换后提示用户重启的功能
hmr-BH 599e0b3
更换为封装后的API
hmr-BH ee05c8f
为重启提示窗添加更多语言支持
hmr-BH fa4efc9
Update Restarter.java
hmr-BH 95458af
feat: 实现启动界面的“小提示”内容
hmr-BH 4d8e756
修改占位的默认值的格式
hmr-BH b70ca5d
优化英文翻译的标点符号的使用
hmr-BH b7d538c
每隔两秒更换”小提示“。优化换行算法
hmr-BH 864f38f
带有”保底“机制的随机”小贴士“生成算法
hmr-BH 9595378
修改随机类命名
hmr-BH b727b67
删除旧的方法封装
hmr-BH 74ed377
对齐启动面板底部组件
hmr-BH b9caaa9
update
Glavo 14fa99f
修改样式使用错误
hmr-BH 0fbf56a
Merge branch 'main' of https://github.com/hmr-BH/HMCL
hmr-BH 5990b27
Revert "update"
hmr-BH 44b0b20
Reapply "update"
hmr-BH 44cd222
还原对update相关重启代码的修改
hmr-BH fc82cfc
按照新版规范添加翻译文件占位
hmr-BH d16df4e
Merge branch 'main' into main
hmr-BH cac3fd7
换用HTML标签的doc,删除restartWithLocale方法
hmr-BH 5229c78
Merge branch 'main' of https://github.com/hmr-BH/HMCL
hmr-BH 9e79c94
规范代码内容
hmr-BH 80c9290
Merge branch 'main' into main
hmr-BH 5ceb561
重构并优化代码逻辑
hmr-BH 59a4d04
将i18n文本迁移到json文件
hmr-BH 86223b7
Merge branch 'HMCL-dev:main' into main
hmr-BH 6a383c4
Merge pull request #1 from hmr-BH/tips
hmr-BH 123f76f
支持使用json文件中的小提示文本
hmr-BH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| */ | ||
| package org.jackhuang.hmcl.ui.main; | ||
|
|
||
| import com.jfoenix.controls.JFXButton; | ||
| import javafx.application.Platform; | ||
| import javafx.beans.InvalidationListener; | ||
| import javafx.beans.WeakInvalidationListener; | ||
|
|
@@ -32,10 +33,12 @@ | |
| import org.jackhuang.hmcl.upgrade.UpdateChannel; | ||
| import org.jackhuang.hmcl.upgrade.UpdateChecker; | ||
| import org.jackhuang.hmcl.upgrade.UpdateHandler; | ||
| import org.jackhuang.hmcl.util.Restarter; | ||
| import org.jackhuang.hmcl.util.StringUtils; | ||
| import org.jackhuang.hmcl.util.i18n.Locales; | ||
| import org.jackhuang.hmcl.util.io.FileUtils; | ||
| import org.jackhuang.hmcl.util.io.IOUtils; | ||
| import org.jackhuang.hmcl.util.logging.Level; | ||
| import org.tukaani.xz.XZInputStream; | ||
|
|
||
| import java.io.File; | ||
|
|
@@ -62,13 +65,48 @@ public final class SettingsPage extends SettingsView { | |
|
|
||
| private InvalidationListener updateListener; | ||
|
|
||
| private boolean ignoreLanguageChange = false; | ||
|
|
||
| public SettingsPage() { | ||
| FXUtils.smoothScrolling(scroll); | ||
|
|
||
| // ==== Languages ==== | ||
| cboLanguage.getItems().setAll(Locales.LOCALES); | ||
| selectedItemPropertyFor(cboLanguage).bindBidirectional(config().localizationProperty()); | ||
|
|
||
| cboLanguage.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { | ||
| if (ignoreLanguageChange) return; | ||
|
|
||
| if (oldValue != null && newValue != null && !oldValue.equals(newValue)) { | ||
| JFXButton restartButton = new JFXButton(i18n("button.restart")); | ||
| restartButton.getStyleClass().add("dialog-accept"); | ||
| restartButton.setOnAction(e -> { | ||
| try { | ||
| Restarter.builder().restart(); | ||
| } catch (IOException ex) { | ||
| LOG.log(Level.WARNING, "Failed to restart", ex); | ||
| ignoreLanguageChange = true; | ||
| cboLanguage.getSelectionModel().select(oldValue); | ||
| ignoreLanguageChange = false; | ||
| } | ||
| }); | ||
|
|
||
| Runnable cancelAction = () -> { | ||
| ignoreLanguageChange = true; | ||
| cboLanguage.getSelectionModel().select(newValue); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里的意义是什么?这时候 |
||
| ignoreLanguageChange = false; | ||
| }; | ||
|
|
||
| Controllers.confirmAction( | ||
| i18n("settings.launcher.language.restart"), | ||
| i18n("message.info"), | ||
| MessageType.INFO, | ||
| restartButton, | ||
| cancelAction | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| disableAutoGameOptionsPane.selectedProperty().bindBidirectional(config().disableAutoGameOptionsProperty()); | ||
| // ==== | ||
|
|
||
|
|
||
105 changes: 105 additions & 0 deletions
105
HMCL/src/main/java/org/jackhuang/hmcl/util/Restarter.java
This file contains hidden or 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,105 @@ | ||
| /* | ||
| * Hello Minecraft! Launcher | ||
| * Copyright (C) 2020 huangyuhui <[email protected]> and contributors | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| package org.jackhuang.hmcl.util; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.jackhuang.hmcl.EntryPoint; | ||
| import org.jackhuang.hmcl.java.JavaRuntime; | ||
| import org.jackhuang.hmcl.util.io.JarUtils; | ||
|
|
||
| /** | ||
| * <p>A common restart tool class, used for:</p> | ||
| * <ul> | ||
| * <li>Restart after update</li> | ||
| * <li>Restart after switching interface language</li> | ||
| * <li>Any scenario that requires a restart to take effect</li> | ||
| * </ul> | ||
| */ | ||
| public final class Restarter { | ||
|
|
||
| private final List<String> jvmOptions = new ArrayList<>(); | ||
| private final List<String> programArgs = new ArrayList<>(); | ||
| private Path jarPath; | ||
|
|
||
| private Restarter() { } | ||
|
|
||
| public static Restarter builder() { | ||
| return new Restarter(); | ||
| } | ||
|
|
||
| public Restarter addSystemProperty(String key, String value) { | ||
| jvmOptions.add("-D" + key + "=" + value); | ||
| return this; | ||
| } | ||
|
|
||
| public Restarter addProgramArguments(List<String> args) { | ||
| programArgs.addAll(args); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * <p> | ||
| * Set the JAR path to start | ||
| * If not, the current running JAR will be used by default | ||
| * </p> | ||
| */ | ||
| public Restarter setJarPath(Path jarPath) { | ||
| this.jarPath = jarPath; | ||
| return this; | ||
| } | ||
|
|
||
| public void restart() throws IOException { | ||
| Path jar = this.jarPath; | ||
| if (jar == null) { | ||
| jar = JarUtils.thisJarPath(); | ||
| } | ||
| if (jar == null) { | ||
| throw new IOException("Cannot locate JAR file"); | ||
| } | ||
|
|
||
| List<String> command = new ArrayList<>(); | ||
| command.add(JavaRuntime.getDefault().getBinary().toString()); | ||
|
|
||
| for (Map.Entry<Object, Object> e : System.getProperties().entrySet()) { | ||
| Object k = e.getKey(); | ||
| if (k instanceof String && ((String) k).startsWith("hmcl.")) { | ||
| command.add("-D" + k + "=" + e.getValue()); | ||
| } | ||
| } | ||
|
|
||
| command.addAll(jvmOptions); | ||
|
|
||
| command.add("-jar"); | ||
| command.add(jar.toAbsolutePath().toString()); | ||
|
|
||
| command.addAll(programArgs); | ||
|
|
||
| new ProcessBuilder(command) | ||
| .directory(new File(System.getProperty("user.dir"))) | ||
| .inheritIO() | ||
| .start(); | ||
|
|
||
| EntryPoint.exit(0); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -205,6 +205,7 @@ button.save_as=另存 | |
| button.select_all=悉擇之 | ||
| button.view=覽 | ||
| button.yes=然 | ||
| button.restart=復啟 | ||
|
|
||
| chat=會集 | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
重启失败的时候为什么要跳回去?我觉得应该提示用户手动重启完成切换。