You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.6 KiB
94 lines
2.6 KiB
7 years ago
|
package com.fr.start.jni;
|
||
|
|
||
7 years ago
|
import com.fr.base.FRContext;
|
||
7 years ago
|
import com.fr.stable.ProductConstants;
|
||
|
import com.fr.stable.StableUtils;
|
||
7 years ago
|
import com.fr.stable.StringUtils;
|
||
7 years ago
|
import com.fr.start.SplashContext;
|
||
|
import com.fr.start.SplashStrategy;
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.io.FileOutputStream;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
|
||
|
/**
|
||
|
* mac上使用jni方式绘制gif。不使用javafx有两个原因:
|
||
|
* 1.mac上javafx和swing同时启动会导致卡死;
|
||
|
* 2.platform.exit会导致设计器崩溃
|
||
|
*
|
||
|
* @author vito
|
||
|
* @see com.fr.start.fx.SplashFx
|
||
|
*/
|
||
|
public class SplashMac implements SplashStrategy {
|
||
|
|
||
|
|
||
|
private SplashJNI jni;
|
||
|
|
||
|
public SplashMac() {
|
||
|
jni = new SplashJNI();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 将jar中的资源拷贝到缓存文件夹
|
||
|
*
|
||
|
* @return 路径
|
||
|
*/
|
||
7 years ago
|
private static String loadResFromJar() {
|
||
7 years ago
|
File tempLib = null;
|
||
7 years ago
|
try (InputStream inputStream = SplashContext.class.getResourceAsStream(SplashContext.SPLASH_PATH)) {
|
||
7 years ago
|
if (inputStream == null) {
|
||
7 years ago
|
FRContext.getLogger().error("Unable to copy " + SplashContext.SPLASH_PATH + " from jar file.");
|
||
7 years ago
|
return StringUtils.EMPTY;
|
||
|
}
|
||
7 years ago
|
tempLib = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), SplashContext.SPLASH_CACHE_NAME));
|
||
7 years ago
|
byte[] buffer = new byte[1024];
|
||
|
int read = -1;
|
||
|
try (FileOutputStream fileOutputStream = new FileOutputStream(tempLib)) {
|
||
|
while ((read = inputStream.read(buffer)) != -1) {
|
||
|
fileOutputStream.write(buffer, 0, read);
|
||
|
}
|
||
|
}
|
||
|
return tempLib.getAbsolutePath();
|
||
|
} catch (IOException e) {
|
||
7 years ago
|
if (tempLib != null) {
|
||
|
tempLib.deleteOnExit();
|
||
|
}
|
||
|
// 直接抛异常
|
||
7 years ago
|
throw new RuntimeException("Unable to copy " + SplashContext.SPLASH_PATH + " from jar file.");
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void show() {
|
||
|
if (jni != null) {
|
||
7 years ago
|
File splash = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), SplashContext.SPLASH_CACHE_NAME));
|
||
7 years ago
|
String path = splash.exists() ? splash.getAbsolutePath() : loadResFromJar();
|
||
|
jni.show(path);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void hide() {
|
||
|
if (jni != null) {
|
||
|
jni.hide();
|
||
|
jni = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void updateModuleLog(String text) {
|
||
|
if (jni != null) {
|
||
|
jni.updateModuleLog(text);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void updateThanksLog(String text) {
|
||
|
if (jni != null) {
|
||
|
jni.updateThanksLog(text);
|
||
|
}
|
||
|
}
|
||
|
}
|