Skip to content

Commit

Permalink
fix examples and name not being used in dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
Osiris-Team committed Aug 8, 2024
1 parent 2f40389 commit ae1ab99
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ In addition, it is also highly beginner-friendly, making it accessible to everyo
vertical().add(text("Hello World!"))
```
<details>
<summary>3 lines example</summary>
<summary>Minimal example</summary>

```java
import com.osiris.desku.App;
import static com.osiris.desku.Statics;
public class Main {
public static void main(String[] args) throws Exception {
App.init(new DesktopUIManager());
App.uis = new DesktopUIManager(); // Not needed when using the Desku-Gradle-Starter-App
App.name = "My-App";
App.init();
App.uis.create(() -> {
return vertical().add(text("Hello World!"));
});
Expand All @@ -37,9 +38,10 @@ import static com.osiris.desku.Statics; // Low-code Java UI via static methods
public class Main {
public static void main(String[] args) throws Exception {

// Setup app details.
App.init(new DesktopUIManager()); // Not needed when using the Desku-Gradle-Starter-App
// Setup app details and init.
App.uis = new DesktopUIManager(); // Not needed when using the Desku-Gradle-Starter-App
App.name = "My-App";
App.init();

// Create routes.
// This is only for demonstration.
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/osiris/desku/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public static void updateDirs(){
*/
public static Theme theme = new Theme();


public static UIManager uis = null;
public static ExecutorService executor = Executors.newCachedThreadPool();

Expand All @@ -127,16 +128,25 @@ public LoggerParams() {
}
}

/**
* Initialize assuming platform-specific {@link UIManager} was already set earlier. <br>
* Meaning {@link App#uis} must be not null when calling this.
*/
public static void init() {
init(null, new LoggerParams());
}

public static void init(UIManager uiManager) {
init(uiManager, new LoggerParams());
}

public static void init(UIManager uiManager, LoggerParams loggerParams) {
if (uiManager == null) {
if (uiManager == null && App.uis == null) {
throw new NullPointerException("Provided UI factory is null!" +
" Make sure to provide an implementation for the platform this app is running in.");
}
App.uis = uiManager;
if(uiManager != null)
App.uis = uiManager;
try {
updateDirs();
Logger.getGlobal().setLevel(Level.SEVERE);
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/osiris/desku/simple_app/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
class AppTest {

public static void main(String[] args) throws Exception {
// Setup details
App.init(new DesktopUIManager());
App.name = "My-App";
// before loading the page
// Setup details before init
App.uis = new DesktopUIManager();
App.name = "My-Example-Desku-App";
App.init();

// Create routes
Route home = new Home();
Expand Down

0 comments on commit ae1ab99

Please sign in to comment.