Skip to content
This repository was archived by the owner on Apr 8, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.psnrigner</groupId>
<artifactId>discord-rpc-java</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
<packaging>jar</packaging>

<!-- Information for release -->
Expand Down Expand Up @@ -55,12 +55,6 @@
</repositories>

<dependencies>
<!-- Use apache lib to efficiently detect OS version, should prolly move to custom system -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>

<!-- Parse and write json objects -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.psnrigner.discordrpcjava.impl;

import org.apache.commons.lang.SystemUtils;

import com.github.psnrigner.discordrpcjava.util.SystemUtils;

/**
* Base connection class
Expand All @@ -15,16 +16,16 @@ public abstract class BaseConnection

static BaseConnection create()
{
if (SystemUtils.IS_OS_MAC_OSX)
if (SystemUtils.isMacOSX())
return new BaseConnectionOsx();

if (SystemUtils.IS_OS_UNIX)
if (SystemUtils.isUnix())
return new BaseConnectionUnix();

if (SystemUtils.IS_OS_WINDOWS)
if (SystemUtils.isWindows())
return new BaseConnectionWindows();

throw new IllegalStateException("This OS is not supported");
throw new IllegalStateException("OS is not supported: " + SystemUtils.getOsName());
}

static void destroy(BaseConnection baseConnection)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.github.psnrigner.discordrpcjava.util;

public class SystemUtils
{

public static boolean isWindows()
{
return is(OS.WINDOWS);
}

public static boolean isMacOSX()
{
return is(OS.MAC_OSX);
}

public static boolean isUnix()
{
return is(OS.UNIX);
}

public static String getOsName() {
return System.getProperty("os.name");
}

private static boolean is(OS os)
{
return OS.byOsName(System.getProperty("os.name")).equals(os);
}

public enum OS {
WINDOWS(new String[]{"Windows"}),
MAC_OSX(new String[]{"Mac"}),
UNIX(new String[]{"Linux", "LINUX", "AIX", "HP-UX", "Trix", "OS/2", "Solaris", "SunOS"}), // feel free to add
UNKNOWN;

private String[] osNames;

OS()
{
}

OS(String[] osNames)
{
this.osNames = osNames;
}


public String[] getOsNames()
{
return osNames;
}

public static OS byOsName(String osName)
{
for(OS os: OS.values()) {
for(String name : os.getOsNames())
{
if(osName.startsWith(name))
{
return os;
}
}
}
return UNKNOWN;
}
}
}