### Full Update Workflow Example (JavaScript) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/auto-updates.md A comprehensive example demonstrating the complete update process: checking for updates, prompting the user, downloading with progress, and installing. ```javascript async function checkForUpdates() { const result = await window.krema.invoke('updater:check'); if (!result.updateAvailable) { console.log('App is up to date'); return; } // Show update dialog const userWantsUpdate = await showUpdateDialog(result); if (!userWantsUpdate) return; // Download with progress window.krema.on('download-progress', updateProgressBar); try { await window.krema.invoke('updater:download'); await window.krema.invoke('updater:install'); } catch (error) { console.error('Update failed:', error); } } ``` -------------------------------- ### Full Auto-Updater Workflow Example Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/user/auto-updater.md Demonstrates a complete process for checking, downloading, and installing updates, including user interaction and progress feedback. Handles potential errors during the update process. ```typescript async function checkForUpdates() { try { const result = await krema.updater.check(); if (!result.updateAvailable) { showNotification('You are up to date!'); return; } const userConfirmed = await showUpdateDialog( result.version, result.notes, result.mandatory ); if (!userConfirmed) return; // Listen for progress const unsub = krema.on('updater:download-progress', (data) => { updateProgressBar(data.progress); }); await krema.updater.download(); unsub(); // stop listening // Ask user to restart const restartNow = await showRestartDialog(); if (restartNow) { await krema.updater.installAndRestart(); } else { // Install will happen next time the app starts await krema.updater.install(); } } catch (err) { console.error('Update failed:', err); } } ``` -------------------------------- ### Run Krema CLI with npx Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/installation.md Initializes a new Krema application using npx without a global installation. Useful for quick project setup. ```bash npx @krema-build/krema init my-app --template react ``` -------------------------------- ### Build and Install Krema from Source Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/installation.md Clones the Krema repository, builds the CLI from source using Maven, and installs it. Includes verification step. ```bash # Clone the Krema repository git clone https://github.com/ApokalypsixDev/krema.git cd krema # Build and install the CLI ./install.sh # Verify installation krema --version ``` -------------------------------- ### Start Development Server Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/cli-cheatsheet.md Starts the app in development mode with hot reload. Use --profile to specify an environment profile or --no-frontend to skip starting the frontend dev server. ```bash krema dev ``` ```bash krema dev --profile development ``` ```bash krema dev --no-frontend ``` -------------------------------- ### Example: System Info Panel Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/os-info.md An example function to fetch system information using 'os:info' and display it in an HTML panel. Includes a helper function to format bytes into GB. ```javascript async function showSystemInfo() { const info = await window.krema.invoke('os:info'); const panel = document.getElementById('system-info'); panel.innerHTML = `

System Information

Platform: ${info.platform} (${info.arch})

Version: ${info.version}

Hostname: ${info.hostname}

User: ${info.username}

CPUs: ${info.cpuCount} cores

Memory: ${formatBytes(info.memory.used)} / ${formatBytes(info.memory.max)}

Locale: ${info.locale.displayName}

