FEAT: Launch with custom config location
FEAT: Generate banner FEAT: Start blender with banner
This commit is contained in:
+71
-18
@@ -7,7 +7,11 @@ import {
|
||||
import { stat, mkdir, readDir, copyFile, rename, remove } from '@tauri-apps/plugin-fs';
|
||||
import { open } from '@tauri-apps/plugin-dialog';
|
||||
import baseicon from '$lib/assets/baseicon.png';
|
||||
import europa from '$lib/assets/fonts/Europa-Mono-Medium.otf';
|
||||
import { BASE_LIBRARY_DIR } from './settings';
|
||||
import figlet from 'figlet';
|
||||
import shadow from 'figlet/fonts/Classy';
|
||||
figlet.parseFont('Big', shadow);
|
||||
|
||||
/**
|
||||
* Create a custom icon with text overlay
|
||||
@@ -19,45 +23,32 @@ export async function createIcon(iconText) {
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
// Load the base icon image
|
||||
const img = new Image();
|
||||
img.src = baseicon;
|
||||
|
||||
// Wait for image to load
|
||||
await new Promise((resolve) => {
|
||||
img.onload = resolve;
|
||||
});
|
||||
|
||||
// Set canvas dimensions to match image
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
|
||||
// Draw the base icon
|
||||
ctx.drawImage(img, 0, 0);
|
||||
|
||||
// Set text properties
|
||||
ctx.fillStyle = '#7d70ba';
|
||||
ctx.textAlign = 'left';
|
||||
ctx.textBaseline = 'top';
|
||||
|
||||
// Load the custom font
|
||||
const fontFace = new FontFace(
|
||||
'Europa-Mono',
|
||||
`url(${baseicon.replace('baseicon.png', 'fonts/Europa-Mono-Medium.otf')})`
|
||||
);
|
||||
const fontFace = new FontFace('Europa-Mono', `url(${europa})`);
|
||||
await fontFace.load();
|
||||
document.fonts.add(fontFace);
|
||||
|
||||
// Set font size based on canvas dimensions
|
||||
const fontSize = canvas.width / 6;
|
||||
ctx.font = `${fontSize}px Europa-Mono`;
|
||||
// Set font size based on canvas dimensions
|
||||
|
||||
// Add version text in the center
|
||||
const text = iconText || 'XXX';
|
||||
ctx.fillText(text, 150, 150);
|
||||
|
||||
// Convert canvas to blob
|
||||
return new Promise((resolve) => {
|
||||
canvas.toBlob((blob) => {
|
||||
resolve(blob);
|
||||
@@ -65,6 +56,71 @@ export async function createIcon(iconText) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a custom banner with version number next to the baseIcon image
|
||||
* @param {string} versionText - Version text to display
|
||||
* @returns {Promise<Blob>} Promise resolving to a PNG blob of the banner
|
||||
*/
|
||||
export async function createBanner(versionText) {
|
||||
// Create canvas element for banner
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
// Set banner dimensions
|
||||
canvas.width = 600;
|
||||
canvas.height = 90;
|
||||
|
||||
// Draw background
|
||||
ctx.fillStyle = '#171a21';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Load and draw base icon
|
||||
const img = new Image();
|
||||
img.src = baseicon;
|
||||
|
||||
await new Promise((resolve) => {
|
||||
img.onload = resolve;
|
||||
});
|
||||
|
||||
// Calculate icon position (centered vertically, left-aligned)
|
||||
const iconSize = 70;
|
||||
const iconX = 20;
|
||||
const iconY = (canvas.height - iconSize) / 2;
|
||||
|
||||
// Add version text
|
||||
ctx.fillStyle = '#f5f5f5';
|
||||
ctx.textAlign = 'left';
|
||||
ctx.textBaseline = 'middle';
|
||||
|
||||
const fontFace = new FontFace('Europa-Mono', `url(${europa})`);
|
||||
await fontFace.load();
|
||||
document.fonts.add(fontFace);
|
||||
const fontSize = 10;
|
||||
ctx.font = `${fontSize}px Europa-Mono`;
|
||||
|
||||
// Position text to the right of the icon
|
||||
const textX = 20;
|
||||
const textY = canvas.height / 2;
|
||||
|
||||
const bannerText = await figlet.text(versionText + ' - Base', { font: 'Big' });
|
||||
const lines = bannerText.split('\n');
|
||||
const lineHeight = fontSize * 1.2;
|
||||
const startY = textY - (lines.length * lineHeight) / 2 + lineHeight / 2;
|
||||
|
||||
ctx.font = `${fontSize}px monospace`;
|
||||
ctx.textAlign = 'left';
|
||||
ctx.textBaseline = 'top';
|
||||
|
||||
lines.forEach((line, index) => {
|
||||
ctx.fillText(line, textX, startY + index * lineHeight);
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
canvas.toBlob((blob) => {
|
||||
resolve(blob);
|
||||
}, 'image/png');
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create library directory structure if it doesn't exist
|
||||
* @param {string} libraryDir - Library directory path
|
||||
@@ -72,13 +128,10 @@ export async function createIcon(iconText) {
|
||||
*/
|
||||
export async function ensureLibraryStructure(libraryDir) {
|
||||
try {
|
||||
// Create main library directory
|
||||
const baseDir = await join(libraryDir, BASE_LIBRARY_DIR);
|
||||
// Create blender subdirectory
|
||||
const blenderDir = await join(baseDir, 'blender');
|
||||
await mkdir(blenderDir, { recursive: true });
|
||||
|
||||
// Create templates subdirectory
|
||||
const templatesDir = await join(baseDir, 'templates');
|
||||
await mkdir(templatesDir, { recursive: true });
|
||||
|
||||
@@ -99,7 +152,7 @@ export async function ensureLibraryStructure(libraryDir) {
|
||||
*/
|
||||
export async function selectDirectory(currentPath) {
|
||||
try {
|
||||
// Use currentPath if provided, otherwise use app data directory
|
||||
// Use currentPath if proided, otherwise use app data directory
|
||||
let defaultPath = await appDataDir();
|
||||
if (currentPath) {
|
||||
defaultPath = currentPath;
|
||||
|
||||
Reference in New Issue
Block a user