package com.dynamicwallpaper;

import com.dynamicwallpaper.gui.MainWindow;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/** Application entry point. */
public final class Main {

    private Main() {
    }

    public static void main(String[] args) {
        if (!System.getProperty("os.name", "").toLowerCase().contains("mac")) {
            System.err.println("Dynamic Wallpaper Creator only runs on macOS, "
                    + "since Dynamic Desktop wallpapers are a macOS feature.");
            System.exit(1);
        }

        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("apple.awt.application.name", "Dynamic Wallpaper Creator");

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            // Fall back to the default look and feel; purely cosmetic.
        }

        SwingUtilities.invokeLater(() -> {
            try {
                new MainWindow().setVisible(true);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Dynamic Wallpaper Creator failed to start:\n" + e.getMessage(),
                        "Startup error", JOptionPane.ERROR_MESSAGE);
            }
        });
    }
}