`; } function formatBytes(bytes) { const gb = bytes / (1024 * 1024 * 1024); return gb.toFixed(2) + ' GB'; } ``` -------------------------------- ### Krema Configuration File Example Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/cli-reference.md Example of a krema.toml file showing package, window, build, bundle, permissions, updater, and environment-specific configurations. ```toml [package] name = "my-app" version = "1.0.0" identifier = "com.example.myapp" [window] title = "My App" width = 1200 height = 800 [build] frontend_command = "npm run build" frontend_dev_command = "npm run dev" frontend_dev_url = "http://localhost:5173" out_dir = "dist" [bundle] icon = "icons/icon.icns" [bundle.macos] signing_identity = "Developer ID Application: ..." notarization_apple_id = "your@email.com" notarization_team_id = "TEAMID" [bundle.windows] certificate_path = "path/to/certificate.pfx" [permissions] allow = ["fs:read", "clipboard:read", "notification"] [updater] pubkey = "MCowBQYDK2VwAyEA..." endpoints = ["https://releases.example.com/{{target}}/{{current_version}}"] [env.development] [env.development.window] title = "My App (Dev)" [env.production] [env.production.build] frontend_command = "npm run build:prod" ``` -------------------------------- ### Electron Main Process Example Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/migration.md A typical Electron main process script using Node.js to create a window and handle IPC messages for file operations and getting app paths. ```javascript const { app, BrowserWindow, ipcMain } = require('electron'); const path = require('path'); const fs = require('fs'); let mainWindow; function createWindow() { mainWindow = new BrowserWindow({ width: 1200, height: 800, webPreferences: { preload: path.join(__dirname, 'preload.js'), nodeIntegration: false, contextIsolation: true } }); mainWindow.loadFile('renderer/index.html'); } app.whenReady().then(createWindow); // IPC handlers pcMain.handle('read-file', async (event, filePath) => { return fs.readFileSync(filePath, 'utf-8'); }); pcMain.handle('write-file', async (event, filePath, content) => { fs.writeFileSync(filePath, content); }); pcMain.handle('get-app-path', () => { return app.getPath('userData'); }); ``` -------------------------------- ### Install Krema CLI Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/guide.md Clone the Krema repository and install the CLI tool. Alternatively, build and install manually using Maven and export the path. ```bash git clone https://github.com/ApokalypsixDev/krema.git cd krema ./install.sh ``` ```bash mvn clean install -DskipTests export PATH="$PATH:$(pwd)/bin" ``` -------------------------------- ### Example: Mini Player Window Management Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/plugins/positioner.md This example demonstrates how to resize, position, and manage window 'always on top' status to create a mini-player effect. ```javascript async function enterMiniPlayer() { await window.krema.invoke('window:setSize', { width: 320, height: 180 }); await window.krema.invoke('positioner:moveTo', { position: 'bottom-right' }); await window.krema.invoke('window:setAlwaysOnTop', { alwaysOnTop: true }); } async function exitMiniPlayer() { await window.krema.invoke('window:setAlwaysOnTop', { alwaysOnTop: false }); await window.krema.invoke('window:setSize', { width: 1024, height: 768 }); await window.krema.invoke('positioner:moveTo', { position: 'center' }); } ``` -------------------------------- ### Start Local Development Server Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/README.md Starts a local development server for live previewing changes. The server automatically reloads the browser on file modifications. ```bash yarn start ``` -------------------------------- ### Create and Run a Krema Project Source: https://github.com/krema-build/krema/blob/master/README.md Initialize a new Krema project with a React template and start the development server. ```bash krema init my-app --template react cd my-app krema dev ``` -------------------------------- ### Development Cycle Workflow Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/cli-cheatsheet.md A common workflow for starting a new project, installing dependencies, and running the development server. ```bash # Start fresh project krema init my-app cd my-app # Install dependencies npm install # Start development krema dev # Build and test production krema build # Create distributable krema bundle --sign ``` -------------------------------- ### Install Windows Dependencies (winget) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/installation.md Installs WebView2 Runtime, Java 25, Maven, and Node.js using winget on Windows. ```powershell # Install WebView2 Runtime (usually pre-installed) winget install Microsoft.EdgeWebView2Runtime # Install Java 25 winget install EclipseAdoptium.Temurin.25.JDK # Install Maven winget install Apache.Maven # Install Node.js winget install OpenJS.NodeJS ``` -------------------------------- ### Example Chat Client Implementation Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/plugins/websocket.md A comprehensive example demonstrating how to build a chat client using the WebSocket plugin. It includes connection management, message sending, and event handling with automatic reconnection. ```javascript class ChatClient { constructor(url, token) { this.url = url; this.token = token; this.setupListeners(); } setupListeners() { window.krema.on('websocket:message', (data) => { if (data.name === 'chat') { const msg = JSON.parse(data.data); this.onMessage(msg); } }); window.krema.on('websocket:disconnected', () => { setTimeout(() => this.connect(), 5000); // Reconnect }); } async connect() { await window.krema.invoke('websocket:connect', { name: 'chat', url: this.url, headers: { 'Authorization': `Bearer ${this.token}` } }); } async send(message) { await window.krema.invoke('websocket:send', { name: 'chat', message: JSON.stringify(message) }); } onMessage(msg) { // Handle incoming message } } ``` -------------------------------- ### Install Krema CLI with npm Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/installation.md Installs the Krema CLI globally using npm. This is the recommended method for web developers. ```bash npm install -g @krema-build/krema ``` -------------------------------- ### Install GraalVM JDK 25+ on Windows Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/native-image.md Install GraalVM JDK 25 or later on Windows by downloading the installer and setting the GRAALVM_HOME and PATH environment variables. ```powershell # Download from https://www.graalvm.org/downloads/ # Set environment variables setx GRAALVM_HOME "C:\path\to\graalvm-jdk-25" setx PATH "%GRAALVM_HOME%\bin;%PATH%" ``` -------------------------------- ### Install Update Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/auto-updates.md Installs the downloaded update and restarts the application. ```APIDOC ## Install Update ### Description Installs the downloaded update and restarts the application. ### Method `await window.krema.invoke('updater:install')` ### Parameters None ### Request Example ```javascript // Restart and install await window.krema.invoke('updater:install'); ``` ``` -------------------------------- ### Getting Help Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/cli-cheatsheet.md Commands to get general help, command-specific help, and the Krema version. ```bash krema --help ``` ```bash krema --help ``` ```bash krema --version ``` -------------------------------- ### Install Dependencies with Yarn Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/README.md Installs project dependencies using Yarn. This is the first step before running any other commands. ```bash yarn ``` -------------------------------- ### Install Linux System Libraries Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/guide.md Install necessary GTK and WebKitGTK libraries on Linux if encountering errors related to missing symbols. ```bash # If you see errors about missing gtk or webkit2gtk symbols: sudo apt install libwebkit2gtk-4.1-0 libgtk-3-0 ``` -------------------------------- ### Install Krema TypeScript Definitions Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/guide.md Install the necessary type definitions for using Krema with TypeScript. ```bash npm install @krema-build/api ``` -------------------------------- ### Install WebKitGTK and GTK (Fedora/RHEL) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/installation.md Installs WebKitGTK and GTK libraries for Linux distributions like Fedora and RHEL. Includes optional package for system tray support. ```bash sudo dnf install webkit2gtk4.0 gtk3 # Optional: for system tray support sudo dnf install libayatana-appindicator-gtk3 ``` -------------------------------- ### Install Maven Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/advanced/troubleshooting.md Install Apache Maven on different operating systems. This is necessary for projects that rely on Maven for dependency management and build processes. ```bash # Install Maven brew install maven # macOS apt install maven # Ubuntu choco install maven # Windows ``` -------------------------------- ### Install WebKitGTK and GTK (Arch Linux) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/installation.md Installs WebKitGTK and GTK libraries for Arch Linux. Includes optional package for system tray support. ```bash sudo pacman -S webkit2gtk-4.1 gtk3 # Optional: for system tray support sudo pacman -S libayatana-appindicator ``` -------------------------------- ### Install Linux System Libraries Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/guide.md On Linux, install necessary system libraries for Krema. This includes WebKitGTK and GTK3. Optional packages for system tray and desktop notifications are also listed. ```bash sudo apt install libwebkit2gtk-4.1-0 libgtk-3-0 # Optional: for system tray support sudo apt install libayatana-appindicator3-1 # Optional: for desktop notifications sudo apt install libnotify-bin ``` ```bash sudo dnf install webkit2gtk4.0 gtk3 # Optional: for system tray support sudo dnf install libayatana-appindicator-gtk3 ``` ```bash sudo pacman -S webkit2gtk-4.1 gtk3 # Optional: for system tray support sudo pacman -S libayatana-appindicator ``` -------------------------------- ### Install Krema CLI Source: https://github.com/krema-build/krema/blob/master/README.md Install the Krema command-line interface using npm or a curl script. ```bash # via npm npm install -g @krema-build/krema # or via curl curl -fsSL https://krema.build/install.sh | bash ``` -------------------------------- ### Install Update and Restart Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/user/auto-updater.md Installs the update and restarts the application. Emits the `updater:before-restart` event prior to restarting, allowing the application to save its state. ```typescript await krema.updater.installAndRestart(); ``` -------------------------------- ### Start Krema Development Server Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/quick-start.md Launches the development server, native window, and enables hot reload for frontend and backend changes. ```bash krema dev ``` -------------------------------- ### Install WebKitGTK Runtime on Debian/Ubuntu Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/native-image.md On Debian-based Linux distributions, ensure the WebKitGTK runtime libraries are installed on the target machine before bundling. ```bash # Ubuntu/Debian sudo apt install libwebkit2gtk-4.1-0 libgtk-3-0 ``` -------------------------------- ### TOML Plugin Configuration Example Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/plugins.md Configure plugin settings like API keys and connection limits using a TOML file. ```toml [plugins.my-plugin] enabled = true api_key = "secret123" max_connections = 5 debug = false ``` -------------------------------- ### Updater Configuration Example Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/advanced/security.md Example TOML configuration for the Krema updater, specifying the public key for signature verification and the endpoints for fetching updates. ```toml [updater] pubkey = "MCowBQYDK2VwAyEA..." endpoints = ["https://releases.example.com/..."] ``` -------------------------------- ### Example .env.development Variables Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/app-environment.md Defines environment-specific variables for the development profile. ```bash API_URL=http://localhost:3000 DEBUG=true LOG_LEVEL=debug ``` -------------------------------- ### Start Development Server Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/cli-reference.md Run 'krema dev' to start the development server with hot reload. This command launches the native window pointing to the dev server and watches for Java source changes. ```bash krema dev [options] ``` ```bash krema dev ``` ```bash krema dev --env staging ``` ```bash krema dev --port 3000 ``` -------------------------------- ### Install WebKitGTK Runtime on Linux Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/advanced/troubleshooting.md Install the WebKitGTK runtime libraries required for Krema applications on various Linux distributions. This is a runtime dependency, not a development header. ```bash # Ubuntu/Debian sudo apt install libwebkit2gtk-4.1-0 libgtk-3-0 # Fedora sudo dnf install webkit2gtk4.0 gtk3 # Arch sudo pacman -S webkit2gtk-4.1 gtk3 ``` -------------------------------- ### Install WebKitGTK and GTK (Ubuntu/Debian) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/installation.md Installs WebKitGTK and GTK libraries for Linux distributions like Ubuntu and Debian. Includes optional package for system tray support. ```bash sudo apt install libwebkit2gtk-4.1-0 libgtk-3-0 # Optional: for system tray support sudo apt install libayatana-appindicator3-1 ``` -------------------------------- ### updater:installAndRestart Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/user/auto-updater.md Installs the update and restarts the application. Emits `updater:before-restart` before restarting. ```APIDOC ## updater:installAndRestart ### Description Installs the update and restarts the application. Emits `updater:before-restart` before restarting to allow the app to save its state. ### Method `krema.updater.installAndRestart()` ``` -------------------------------- ### Example .env.production Variables Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/app-environment.md Defines environment-specific variables for the production profile. ```bash API_URL=https://api.example.com DEBUG=false LOG_LEVEL=error ``` -------------------------------- ### Tauri Configuration (tauri.conf.json) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/migration.md Example of a Tauri configuration file, defining application metadata and window settings. ```json { "package": { "productName": "My App", "version": "1.0.0" }, "tauri": { "windows": [{ "title": "My App", "width": 1200, "height": 800, "resizable": true }], "bundle": { "identifier": "com.example.myapp", "icon": ["icons/icon.icns"] } } } ``` -------------------------------- ### Tauri Rust Command: Greet Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/migration/from-tauri.md Example of a simple 'greet' command in Tauri using Rust. ```rust #[tauri::command] fn greet(name: &str) -> String { format!("Hello, {}!", name) } ``` -------------------------------- ### Install Krema CLI with curl (macOS/Linux) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/installation.md Installs Krema CLI using a curl script for macOS and Linux. The script handles downloading binaries or JARs and Java setup. ```bash curl -fsSL https://raw.githubusercontent.com/krema-build/krema/master/packages/install.sh | bash ``` -------------------------------- ### Install Plugin to Application Directory Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/plugins.md Place the plugin JAR file in the application's plugin directory for global availability. ```bash ~/.krema/plugins/my-plugin.jar ``` -------------------------------- ### Electron Configuration: electron-builder.json Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/migration/from-electron.md Example structure for an electron-builder.json file, specifying app ID, product name, and platform-specific settings. ```json { "appId": "com.example.myapp", "productName": "My App", "mac": { "category": "public.app-category.developer-tools", "identity": "Developer ID Application: ..." }, "win": { "target": "nsis" } } ``` -------------------------------- ### Build and Sign Application Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/user/code-signing.md Execute this command to build your application, create the installer, and sign all generated .exe files with your configured certificate. Signing is timestamped using SHA256. ```bash krema bundle --sign ``` -------------------------------- ### Get Krema Version Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/advanced/troubleshooting.md Display the installed Krema version. This information is crucial when reporting issues. ```bash krema --version ``` -------------------------------- ### Electron Native Module Example Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/migration.md Demonstrates using a native Node module (better-sqlite3) within an Electron application via ipcMain. ```javascript const sqlite3 = require('better-sqlite3'); const db = sqlite3('mydb.sqlite'); ipcMain.handle('query', (event, sql) => { return db.prepare(sql).all(); }); ``` -------------------------------- ### Initialize New Krema Project Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/cli-reference.md Use 'krema init' to create a new Krema project. Specify the project name and optionally a template or use interactive modes. ```bash krema init [options] ``` ```bash # Create a React project krema init my-app --template react ``` ```bash # Full interactive wizard (configure plugins, window settings, etc.) krema init --wizard ``` ```bash # CI mode (no prompts) krema init my-app --ci -t react ``` -------------------------------- ### Initialize Krema Project Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/quick-start.md Use the Krema CLI to scaffold a new project with a specified template. ```bash krema init my-app --template react ``` -------------------------------- ### Manage Plugins via CLI Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/plugins.md Commands for installing, listing, and removing plugins from the repository (future feature). ```bash # Install from repository (future feature) krema plugin install my-plugin # List installed plugins krema plugin list # Remove plugin krema plugin remove my-plugin ``` -------------------------------- ### Initialize Krema Project with Wizard Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/quick-start.md Use the wizard mode for full configuration including plugins when initializing a new Krema project. ```bash krema init --wizard ``` -------------------------------- ### Install Plugin to Project Directory Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/plugins.md Place the plugin JAR file in the project's local plugins directory for project-specific use. ```bash ./plugins/my-plugin.jar ``` -------------------------------- ### Enable Autostart Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/plugins/autostart.md Invoke the 'autostart:enable' command to register the app for launch at login. ```javascript const success = await window.krema.invoke('autostart:enable'); ``` -------------------------------- ### Install GraalVM JDK 25+ on macOS Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/native-image.md Use Homebrew to install GraalVM JDK 25 or later on macOS. Verify the installation using the java_home command. ```bash brew install --cask graalvm-jdk@25 ``` ```bash /usr/libexec/java_home -v 25 ``` -------------------------------- ### Initialize New Project Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/cli-cheatsheet.md Creates a new Krema project with interactive setup. You can specify a project name, use a template, or skip git initialization. ```bash krema init my-app ``` ```bash krema init my-app --template react ``` ```bash krema init . --no-git ``` -------------------------------- ### Install Update Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/javascript-api.md Installs the downloaded update and restarts the application. This operation is asynchronous. ```typescript function install(): Promise; ``` -------------------------------- ### Notes App Database Initialization and Operations Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/plugins/sql.md Example demonstrating how to initialize a notes database, create new notes, and retrieve all notes using the SQL plugin. ```javascript class NotesDB { async init() { await window.krema.invoke('sql:open', { name: 'notes' }); await window.krema.invoke('sql:batch', { name: 'notes', statements: [ `CREATE TABLE IF NOT EXISTS notes ( id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, content TEXT, created_at INTEGER DEFAULT (strftime('%s', 'now')) )` ] }); } async create(title, content) { const result = await window.krema.invoke('sql:execute', { name: 'notes', sql: 'INSERT INTO notes (title, content) VALUES (?, ?)', params: [title, content] }); return result.lastInsertId; } async findAll() { return window.krema.invoke('sql:select', { name: 'notes', sql: 'SELECT * FROM notes ORDER BY created_at DESC' }); } } ``` -------------------------------- ### updater:install Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/user/auto-updater.md Installs a previously downloaded update without restarting the application. ```APIDOC ## updater:install ### Description Installs a previously downloaded update without restarting the application. ### Method `krema.updater.install()` ``` -------------------------------- ### Initialize New Krema Project Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/migration/from-electron.md Use the 'krema init' command to create a new Krema project with a specified template. ```bash krema init my-app --template react cd my-app ``` -------------------------------- ### Windows .exe Bundle Structure Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/building.md Understand the directory layout for a Windows .exe bundle, which includes the installer, bundled runtime, and application files. ```text target/bundle/windows/ MyApp/ MyApp.exe # Installer runtime/ # Bundled JVM app/ # Application JAR + assets ``` -------------------------------- ### Install Update (JavaScript) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/auto-updates.md Triggers the installation of a downloaded update. This action will typically restart the application. ```javascript // Restart and install await window.krema.invoke('updater:install'); ``` -------------------------------- ### Bundle Native Image Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/native-image.md After building a native image, use these commands to bundle it into a platform-specific installer. The bundler automatically detects the native binary. ```bash # Build native image first krema build --native # Then bundle krema bundle --type dmg # macOS krema bundle --type exe # Windows krema bundle --type appimage # Linux ``` -------------------------------- ### Using Krema CLI with Profiles Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/krema-toml.md Demonstrates how to activate environment-specific configurations using the Krema CLI with the `--profile` flag. ```bash # Development krema dev --profile development # Staging build krema build --profile staging # Production bundle krema bundle --profile production ``` -------------------------------- ### Install Update (No Restart) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/user/auto-updater.md Installs a previously downloaded update. This action does not restart the application immediately. ```typescript await krema.updater.install(); ``` -------------------------------- ### Krema Configuration (krema.toml) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/migration/from-tauri.md Example of a krema.toml file, demonstrating the equivalent configuration for package details, window settings, bundle icon, and permissions. ```toml [package] name = "my-app" version = "1.0.0" identifier = "com.example.myapp" [window] title = "My App" width = 1200 height = 800 [bundle] icon = "icons/icon.icns" [permissions] allow = [ "fs:read", "fs:write", "clipboard:read", "clipboard:write" ] ``` -------------------------------- ### Configure System Tray Icon and Menu Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/native-apis.md Set up the system tray icon, tooltip, and a context menu with items and actions. This involves using SystemTray.get() and TrayMenu.builder(). ```java import build.krema.api.tray.SystemTray; import build.krema.api.tray.TrayMenu; @KremaCommand public void setupTray() { SystemTray.get() .setIcon(iconBytes) .setTooltip("My App") .setMenu(TrayMenu.builder() .item("Show", () -> window.show()) .separator() .item("Quit", () -> System.exit(0)) .build()) .show(); } ``` -------------------------------- ### Install Homebrew Dependencies (macOS) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/installation.md Installs Java 25, Maven, and Node.js using Homebrew on macOS. ```bash # Install Java 25 (required) brew install openjdk@25 # Install Maven brew install maven # Install Node.js brew install node ``` -------------------------------- ### Krema Development Mode Build Process Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/advanced/architecture.md Outlines the steps involved in starting the Krema development server, including launching the Java application with the WebView pointing to the development URL and enabling hot reloading. ```bash krema dev │ ├─► Start frontend dev server (npm run dev) │ ├─► Wait for server ready │ ├─► Launch Java with WebView pointing to dev URL │ └─► Watch for changes, hot reload ``` -------------------------------- ### Create Platform Bundle Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/cli-cheatsheet.md Creates a distributable application bundle (.app, .exe, .AppImage). Options include targeting a specific platform, signing, and notarizing. ```bash krema bundle ``` ```bash krema bundle --sign ``` ```bash krema bundle --sign --notarize ``` ```bash krema bundle --target windows ``` -------------------------------- ### Install OpenJDK 25 on macOS Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/advanced/troubleshooting.md Install OpenJDK 25 using Homebrew and configure the JAVA_HOME and PATH environment variables. ```bash # macOS brew install openjdk@25 # Add to PATH export JAVA_HOME=/opt/homebrew/opt/openjdk@25 export PATH="$JAVA_HOME/bin:$PATH" ``` -------------------------------- ### Setup System Tray Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/guide.md Create and configure a system tray icon with a custom menu. The menu can contain items with associated actions, separators, and a quit option. ```java import build.krema.api.tray.SystemTray; import build.krema.api.tray.TrayMenu; public void setupTray() { SystemTray tray = SystemTray.create(); tray.setIcon(loadIcon()); tray.setTooltip("My App"); TrayMenu menu = TrayMenu.builder() .item("Show Window", () -> showWindow()) .separator() .item("Settings", () -> openSettings()) .separator() .item("Quit", () -> System.exit(0)) .build(); tray.setMenu(menu); } ``` -------------------------------- ### Complete Krema TOML Configuration Example Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/krema-toml.md This snippet shows a comprehensive TOML configuration file for a Krema application, demonstrating settings for package details, window appearance, build processes, bundling, permissions, updates, deep linking, splash screens, and environment-specific configurations. ```toml [package] name = "my-app" version = "1.0.0" identifier = "com.example.myapp" description = "My awesome desktop application" [window] title = "My App" width = 1200 height = 800 min_width = 800 min_height = 600 resizable = true fullscreen = false decorations = true [build] frontend_command = "npm run build" frontend_dev_command = "npm run dev" frontend_dev_url = "http://localhost:5173" out_dir = "dist" java_source_dir = "src-java" assets_path = "assets" [bundle] icon = "icons/icon.icns" identifier = "com.example.myapp" copyright = "Copyright 2024 Example Inc." [bundle.macos] signing_identity = "Developer ID Application: Example Inc. (ABCDEF1234)" notarization_apple_id = "dev@example.com" notarization_team_id = "ABCDEF1234" [bundle.windows] signing_certificate = "certs/signing.pfx" [permissions] allow = [ "fs:read", "fs:write", "clipboard:*", "notification", "dialog", "shell:open" ] [updater] pubkey = "your-base64-encoded-public-key" endpoints = ["https://releases.example.com/latest.json"] check_on_startup = true timeout = 30 [deep-link] schemes = ["myapp"] [splash] enabled = true image = "splash.png" width = 480 height = 320 [env.development] [env.development.window] title = "My App (Dev)" [env.production] [env.production.updater] endpoints = ["https://releases.example.com/updates.json"] ``` -------------------------------- ### Verify Native Image Installation Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/native-image.md Check if the native-image tool is installed and accessible by running the version command. This confirms GraalVM is set up correctly. ```bash native-image --version ``` -------------------------------- ### Manual Build and Install Krema from Source Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/installation.md Manually builds Krema from source using Maven and sets up the PATH environment variable. Recommended for advanced users or specific build requirements. ```bash mvn clean install -DskipTests export PATH="$PATH:$(pwd)/bin" ``` -------------------------------- ### Krema Init Command Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/design.md Initializes a new Krema project, creating necessary directories, copying template files, and generating the configuration file. ```java import picocli.CommandLine.Command; import picocli.CommandLine.Parameters; import picocli.CommandLine.Option; import java.nio.file.Files; import java.nio.file.Path; @Command(name = "init", description = "Create a new Krema project") public class InitCommand implements Callable { @Parameters(index = "0", description = "Project name") private String projectName; @Option(names = {"-t", "--template"}, description = "Template: vanilla, react, vue, svelte") private String template = "vanilla"; @Override public Integer call() throws Exception { Path projectDir = Path.of(projectName); // Create directory structure Files.createDirectories(projectDir.resolve("src")); Files.createDirectories(projectDir.resolve("src-java")); // Copy template files copyTemplate(template, projectDir); // Generate krema.toml generateConfig(projectDir, projectName); System.out.println("Created project: " + projectName); return 0; } } ``` -------------------------------- ### Initializing a Krema Plugin with PluginContext Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/plugins.md Demonstrates how to implement the `initialize` method of a Krema plugin using the `PluginContext`. This includes accessing the logger, event emitter, data directory, and configuration. ```java public class MyPlugin implements KremaPlugin { private PluginContext context; @Override public void initialize(PluginContext context) { this.context = context; // Access logger context.getLogger().info("Initializing..."); // Access event emitter EventEmitter events = context.getEventEmitter(); events.emit("my-plugin:ready", Map.of("version", getVersion())); // Access data directory Path dataDir = context.getDataDir(); // ~/.krema/plugins/my-plugin/data/ // Load configuration MyPluginConfig config = context.getConfig(MyPluginConfig.class); } } ``` -------------------------------- ### Run Krema React Demo App Source: https://github.com/krema-build/krema/blob/master/CONTRIBUTING.md Navigate to the Krema React demo directory, install dependencies, and compile the application using Maven with a development profile. ```bash cd krema-demos/krema-react npm install mvn compile exec:exec -Pdev ``` -------------------------------- ### Setup Complete Application Menu Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/menu-shortcut.md Defines and sets the application menu, including platform-specific adjustments for macOS. Use this to create a full application menu structure. ```javascript async function setupMenu() { const isMac = (await window.krema.invoke('os:platform')) === 'macos'; const appMenu = isMac ? [{ label: 'App Name', submenu: [ { role: 'about' }, { type: 'separator' }, { role: 'hide' }, { role: 'hideOthers' }, { role: 'unhide' }, { type: 'separator' }, { role: 'quit' } ] }] : []; await window.krema.invoke('menu:setApplicationMenu', { menu: [ ...appMenu, { label: 'File', submenu: [ { id: 'new', label: 'New', accelerator: 'CmdOrCtrl+N' }, { id: 'open', label: 'Open...', accelerator: 'CmdOrCtrl+O' }, { type: 'separator' }, isMac ? { role: 'close' } : { role: 'quit' } ] }, { label: 'Edit', submenu: [ { role: 'undo' }, { role: 'redo' }, { type: 'separator' }, { role: 'cut' }, { role: 'copy' }, { role: 'paste' }, ...(isMac ? [ { role: 'selectAll' }, { type: 'separator' }, { label: 'Speech', submenu: [ { role: 'startSpeaking' }, { role: 'stopSpeaking' } ] } ] : [ { role: 'selectAll' } ]) ] } ] }); } ``` -------------------------------- ### Grant Autostart Permissions Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/plugins/autostart.md Configure TOML permissions to allow the 'autostart:manage' action. ```toml [permissions] allow = ["autostart:manage"] ``` -------------------------------- ### Get Screen Information Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/native-apis.md Retrieves details about all screens, including their bounds, scale factor, and primary status. Also shows how to get the current cursor position. ```java import build.krema.api.screen.Screen; @KremaCommand public List getScreens() { return Screen.all().stream() .map(s -> new ScreenInfo( s.bounds(), s.scaleFactor(), s.isPrimary() )) .toList(); } @KremaCommand public Point getCursorPosition() { return Screen.cursorPosition(); } ``` -------------------------------- ### Install GraalVM JDK 25+ on Linux with SDKMAN Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/native-image.md Install GraalVM JDK 25 or later on Linux using SDKMAN. This is a convenient way to manage Java versions. ```bash sdk install java 25-graalce ``` -------------------------------- ### Krema Bundling Process Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/advanced/architecture.md Describes the steps for bundling the Krema application into platform-specific formats, such as .app/.dmg for macOS, .exe installer for Windows, and .AppImage for Linux. It also mentions the optional step of signing and notarizing the bundles. ```bash krema bundle │ ├─► Detect platform │ ├─► Create platform-specific bundle │ ├── macOS: .app + .dmg │ ├── Windows: .exe installer │ └── Linux: .AppImage │ └─► Optional: Sign and notarize ``` -------------------------------- ### Plugin Manifest Example (plugin.json) Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs/design.md Illustrates the structure of a `plugin.json` manifest file. This file declares plugin metadata, entry point, permissions, and dependencies. ```json { "name": "fs", "version": "1.0.0", "description": "File system operations", "main": "build.krema.plugin.fs.FsPlugin", "permissions": ["fs:read", "fs:write"], "dependencies": [] } ``` -------------------------------- ### Install GraalVM JDK 25+ on Linux manually Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/native-image.md Manually install GraalVM JDK 25 or later on Linux by downloading and extracting the archive. Set the GRAALVM_HOME and PATH environment variables. ```bash # Download from https://www.graalvm.org/downloads/ tar -xzf graalvm-jdk-25_linux-x64.tar.gz export GRAALVM_HOME=/path/to/graalvm-jdk-25 export PATH="$GRAALVM_HOME/bin:$PATH" ``` -------------------------------- ### State Management: Tauri AppState vs. Krema Constructor Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/migration/from-tauri.md Demonstrates how state is managed differently in Tauri using AppState and in Krema via constructor injection for commands. ```rust struct AppState { db: Mutex, } #[tauri::command] fn query(state: State) -> Vec { state.db.lock().unwrap().query() } ``` ```java public class Commands { private final Database db; public Commands(Database db) { this.db = db; } @KremaCommand public List query() { return db.query(); } } ``` -------------------------------- ### Set GraalVM Environment Variables Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/advanced/troubleshooting.md Configure the GRAALVM_HOME and PATH environment variables to use a specific GraalVM installation for native image builds. Verify the installation by checking the native-image version. ```bash export GRAALVM_HOME=/path/to/graalvm-jdk-25 export PATH="$GRAALVM_HOME/bin:$PATH" # Verify (native-image is built-in with GraalVM 25+) native-image --version ``` -------------------------------- ### Configure Main Class for Native Build Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/native-image.md Set the 'main_class' in 'krema.toml' to specify the entry point for native builds. ```toml [build] main_class = "com.example.myapp.Main" ``` -------------------------------- ### Build Krema Application for Production Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/quick-start.md Build the Krema application for production and create a distributable bundle. ```bash # Build the app krema build # Create a distributable bundle (.app, .exe, .AppImage) krema bundle ``` -------------------------------- ### Get Hostname Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/os-info.md Retrieve the machine's hostname. ```javascript const hostname = await window.krema.invoke('os:hostname'); // "my-macbook.local" ``` -------------------------------- ### Get Username Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/os-info.md Retrieve the current user's username. ```javascript const username = await window.krema.invoke('os:username'); // "john" ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/getting-started/quick-start.md Change the current directory to your newly created Krema project. ```bash cd my-app ``` -------------------------------- ### Bundle Options: Skip Build, Sign, Notarize, and Environment Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/guides/building.md Utilize command-line options to control the bundling process, such as skipping the build step, signing, notarizing for macOS, or specifying an environment profile. ```bash # Skip the build step (if already built) krema bundle --skip-build # Sign the bundle krema bundle --sign # Sign and notarize (macOS only) krema bundle --notarize # Use a specific environment profile krema bundle --env production ``` -------------------------------- ### Screen API - cursorPosition Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/javascript-api.md Gets the current position of the mouse cursor on the screen. ```APIDOC ## Screen API - cursorPosition ### Description Get current cursor position. ### Method ```typescript function cursorPosition(): Promise<{ x: number; y: number }>; ``` ### Response #### Success Response (200) - **{ x: number; y: number }**: An object containing the x and y coordinates of the cursor. ``` -------------------------------- ### Accelerator Format Example Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/menu-shortcut.md Illustrates the format for defining keyboard shortcuts (accelerators) in menu items. Modifiers like Cmd, Ctrl, Alt, and Shift can be combined with keys. ```plaintext CmdOrCtrl+S // Cmd on macOS, Ctrl elsewhere Cmd+Shift+Z // macOS only Ctrl+Alt+Delete // Windows/Linux F11 // Function key ``` -------------------------------- ### Get All Environment Variables Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/os-info.md Retrieve all environment variables available on the system as an object. ```javascript const env = await window.krema.invoke('os:envAll'); // { // PATH: "/usr/local/bin:/usr/bin:/bin", // HOME: "/Users/john", // USER: "john", // ... // } ``` -------------------------------- ### dock:getBadge Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/dock.md Gets the current badge text displayed on the dock icon. ```APIDOC ## dock:getBadge ### Description Gets the current badge text. ### Method INVOKE ### Endpoint dock:getBadge ### Response #### Success Response (200) - **badge** (string) - The current badge text, or an empty string if no badge is set. ``` -------------------------------- ### Build Frontend Separately Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/advanced/troubleshooting.md Before building the Krema application, navigate to the 'src' directory, install npm dependencies, and run the build script for the frontend. This ensures frontend assets are ready. ```bash cd src npm install npm run build ``` -------------------------------- ### Get Application Configuration Directory Source: https://github.com/krema-build/krema/blob/master/krema-docs/docs-site/docs/api/javascript-api.md Retrieves the directory path for application configuration files. ```typescript function appConfigDir(): Promise; ```