community templates (#691)
This commit is contained in:
@@ -5,7 +5,7 @@ import http from "isomorphic-git/http/node";
|
||||
import { app } from "electron";
|
||||
import { copyDirectoryRecursive } from "../utils/file_utils";
|
||||
import { readSettings } from "@/main/settings";
|
||||
import { DEFAULT_TEMPLATE_ID, getTemplateOrThrow } from "@/shared/templates";
|
||||
import { getTemplateOrThrow } from "../utils/template_utils";
|
||||
import log from "electron-log";
|
||||
|
||||
const logger = log.scope("createFromTemplate");
|
||||
@@ -16,7 +16,7 @@ export async function createFromTemplate({
|
||||
fullAppPath: string;
|
||||
}) {
|
||||
const settings = readSettings();
|
||||
const templateId = settings.selectedTemplateId ?? DEFAULT_TEMPLATE_ID;
|
||||
const templateId = settings.selectedTemplateId;
|
||||
|
||||
if (templateId === "react") {
|
||||
await copyDirectoryRecursive(
|
||||
@@ -26,7 +26,7 @@ export async function createFromTemplate({
|
||||
return;
|
||||
}
|
||||
|
||||
const template = getTemplateOrThrow(templateId);
|
||||
const template = await getTemplateOrThrow(templateId);
|
||||
if (!template.githubUrl) {
|
||||
throw new Error(`Template ${templateId} has no GitHub URL`);
|
||||
}
|
||||
|
||||
19
src/ipc/handlers/template_handlers.ts
Normal file
19
src/ipc/handlers/template_handlers.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { createLoggedHandler } from "./safe_handle";
|
||||
import log from "electron-log";
|
||||
import { getAllTemplates } from "../utils/template_utils";
|
||||
import { localTemplatesData, type Template } from "../../shared/templates";
|
||||
|
||||
const logger = log.scope("template_handlers");
|
||||
const handle = createLoggedHandler(logger);
|
||||
|
||||
export function registerTemplateHandlers() {
|
||||
handle("get-templates", async (): Promise<Template[]> => {
|
||||
try {
|
||||
const templates = await getAllTemplates();
|
||||
return templates;
|
||||
} catch (error) {
|
||||
logger.error("Error fetching templates:", error);
|
||||
return localTemplatesData;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user