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 all commits
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,17 @@ public abstract class BaseConnection

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

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

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

throw new IllegalStateException("This OS is not supported");
switch (SystemUtils.getOs()) {
case WINDOWS:
return new BaseConnectionWindows();
case MAC_OSX:
return new BaseConnectionOsx();
case UNIX:
return new BaseConnectionUnix();
case UNKNOWN:
break; // throw error below
}
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,50 @@
package com.github.psnrigner.discordrpcjava.util;

public class SystemUtils
{
public static OS getOs() {
return OS.byOsName(getOsName());
}

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

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;
}
}
}