diff --git a/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java b/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java index 2ea81f9b4..aa7468a41 100644 --- a/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java +++ b/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java @@ -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 ); } diff --git a/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java b/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java index abec9abfb..fc254b5cc 100644 --- a/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java +++ b/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java @@ -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> fonts; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java index aebbfbfaf..7cd241305 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java @@ -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); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/NewsScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/NewsScene.java index e7236f971..6cc4522ec 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/NewsScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/NewsScene.java @@ -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); diff --git a/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java b/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java index c07df9856..62bbd268a 100644 --- a/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java +++ b/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java @@ -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 diff --git a/services/updates/debugUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/DebugUpdates.java b/services/updates/debugUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/DebugUpdates.java index 59c006fda..c16b80dff 100644 --- a/services/updates/debugUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/DebugUpdates.java +++ b/services/updates/debugUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/DebugUpdates.java @@ -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/"); } } diff --git a/services/updates/githubUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/GitHubUpdates.java b/services/updates/githubUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/GitHubUpdates.java index 4b29e4c80..db1c26cc6 100644 --- a/services/updates/githubUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/GitHubUpdates.java +++ b/services/updates/githubUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/GitHubUpdates.java @@ -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