Skip to content

Commit

Permalink
截屏 保存并复制
Browse files Browse the repository at this point in the history
  • Loading branch information
xushengfeng committed Jun 28, 2024
1 parent ec8d024 commit adcabf8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/ShareTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export interface setting {
默认格式: "png" | "jpg" | "svg";
保存路径: { 图片: string; 视频: string };
快速保存: boolean;
保存并复制: boolean;
};
保存名称: { 前缀: string; 时间: string; 后缀: string };
jpg质量: number;
Expand Down
1 change: 1 addition & 0 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,7 @@ var defaultSetting: setting = {
默认格式: "png",
保存路径: { 图片: "", 视频: "" },
快速保存: false,
保存并复制: false,
},
保存名称: { 前缀: "eSearch-", 时间: "YYYY-MM-DD-HH-mm-ss-S", 后缀: "" },
jpg质量: 1,
Expand Down
53 changes: 22 additions & 31 deletions src/renderer/clip/clip_window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ function runCopy() {
});
}
// 保存
var type;
var type: "svg" | "png" | "jpg";
import timeFormat from "../../../lib/time_format";
function runSave() {
if (store.get("保存.快速保存")) {
Expand All @@ -1131,7 +1131,7 @@ function runSave() {
var el = <HTMLDivElement>e.target;
if (el.dataset.value) {
ipcRenderer.send("clip_main_b", "save", el.dataset.value);
type = el.dataset.value;
type = el.dataset.value as typeof type;
sCenterBar("save");
}
};
Expand Down Expand Up @@ -1162,36 +1162,27 @@ function save(message: string) {
if (message) {
const fs = require("fs");
getClipPhoto(type).then((c) => {
switch (type) {
case "svg":
var dataBuffer = Buffer.from(<string>c);
fs.writeFile(message, dataBuffer, (err) => {
if (!err) {
ipcRenderer.send("clip_main_b", "ok_save", message);
}
});
break;
case "png":
var f = (<HTMLCanvasElement>c).toDataURL().replace(/^data:image\/\w+;base64,/, "");
var dataBuffer = Buffer.from(f, "base64");
fs.writeFile(message, dataBuffer, (err) => {
if (!err) {
ipcRenderer.send("clip_main_b", "ok_save", message);
}
});
break;
case "jpg":
var f = (<HTMLCanvasElement>c)
.toDataURL("image/jpeg", store.get("jpg质量") - 0)
.replace(/^data:image\/\w+;base64,/, "");
var dataBuffer = Buffer.from(f, "base64");
fs.writeFile(message, dataBuffer, (err) => {
if (!err) {
ipcRenderer.send("clip_main_b", "ok_save", message);
}
});
break;
let dataBuffer: Buffer;
if (type === "svg") {
dataBuffer = Buffer.from(<string>c);
} else {
let f = "";
if (type === "png") {
f = (<HTMLCanvasElement>c).toDataURL();
} else if (type === "jpg") {
f = (<HTMLCanvasElement>c).toDataURL("image/jpeg", store.get("jpg质量") - 0);
}
dataBuffer = Buffer.from(f.replace(/^data:image\/\w+;base64,/, ""), "base64");
if (store.get("保存.保存并复制")) {
clipboard.writeImage(nativeImage.createFromDataURL(f));
}
}

fs.writeFile(message, dataBuffer, (err) => {
if (!err) {
ipcRenderer.send("clip_main_b", "ok_save", message);
}
});
});
tool.close();
}
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@ <h2>默认格式</h2>
<br>
<t>jpg质量</t>
<range-b out="true" id="jpg质量" min="0" max="1.00" step="0.01" data-path="jpg质量"></range-b>
<br>
<label>
<input type="checkbox" data-path="保存.保存并复制">
<t>保存时自动复制</t>
</label>

<h2>快速保存</h2>
<comment>按下保存键后,默认保存到上次保存的位置,无需选择</comment>
Expand Down

0 comments on commit adcabf8

Please sign in to comment.