File tree Expand file tree Collapse file tree 6 files changed +87
-39
lines changed
src/main/java/dev/webview Expand file tree Collapse file tree 6 files changed +87
-39
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 2323import co .casterlabs .rakurai .json .element .JsonElement ;
2424import co .casterlabs .rakurai .json .serialization .JsonParseException ;
2525import dev .webview .WebviewNative .BindCallback ;
26+ import dev .webview .platform .OperatingSystem ;
27+ import dev .webview .platform .Platform ;
2628import lombok .NonNull ;
2729
2830public class Webview implements Closeable , Runnable {
2931 private static final WebviewNative N ;
3032
31- public static final Platform PLATFORM = Platform .get ();
32-
3333 static {
3434 WebviewNative .runSetup ();
3535 N = Native .load ("webview" , WebviewNative .class );
@@ -79,7 +79,7 @@ private void updateSize() {
7979 // There is a random margin on Windows that isn't visible, so we must
8080 // compensate.
8181 // TODO figure out why this is caused.
82- if (PLATFORM == Platform .WINDOWS ) {
82+ if (Platform . os == OperatingSystem .WINDOWS ) {
8383 width -= 16 ;
8484 height -= 39 ;
8585 }
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public interface WebviewNative extends Library {
1919 static void runSetup () {
2020 String [] libraries = null ;
2121
22- switch (Webview . PLATFORM ) {
22+ switch (Platform . os ) {
2323 case LINUX : {
2424 libraries = new String [] {
2525 "libwebview.so"
Original file line number Diff line number Diff line change 1+ package dev .webview .platform ;
2+
3+ import java .util .regex .Pattern ;
4+
5+ import lombok .AllArgsConstructor ;
6+
7+ @ AllArgsConstructor
8+ public enum Arch {
9+ // @formatter:off
10+ AMD64 ("amd64" , "amd64|x86_64" ),
11+ X86 ("x86" , "x86|i386|i486|i586|i686|i786" ),
12+ AARCH64 ("aarch64" , "arm64|aarch64" ),
13+ ARM32 ("arm32" , "arm" );
14+ // @formatter:on
15+
16+ private String str ;
17+ private String regex ;
18+
19+ static Arch get () {
20+ String osArch = System .getProperty ("os.arch" ).toLowerCase ();
21+
22+ for (Arch arch : values ()) {
23+ if (Pattern .compile (arch .regex ).matcher (osArch ).find ()) {
24+ return arch ;
25+ }
26+ }
27+
28+ throw new UnsupportedOperationException ("Unknown cpu arch: " + osArch );
29+ }
30+
31+ @ Override
32+ public String toString () {
33+ return this .str ;
34+ }
35+
36+ }
Original file line number Diff line number Diff line change 1+ package dev .webview .platform ;
2+
3+ import java .util .regex .Pattern ;
4+
5+ import lombok .AllArgsConstructor ;
6+
7+ @ AllArgsConstructor
8+ public enum OperatingSystem {
9+ // @formatter:off
10+ MACOSX ("macOS" , "mac|darwin" ),
11+ LINUX ("Linux" , "nux" ),
12+ WINDOWS ("Windows" , "win" );
13+ // @formatter:on
14+
15+ private String str ;
16+ private String regex ;
17+
18+ static OperatingSystem get () {
19+ String osName = System .getProperty ("os.name" ).toLowerCase ();
20+
21+ for (OperatingSystem os : values ()) {
22+ if (Pattern .compile (os .regex ).matcher (osName ).find ()) {
23+ return os ;
24+ }
25+ }
26+
27+ throw new UnsupportedOperationException ("Unknown operating system: " + osName );
28+ }
29+
30+ @ Override
31+ public String toString () {
32+ return this .str ;
33+ }
34+
35+ }
Original file line number Diff line number Diff line change 1+ package dev .webview .platform ;
2+
3+ public class Platform {
4+ public static final Arch arch ;
5+ public static final OperatingSystem os ;
6+
7+ static {
8+ arch = Arch .get ();
9+ os = OperatingSystem .get ();
10+ }
11+
12+ }
You can’t perform that action at this time.
0 commit comments