當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript electron.nativeImage類代碼示例

本文整理匯總了TypeScript中electron.nativeImage的典型用法代碼示例。如果您正苦於以下問題:TypeScript nativeImage類的具體用法?TypeScript nativeImage怎麽用?TypeScript nativeImage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了nativeImage類的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));
});
開發者ID:sunyton,項目名稱:upterm,代碼行數:35,代碼來源:Main.ts

示例2: 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;
}
開發者ID:nikteg,項目名稱:caprine,代碼行數:32,代碼來源:emoji.ts

示例3: 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();
  }
開發者ID:wireapp,項目名稱:wire-desktop,代碼行數:28,代碼來源:TrayHandler.ts

示例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}`);
    }
  });
開發者ID:HorrerGames,項目名稱:itch,代碼行數:27,代碼來源:notifications.ts

示例5: Notification

	(_event: ElectronEvent, {id, title, body, icon, silent}: NotificationEvent) => {
		const notification = new Notification({
			title,
			body,
			hasReply: true,
			icon: nativeImage.createFromDataURL(icon),
			silent
		});

		notifications.set(id, notification);

		notification.on('click', () => {
			mainWindow.show();
			sendAction('notification-callback', {callbackName: 'onclick', id});

			notifications.delete(id);
		});

		notification.on('reply', (_event, reply: string) => {
			// We use onclick event used by messenger to go to the right convo
			sendBackgroundAction('notification-reply-callback', {callbackName: 'onclick', id, reply});

			notifications.delete(id);
		});

		notification.on('close', () => {
			sendAction('notification-callback', {callbackName: 'onclose', id});

			notifications.delete(id);
		});

		notification.show();
	}
開發者ID:kusamakura,項目名稱:caprine,代碼行數:33,代碼來源:index.ts

示例6:

 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"]);
     };
 });
開發者ID:E024,項目名稱:Electron.NET,代碼行數:7,代碼來源:browserWindows.ts

示例7: 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;
}
開發者ID:hlyu368,項目名稱:outline-client,代碼行數:8,代碼來源:index.ts

示例8:

			const items = conversations.map(({label, icon}, index) => {
				return {
					label: `${label}`,
					icon: nativeImage.createFromDataURL(icon),
					click: () => {
						mainWindow.show();
						sendAction('jump-to-conversation', index + 1);
					}
				};
			});
開發者ID:kusamakura,項目名稱:caprine,代碼行數:10,代碼來源:index.ts

示例9: TouchBarButton

	const items = conversations.map(({label, selected, icon}, index: number) => {
		return new TouchBarButton({
			label: label.length > 25 ? label.slice(0, 25) + '…' : label,
			backgroundColor: selected ? '#0084ff' : undefined,
			icon: nativeImage.createFromDataURL(icon),
			iconPosition: 'left',
			click: () => {
				sendAction('jump-to-conversation', index + 1);
			}
		});
	});
開發者ID:kusamakura,項目名稱:caprine,代碼行數:11,代碼來源:touch-bar.ts

示例10: saveAsPng

export function saveAsPng(data:ImageData,outfile:string){
    var canv = document.createElement('canvas');
    canv.width=data.width;
    canv.height=data.height;
    var ctx = canv.getContext('2d');
    ctx.putImageData(data,0,0);
    var buf = canv.toDataURL('image/png');
    var nimg = nativeImage.createFromDataURL(buf);
    fs.writeFileSync(outfile,nimg.toPng());
    return nativeImage;
}
開發者ID:guozhaokui,項目名稱:CanvasLabs,代碼行數:11,代碼來源:imgfunc.ts


注:本文中的electron.nativeImage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。