本文整理汇总了TypeScript中eez-studio-shared/service.service函数的典型用法代码示例。如果您正苦于以下问题:TypeScript service函数的具体用法?TypeScript service怎么用?TypeScript service使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了service函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
import { service } from "eez-studio-shared/service";
import { db } from "eez-studio-shared/db";
export default service<void, void>("db-services/vacuum", async () => {
db.exec("VACUUM");
});
示例2: serviceImplementation
import { service } from "eez-studio-shared/service";
import { FontProperties } from "font-services/interfaces";
import * as FreeTypeModule from "font-services/freetype";
interface Params {
font: FontProperties;
projectFilePath: string;
}
function serviceImplementation(data: Params) {
const { rebuildFont } = require("font-services/freetype") as typeof FreeTypeModule;
return rebuildFont(data.font, data.projectFilePath);
}
export default service("font-services/font-rebuild", serviceImplementation, true);
示例3: service
import { service } from "eez-studio-shared/service";
export default service("pdf-services/pdf-to-png", async (data: string) => {
const pdfjsLib = require("../../libs/pdfjs/build/pdf.js");
pdfjsLib.GlobalWorkerOptions.workerSrc = "../../libs/pdfjs/build/pdf.worker.js";
var pdfDocument = await pdfjsLib.getDocument(data);
var page = await pdfDocument.getPage(1);
var viewport = page.getViewport(1.0);
var canvas = document.createElement("canvas");
canvas.height = viewport.height;
canvas.width = viewport.width;
var context = canvas.getContext("2d");
var renderContext = {
canvasContext: context,
viewport: viewport
};
await page.render(renderContext);
return canvas.toDataURL();
});
示例4: require
if (path.extname(data.relativeFilePath) == ".bdf") {
const { extractBdfFont } = require("font-services/bdf") as typeof BdfModule;
return extractBdfFont(
data.name,
data.absoluteFilePath,
data.relativeFilePath,
data.bpp,
data.createGlyphs,
data.fromEncoding,
data.toEncoding,
data.createBlankGlyphs || false
);
} else {
const { extractFreeTypeFont } = require("font-services/freetype") as typeof FreeTypeModule;
return extractFreeTypeFont(
data.name,
data.absoluteFilePath,
data.relativeFilePath,
data.bpp,
data.size,
data.threshold,
data.createGlyphs,
data.fromEncoding,
data.toEncoding,
data.createBlankGlyphs || false
);
}
}
export default service("font-services/font-extract", serviceImplementation, true);
示例5: async
import { service } from "eez-studio-shared/service";
import { db } from "eez-studio-shared/db";
interface Params {
query: string;
args: any[];
}
interface Result {
err: any;
rows: any[];
}
export default service<Params, Result>("db-services/query", async (inputParams: Params) => {
try {
const rows = db.prepare(inputParams.query).all(...inputParams.args);
return {
err: null,
rows
};
} catch (err) {
return {
err,
rows: []
};
}
});