package com.axis.innovators.box;

import com.axis.innovators.box.events.GlobalEventBus;
import com.axis.innovators.box.events.SettingsLoadEvents;
import com.axis.innovators.box.events.SubscribeEvent;
import com.axis.innovators.box.gui.FridaWindow;
import com.axis.innovators.box.gui.MainWindow;
import com.axis.innovators.box.tools.FolderCreator;
import com.axis.innovators.box.tools.LibraryLoad;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * 主类
 * @author tzdwindows 7
 */
public class Main {

    static {
        LibraryLoad.loadLibrary("FridaNative");
    }

    @SubscribeEvent
    public void onSettingsLoad(SettingsLoadEvents event) {
        JLabel placeholder = new JLabel("设置功能开发中...", SwingConstants.CENTER);
        placeholder.setFont(new Font("微软雅黑", Font.PLAIN, 24));
        placeholder.setForeground(new Color(127, 140, 153));
        event.content().add(placeholder, BorderLayout.CENTER);

        // 我不想写这个了你们自己实现
    }

    public static void main(String[] args) {
        // 注册事件
        GlobalEventBus.EVENT_BUS.register(new Main());
        // 设置系统外观
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ignored) {}

        // 创建窗口
        SwingUtilities.invokeLater(() -> {
            MainWindow ex = new MainWindow();
            int id = 0;
            MainWindow.ToolCategory debugCategory = new MainWindow.ToolCategory("调试工具",
                    "debug/debug.png",
                    "用于调试指定Windows工具的一个分类");

            debugCategory.addTool(new MainWindow.ToolItem("Frida注入工具", "debug/frida/frida_main.png",
                    "使用frida注入目标进程的脚本程序 " +
                            "\n作者：tzdwindows 7", ++id, new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Window owner = SwingUtilities.windowForComponent((Component) e.getSource());
                    FridaWindow fridaWindow = new FridaWindow(owner);
                    fridaWindow.setVisible(true);
                }
            }));

            // 在后面注册你自己的项或是添加你自己的分类
            // ....

            ex.addToolCategory(debugCategory);
            ex.initUI();
            ex.setVisible(true);
        });
    }
}