Skip to content

Commit 7e87326

Browse files
committed
feat: toast window shadow
1 parent a5f6a86 commit 7e87326

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

electron/mapi/app/toast.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { BrowserWindow } from "electron";
2-
import { icons } from "./icons";
3-
import { AppsMain } from "./main";
1+
import {BrowserWindow} from "electron";
2+
import {icons} from "./icons";
3+
import {AppsMain} from "./main";
44

55
let win = null;
66
let winCloseTimer = null;
@@ -55,6 +55,7 @@ export const makeToast = async (
5555
win = new BrowserWindow({
5656
height,
5757
width,
58+
parent: null,
5859
x: 0,
5960
y: 0,
6061
modal: false,
@@ -68,7 +69,7 @@ export const makeToast = async (
6869
focusable: false,
6970
skipTaskbar: true,
7071
});
71-
const htmlContent = `
72+
const htmlContent = `
7273
<!DOCTYPE html>
7374
<html>
7475
<head>
@@ -83,29 +84,29 @@ export const makeToast = async (
8384
}
8485
.message-view {
8586
height: 100%;
86-
display:flex;
8787
text-align:center;
88-
padding:10px;
8988
box-sizing: border-box;
89+
background-color:transparent;
90+
padding: 10px;
9091
}
9192
.message-view div{
9293
margin: auto;
9394
font-size: 16px;
9495
display: inline-flex;
9596
align-items: center;
9697
line-height: 20px;
97-
white-space: nowrap;
9898
background: rgba(0, 0, 0, 0.85);
9999
border-radius: 15px;
100-
padding: 8px 14px;
101-
box-shadow: 0 6px 18px rgba(0,0,0,0.3);
100+
padding: 10px 10px;
101+
box-shadow: 5px 5px 5px rgba(0,0,0,0.3);
102102
}
103103
.message-view div .icon{
104104
width: 30px;
105105
height: 30px;
106106
display:inline-block;
107107
margin-right: 8px;
108108
vertical-align: middle;
109+
flex-shrink: 0;
109110
}
110111
::-webkit-scrollbar {
111112
width: 0;
@@ -124,18 +125,20 @@ export const makeToast = async (
124125
win.loadURL(`data:text/html;charset=UTF-8,${encodedHTML}`);
125126
win.on("ready-to-show", async () => {
126127
if (!win) return;
127-
const width = Math.ceil(
128-
await win.webContents.executeJavaScript(`(()=>{
128+
const containerSize = await win.webContents.executeJavaScript(`(()=>{
129129
const message = document.getElementById('message');
130130
const width = message.scrollWidth;
131-
return width;
132-
})()`)
133-
);
134-
win.setSize(width + 20, height);
135-
const x = display.workArea.x + display.workArea.width / 2 - (width + 20) / 2;
131+
const height = message.scrollHeight;
132+
return {width:width,height:height};
133+
})()`);
134+
// console.log('containerSize', containerSize);
135+
const containerWidth = containerSize.width + 20;
136+
const containerHeight = containerSize.height + 20;
137+
win.setSize(containerWidth, containerHeight);
138+
const x = display.workArea.x + display.workArea.width / 2 - containerWidth / 2;
136139
const y = display.workArea.y + (display.workArea.height * 1) / 4;
137140
win.setPosition(Math.floor(x), Math.floor(y));
138-
win.show();
141+
win.showInactive();
139142
// win.webContents.openDevTools({
140143
// mode: 'detach'
141144
// })

0 commit comments

Comments
 (0)