Skip to content

Commit

Permalink
tmp: add ui and localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Shxuuer committed Jan 20, 2025
1 parent 4d4935e commit 1b35ae7
Show file tree
Hide file tree
Showing 12 changed files with 1,590 additions and 351 deletions.
653 changes: 400 additions & 253 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email",
"version": "1.0.0",
"name": "lw-mail",
"version": "0.0.2",
"description": "",
"main": "main.js",
"scripts": {
Expand All @@ -13,11 +13,11 @@
"dependencies": {
"iconv-lite": "^0.6.3",
"imap": "^0.8.19",
"node-localstorage": "^3.0.5",
"readline": "^1.3.0"
},
"devDependencies": {
"@types/electron": "^1.6.12",
"@types/node": "^22.10.7",
"@types/node-localstorage": "^1.3.3",
"copyfiles": "^2.4.1",
"electron": "^34.0.0",
"nodemon": "^3.1.9",
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ LWmail: A concise email client
## build

```bash
npm install
npm buildjs
yarn install
npm run buildjs
```
2 changes: 1 addition & 1 deletion src/interface.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface mail {
getMailBoxes: () => Promise<any>;
safeStorageMailInfo: (mail: {}) => Promise<any>;
}

declare global {
Expand Down
17 changes: 6 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app, BrowserWindow, ipcMain, Menu, Tray } from 'electron';
import * as path from 'path';
import { mailServices } from './mail/mailManager';
import { LocalStorage } from 'node-localstorage';

let mainWindow: BrowserWindow | null = null;

Expand Down Expand Up @@ -36,17 +36,12 @@ const createTray = () => {
};

const handleIPC = () => {
ipcMain.handle('get-mail-boxes', async () => {
// return mailServices.map(
// async (mailService) => await mailService.getMailBoxes(),
// );
return mailServices[0].getMailBoxes();
// return mailServices.map((mailService) => mailService.getMailBoxes());
});
ipcMain.handle('get-mail-box', async (event, boxName: string) => {
return mailServices.map(
async (mailService) => await mailService.getMailBox(boxName),
ipcMain.on('safe-storage-mail-info', (event, mail) => {
const localStorage: LocalStorage = new LocalStorage(
path.join(__dirname, 'config'),
);
localStorage.setItem('mail', JSON.stringify(mail));
console.log(localStorage.getItem('mail'));
});
};

Expand Down
37 changes: 0 additions & 37 deletions src/pages/components.ts

This file was deleted.

58 changes: 57 additions & 1 deletion src/pages/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
flex-direction: row;
margin-bottom: 20px;
}
.left-bar {
#left-bar {
width: 30%;
height: 100%;
background-color: rgba(245, 250, 255, 0.65);
Expand Down Expand Up @@ -108,3 +108,59 @@
.mail-box-name:hover {
background-color: #f0f5ff;
}
.pop {
top: 0;
left: 0;
z-index: 100;
position: absolute;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
}
.input-pop {
width: 300px;
background-color: #fff;
border-radius: 5px;
display: flex;
flex-direction: column;
}
.input-pop-title {
width: 100%;
padding: 5px 10px;
font-size: 1.3em;
border-bottom: 1px solid #e0e0e0;
height: fit-content;
}
.input-pop-area {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
.input-pop-area {
width: 100%;
display: flex;
flex-direction: column;
}
.input-pop-container {
width: 100%;
display: flex;
flex-direction: column;
padding: 5px;
}
.input-pop-label {
color: #1e1e1e;
font-size: 0.9em;
}
.input-pop-input {
display: block;
width: 70%;
}
.input-pop-confirm {
width: 100%;
margin-top: 20px;
height: 2em;
}
4 changes: 2 additions & 2 deletions src/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<style type="text/css"></style>
</head>
<body>
<body style="position: relative">
<div class="container">
<div class="header">
<div class="add-mail">
Expand All @@ -16,7 +16,7 @@
</div>

<div class="main">
<div class="left-bar">
<div id="left-bar">
<div class="one-mail">
<div class="mail-addr">
<img src="../../static//off.svg" />
Expand Down
145 changes: 108 additions & 37 deletions src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,109 @@
// export interface Mail {
// mailAddr: string;
// open: boolean;
// boxes: Box[];
// }
// export interface Box {
// boxName: string;
// open: boolean;
// mails: [];
// }
// export interface MailState {}
// const mails: Mail[] = [
// {
// mailAddr: '[email protected]',
// open: false,
// boxes: [
// {
// boxName: '收件箱',
// open: false,
// mails: [],
// },
// ],
// },
// {
// mailAddr: '[email protected]',
// open: false,
// boxes: [
// {
// boxName: '收件箱',
// open: false,
// mails: [],
// },
// ],
// },
// ];
import { createOneMail } from './components';
function createMailBox(boxName: string) {
const mailBox = document.createElement('div');
mailBox.className = 'mail-box';
const mailBoxName = document.createElement('div');
mailBoxName.className = 'mail-box-name';
mailBoxName.innerText = boxName;
const mails = document.createElement('div');
mails.className = 'mails';
mailBox.appendChild(mailBoxName);
mailBox.appendChild(mails);
return mailBox;
}

function createMailBoxes(boxes: string[]) {
const mailBoxes = document.createElement('div');
mailBoxes.className = 'mail-boxes';
boxes.forEach((boxName) => {
mailBoxes.appendChild(createMailBox(boxName));
});
return mailBoxes;
}

function createOneMail(mail: string, boxes: string[]) {
const oneMail = document.createElement('div');
oneMail.className = 'one-mail';
const mailAddr = document.createElement('div');
mailAddr.className = 'mail-addr';
const img = document.createElement('img');
img.src = '../../static/off.svg';
const span = document.createElement('span');
span.innerText = mail;
mailAddr.appendChild(img);
mailAddr.appendChild(span);
oneMail.appendChild(mailAddr);
oneMail.appendChild(createMailBoxes(boxes));
return oneMail;
}

function createPop(inner: HTMLElement) {
const body = document.body;
const pop = document.createElement('div');
pop.className = 'pop';
pop.appendChild(inner);
body.appendChild(pop);
}

const leftBar = document.getElementById('left-bar');
leftBar?.appendChild(createOneMail('[email protected]', ['收件箱']));
const inner = createOneMail('[email protected]', ['收件箱']);
leftBar?.appendChild(inner);

document.getElementsByClassName('add-mail')[0].addEventListener('click', () => {
const inputPop = document.createElement('div');
inputPop.className = 'input-pop';
const title = document.createElement('div');
title.className = 'input-pop-title';
title.innerText = '添加邮箱';
inputPop.appendChild(title);
const inputArea = document.createElement('div');
inputArea.className = 'input-pop-area';
inputPop.appendChild(inputArea);

function createInput(info: {
label: string;
id: string;
password?: boolean;
}) {
const container = document.createElement('div');
container.className = 'input-pop-container';
const labelElement = document.createElement('label');
labelElement.innerText = info.label;
labelElement.className = 'input-pop-label';
const inputElement = document.createElement('input');
inputElement.type = info.password ? 'password' : 'text';
inputElement.id = info.id;
inputElement.className = 'input-pop-input';
container.appendChild(labelElement);
container.appendChild(inputElement);
return container;
}
const infos = [
{ label: 'imap服务器', id: 'imap' },
{ label: 'imap端口号', id: 'imap-port' },
{ label: 'smtp服务器', id: 'smtp' },
{ label: 'smtp端口号', id: 'smtp-port' },
{ label: '邮箱地址', id: 'mail-addr' },
{ label: '密码', id: 'password', password: true },
];
infos.forEach((info) => {
inputArea.appendChild(createInput(info));
});

const confirm = document.createElement('button');
confirm.innerText = '确定';
confirm.className = 'input-pop-confirm';
inputPop.appendChild(confirm);
confirm.addEventListener('click', () => {
const inputs = document.getElementsByClassName('input-pop-input');
const mail = {
imap: (inputs[0] as HTMLInputElement).value,
imapPort: (inputs[1] as HTMLInputElement).value,
smtp: (inputs[2] as HTMLInputElement).value,
smtpPort: (inputs[3] as HTMLInputElement).value,
mailAddr: (inputs[4] as HTMLInputElement).value,
password: (inputs[5] as HTMLInputElement).value,
};
window.mail.safeStorageMailInfo(mail);
});
createPop(inputPop);
});
4 changes: 2 additions & 2 deletions src/preload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('mail', {
getMailBoxes: () => ipcRenderer.invoke('get-mail-boxes'),
getMailBox: (boxName: string) => ipcRenderer.invoke('get-mail-box', boxName),
safeStorageMailInfo: (mail: {}) =>
ipcRenderer.send('safe-storage-mail-info', mail),
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es6",
"module": "ES6",
"module": "CommonJS",
"strict": true,
"esModuleInterop": true,
"outDir": "out",
Expand Down
Loading

0 comments on commit 1b35ae7

Please sign in to comment.