本文整理匯總了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: []
};
}
});