Skip to content

Commit

Permalink
feat: 简化代码,移除多余依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
mohuishou committed Jun 21, 2021
1 parent bb4fb6f commit dbf79c8
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions plugins/iconfont/src/iconfont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Axios, { AxiosInstance } from "axios";
import { stringify } from "querystring";
import { writeFileSync } from "fs";
import { join } from "path";
import { nativeImage } from "electron";
interface keywordParams {
[index: string]: { key: string; val: any };
}
Expand Down Expand Up @@ -158,6 +157,14 @@ export class Iconfont implements Plugin {
operate: "copy",
item: item,
},
{
title: "复制 SVG Base64",
description: item.title,
data: item.icon,
icon: "icon/copy.svg",
operate: "copy_svg_base64",
item: item,
},
{
title: "复制 PNG 图片",
description: item.title,
Expand Down Expand Up @@ -194,7 +201,7 @@ export class Iconfont implements Plugin {
case "copy":
tmpPath = join(utools.getPath("temp"), item.id + ".svg");
writeFileSync(tmpPath, item.data);
utools.copyFile(tmpPath);
utools.copyImage(tmpPath);
utools.showNotification("svg 已复制到剪切板");
break;
case "open":
Expand All @@ -215,11 +222,11 @@ export class Iconfont implements Plugin {
break;
case "copy_png":
let dataUrl = await this.svg2png(item.id, item.data);
let img = nativeImage.createFromDataURL(dataUrl);

tmpPath = join(utools.getPath("temp"), item.id + ".png");
writeFileSync(tmpPath, img.toPNG());
utools.copyFile(tmpPath);
utools.copyImage(dataUrl);
utools.showNotification(item.title + "复制成功");
break;
case "copy_svg_base64":
utools.copyText(item.data);
utools.showNotification(item.title + "复制成功");
break;
case "return":
Expand Down

0 comments on commit dbf79c8

Please sign in to comment.