本文整理汇总了TypeScript中electron.nativeImage.createFromPath方法的典型用法代码示例。如果您正苦于以下问题:TypeScript nativeImage.createFromPath方法的具体用法?TypeScript nativeImage.createFromPath怎么用?TypeScript nativeImage.createFromPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.nativeImage
的用法示例。
在下文中一共展示了nativeImage.createFromPath方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: windowBounds
app.on("ready", () => {
const bounds = windowBounds();
let options: Electron.BrowserWindowConstructorOptions = {
webPreferences: {
experimentalFeatures: true,
experimentalCanvasFeatures: true,
},
titleBarStyle: "hidden",
resizable: true,
minWidth: 500,
minHeight: 300,
width: bounds.width,
height: bounds.height,
x: bounds.x,
y: bounds.y,
show: false,
};
const browserWindow = new BrowserWindow(options);
if (app.dock) {
app.dock.setIcon(nativeImage.createFromPath("build/icon.png"));
} else {
browserWindow.setIcon(nativeImage.createFromPath("build/icon.png"));
}
browserWindow.loadURL("file://" + __dirname + "/../views/index.html");
browserWindow.webContents.on("did-finish-load", () => {
browserWindow.show();
browserWindow.focus();
});
app.on("open-file", (_event, file) => browserWindow.webContents.send("change-working-directory", file));
});
示例2: initTray
initTray(trayIcon = new Tray(nativeImage.createEmpty())) {
const IMAGE_ROOT = path.join(app.getAppPath(), 'img');
let trayPng = 'tray.png';
let trayBadgePng = 'tray.badge.png';
if (EnvironmentUtil.platform.IS_LINUX) {
trayPng = `tray${EnvironmentUtil.linuxDesktop.isGnome ? '.gnome' : '@3x'}.png`;
trayBadgePng = `tray.badge${EnvironmentUtil.linuxDesktop.isGnome ? '.gnome' : '@3x'}.png`;
}
const iconPaths = {
badge: path.join(IMAGE_ROOT, 'taskbar.overlay.png'),
tray: path.join(IMAGE_ROOT, 'tray-icon/tray', trayPng),
trayWithBadge: path.join(IMAGE_ROOT, 'tray-icon/tray-with-badge', trayBadgePng),
};
this.icons = {
badge: nativeImage.createFromPath(iconPaths.badge),
tray: nativeImage.createFromPath(iconPaths.tray),
trayWithBadge: nativeImage.createFromPath(iconPaths.trayWithBadge),
};
this.trayIcon = trayIcon;
this.trayIcon.setImage(this.icons.tray);
this.buildTrayMenu();
}
示例3:
thumbarButtons.forEach(thumbarButton => {
const imagePath = path.join(__dirname.replace('api', ''), 'bin', thumbarButton.icon.toString());
thumbarButton.icon = nativeImage.createFromPath(imagePath);
thumbarButton.click = () => {
socket.emit("thumbarButtonClicked", thumbarButton["id"]);
};
});
示例4: async
watcher.on(actions.notify, async (store, action) => {
const {
title = "itch",
body,
icon = DEFAULT_ICON,
onClick,
} = action.payload;
if (Notification.isSupported()) {
const n = new Notification({
title,
subtitle: null,
body,
icon: icon ? nativeImage.createFromPath(icon) : null,
actions: null,
});
if (onClick) {
n.on("click", e => {
store.dispatch(actions.focusWindow({ window: "root" }));
store.dispatch(onClick);
});
}
n.show();
} else {
logger.warn(`Cannot show notification: ${body}`);
}
});
示例5: getEmojiIcon
/**
@returns An icon to use for the menu item of this emoji style.
*/
async function getEmojiIcon(style: EmojiStyle): Promise<NativeImage | undefined> {
const cachedIcon = cachedEmojiMenuIcons.get(style);
if (cachedIcon) {
return cachedIcon;
}
if (style === 'native') {
if (!getWindow()) {
return undefined;
}
const dataUrl = await renderEmoji('đ');
const image = nativeImage.createFromDataURL(dataUrl);
const resizedImage = image.resize({width: 16, height: 16});
cachedEmojiMenuIcons.set(style, resizedImage);
return resizedImage;
}
const image = nativeImage.createFromPath(
path.join(__dirname, '..', 'static', `emoji-${style}.png`)
);
cachedEmojiMenuIcons.set(style, image);
return image;
}
示例6: createTrayIconImage
function createTrayIconImage(imageName: string) {
const image =
nativeImage.createFromPath(path.join(app.getAppPath(), 'resources', 'tray', imageName));
if (image.isEmpty()) {
throw new Error(`cannot find ${imageName} tray icon image`);
}
return image;
}
示例7: normalmapToHeightmap
export function normalmapToHeightmap(nmfile,worldw:number, worldh:number):Float32Array{
var img = nativeImage.createFromPath(nmfile);
if(!img){
throw 'open failed';
}
var buf = img.toBitmap() as Buffer;
var sz = img.getSize();
var w = sz.width;
var h = sz.height;
var hm = new Float32Array(w*h);
//test
saveFloatArray(hm, w,h, 'd:/temp/hm.png');
debugger;
return hm;
}
示例8: startMainWindow
function startMainWindow() {
'use strict';
const index_html = 'file://' + join(__dirname, '..', 'renderer', 'main.html');
const default_config = {
width: 800,
height: 600,
useContentSize: true,
webPreferences: {
blinkFeatures: 'KeyboardEventKey',
},
icon: nativeImage.createFromPath(join(__dirname, '..', 'resources', 'icon', 'nyaovim-logo.png')),
} as Electron.BrowserWindowOptions;
const user_config = browser_config.applyToOptions(default_config);
let win = new BrowserWindow(user_config);
const already_exists = browser_config.configSingletonWindow(win);
if (already_exists) {
app.quit();
return null;
}
browser_config.setupWindowState(win);
if (browser_config.loaded_config !== null && browser_config.loaded_config.show_menubar === false) {
win.setMenuBarVisibility(false);
}
win.once('closed', function() {
win = null;
});
win.loadURL(index_html);
if (process.env.NODE_ENV !== 'production' && is_run_from_npm_package_on_darwin) {
win.webContents.openDevTools({mode: 'detach'});
}
return win;
}
示例9: getTray
export function getTray(store: Store): Electron.Tray {
if (!tray) {
const iconPath = getImagePath(`tray/${env.appName}.png`);
mainLogger.info(`Using tray image (${iconPath})`);
let iconImage = nativeImage.createFromPath(iconPath);
let onKDE = process.env.XDG_CURRENT_DESKTOP === "KDE";
if (process.platform === "win32") {
// cf. https://github.com/itchio/itch/issues/462
// windows still displays a 16x16, whereas
// some linux DEs don't know what to do with a @x2, etc.
iconImage = iconImage.resize({
width: 16,
height: 16,
});
} else if (onKDE) {
// KDE can't handle a 256x256 png apparently
iconImage = iconImage.resize({
width: 24,
height: 24,
});
}
tray = new Tray(iconImage);
tray.setToolTip(env.appName);
tray.on("click", () => {
store.dispatch(actions.focusWind({ wind: "root", toggle: true }));
});
tray.on("double-click", () => {
store.dispatch(actions.focusWind({ wind: "root" }));
});
tray.on("balloon-click", () => {
if (lastNotificationAction) {
store.dispatch(lastNotificationAction);
}
});
}
return tray;
}
示例10: require
const app: Electron.App = require("app");
const browserWindowConstructor: typeof Electron.BrowserWindow = require("browser-window");
import {ipcMain, nativeImage} from "electron";
import menu from "./Menu";
let fixPath = require("fix-path");
let browserWindow: Electron.BrowserWindow = undefined;
// Fix the $PATH on OS X
fixPath();
if (app.dock) {
app.dock.setIcon(nativeImage.createFromPath("icon.png"));
}
app.on("open-file", (event: Event, file: string) => getMainWindow().webContents.send("change-working-directory", file))
.on("ready", getMainWindow)
.on("activate", getMainWindow)
.on("mainWindow-all-closed", () => process.platform === "darwin" || app.quit());
ipcMain.on("quit", app.quit);
function getMainWindow(): Electron.BrowserWindow {
const screen: Electron.Screen = require("screen");
const workAreaSize = screen.getPrimaryDisplay().workAreaSize;
if (!browserWindow) {
let options: Electron.BrowserWindowOptions = {
webPreferences: {
experimentalFeatures: true,
experimentalCanvasFeatures: true,