v1.2.0: fixed URI's failing to open on macOS

This commit is contained in:
Evan Debenham 2022-01-26 19:55:54 -05:00
parent c6189e32dc
commit 17d4dda402
7 changed files with 41 additions and 10 deletions

View File

@ -63,10 +63,6 @@ public class DeviceCompat {
return Game.version.contains("INDEV");
}
public static void openURI( String URI ){
Gdx.net.openURI(URI);
}
public static void log( String tag, String message ){
Gdx.app.log( tag, message );
}

View File

@ -47,6 +47,10 @@ public abstract class PlatformSupport {
//does nothing by default
}
public boolean openURI( String uri ){
return Gdx.net.openURI( uri );
}
//TODO should consider spinning this into its own class, rather than platform support getting ever bigger
protected static HashMap<FreeTypeFontGenerator, HashMap<Integer, BitmapFont>> fonts;

View File

@ -315,7 +315,7 @@ public class AboutScene extends PixelScene {
linkButton = new PointerArea(0, 0, 0, 0){
@Override
protected void onClick( PointerEvent event ) {
DeviceCompat.openURI( linkUrl );
ShatteredPixelDungeon.platform.openURI( linkUrl );
}
};
add(linkButton);

View File

@ -151,7 +151,7 @@ public class NewsScene extends PixelScene {
link += "?utm_source=shatteredpd";
link += "&utm_medium=news_page";
link += "&utm_campaign=ingame_link";
DeviceCompat.openURI(link);
ShatteredPixelDungeon.platform.openURI(link);
}
};
btnSite.icon(Icons.get(Icons.NEWS));
@ -323,7 +323,7 @@ public class NewsScene extends PixelScene {
link += "?utm_source=shatteredpd";
link += "&utm_medium=news_page";
link += "&utm_campaign=ingame_link";
DeviceCompat.openURI(link);
ShatteredPixelDungeon.platform.openURI(link);
}
};
link.setRect(0, height + 2, width, BTN_HEIGHT);

View File

@ -25,11 +25,14 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.PixmapPacker;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.utils.SharedLibraryLoader;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.watabou.noosa.Game;
import com.watabou.utils.PlatformSupport;
import com.watabou.utils.Point;
import java.awt.Desktop;
import java.net.URI;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -63,6 +66,34 @@ public class DesktopPlatformSupport extends PlatformSupport {
public boolean connectedToUnmeteredNetwork() {
return true; //no easy way to check this in desktop, just assume user doesn't care
}
//TODO backported openURI fix from libGDX-1.10.1-SNAPSHOT, remove when updating libGDX
public boolean openURI( String uri ){
if (SharedLibraryLoader.isMac) {
try {
(new ProcessBuilder("open", (new URI(uri).toString()))).start();
return true;
} catch (Throwable t) {
return false;
}
} else if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
try {
Desktop.getDesktop().browse(new URI(uri));
return true;
} catch (Throwable t) {
return false;
}
} else if (SharedLibraryLoader.isLinux) {
try {
(new ProcessBuilder("xdg-open", (new URI(uri).toString()))).start();
return true;
} catch (Throwable t) {
return false;
}
}
return false;
}
/* FONT SUPPORT */
//custom pixel font, for use with Latin and Cyrillic languages

View File

@ -57,7 +57,7 @@ public class DebugUpdates extends UpdateService {
@Override
public void initializeUpdate(AvailableUpdateData update) {
DeviceCompat.openURI( update.URL );
Game.platform.openURI( update.URL );
}
@Override
@ -83,6 +83,6 @@ public class DebugUpdates extends UpdateService {
@Override
public void openReviewURI() {
DeviceCompat.openURI("https://www.google.com/");
Game.platform.openURI("https://www.google.com/");
}
}

View File

@ -125,7 +125,7 @@ public class GitHubUpdates extends UpdateService {
@Override
public void initializeUpdate(AvailableUpdateData update) {
DeviceCompat.openURI( update.URL );
Game.platform.openURI( update.URL );
}
@Override