Merge branch 'feature/calendar'
Calendar feature via EWS SOAP API: - Week view with event detail popup - NTLM authentication for corporate Exchange - Account switcher + calendar sidebar - EWS FindItem/FindFolder with CalendarView date range Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
4c3b14c7a9
18 changed files with 2455 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ import { AccountManager } from './services/account-manager'
|
|||
import { registerAccountHandlers } from './ipc/accounts.handler'
|
||||
import { registerFolderHandlers } from './ipc/folders.handler'
|
||||
import { registerMessageHandlers } from './ipc/messages.handler'
|
||||
import { registerCalendarHandlers } from './ipc/calendar.handler'
|
||||
import type { ComposeSession } from '@shared/types/message'
|
||||
|
||||
const accountManager = new AccountManager()
|
||||
|
|
@ -142,6 +143,7 @@ app.whenReady().then(async () => {
|
|||
registerAccountHandlers(accountManager)
|
||||
registerFolderHandlers(accountManager)
|
||||
registerMessageHandlers(accountManager)
|
||||
registerCalendarHandlers(accountManager)
|
||||
|
||||
createWindow()
|
||||
|
||||
|
|
|
|||
16
src/main/ipc/calendar.handler.ts
Normal file
16
src/main/ipc/calendar.handler.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import type { AccountManager } from '../services/account-manager'
|
||||
import { registerHandler } from './registry'
|
||||
|
||||
export function registerCalendarHandlers(manager: AccountManager): void {
|
||||
registerHandler('calendar:list', ({ accountId }) =>
|
||||
manager.listCalendars(accountId)
|
||||
)
|
||||
|
||||
registerHandler('calendar:events', ({ accountId, calendarId, start, end }) =>
|
||||
manager.listCalendarEvents(accountId, calendarId, new Date(start), new Date(end))
|
||||
)
|
||||
|
||||
registerHandler('calendar:probe', ({ accountId }) =>
|
||||
manager.probeCalendarPaths(accountId)
|
||||
)
|
||||
}
|
||||
219
src/main/lib/ntlm.ts
Normal file
219
src/main/lib/ntlm.ts
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
/**
|
||||
* NTLM (NTLMv2) authentication for HTTP — MS-NLMP spec.
|
||||
* Pure Node.js crypto, no external deps.
|
||||
*
|
||||
* Flow over HTTP:
|
||||
* Client → Server: method + Authorization: NTLM <Type1>
|
||||
* Server → Client: 401 + WWW-Authenticate: NTLM <Type2-challenge>
|
||||
* Client → Server: method + Authorization: NTLM <Type3> + actual body
|
||||
* Server → Client: 207 / 200
|
||||
*
|
||||
* All three round-trips MUST use the same TCP connection (keepAlive agent).
|
||||
*/
|
||||
|
||||
import crypto from 'node:crypto'
|
||||
|
||||
// ── MD4 (pure JS) ─────────────────────────────────────────────────────────────
|
||||
// Needed for NT hash: MD4(UTF-16LE(password)).
|
||||
// Node.js 20+ / OpenSSL 3.x moved MD4 to the legacy provider, so we
|
||||
// implement it ourselves to avoid any availability issues.
|
||||
|
||||
function md4(buf: Buffer): Buffer {
|
||||
const F = (x: number, y: number, z: number) => (x & y) | (~x & z)
|
||||
const G = (x: number, y: number, z: number) => (x & y) | (x & z) | (y & z)
|
||||
const H = (x: number, y: number, z: number) => x ^ y ^ z
|
||||
const add = (a: number, b: number) => (a + b) >>> 0
|
||||
const rol = (x: number, n: number) => ((x << n) | (x >>> (32 - n))) >>> 0
|
||||
|
||||
const l = buf.length
|
||||
const extra = ((56 - l - 1) % 64 + 64) % 64
|
||||
const padded = Buffer.alloc(l + 1 + extra + 8)
|
||||
buf.copy(padded)
|
||||
padded[l] = 0x80
|
||||
const bitLen = l * 8
|
||||
padded.writeUInt32LE(bitLen >>> 0, padded.length - 8)
|
||||
padded.writeUInt32LE(Math.floor(bitLen / 2 ** 32), padded.length - 4)
|
||||
|
||||
let a = 0x67452301, b = 0xefcdab89, c = 0x98badcfe, d = 0x10325476
|
||||
|
||||
for (let off = 0; off < padded.length; off += 64) {
|
||||
const X = Array.from({ length: 16 }, (_, i) => padded.readUInt32LE(off + i * 4))
|
||||
let [A, B, C, D] = [a, b, c, d]
|
||||
|
||||
// Round 1: F, shifts 3,7,11,19, word order 0..15
|
||||
for (let i = 0; i < 16; i++) {
|
||||
A = rol(add(add(A, F(B, C, D)), X[i]), [3, 7, 11, 19][i & 3])
|
||||
;[A, B, C, D] = [D, A, B, C]
|
||||
}
|
||||
// Round 2: G, shifts 3,5,9,13, word order 0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15
|
||||
const r2 = [0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15]
|
||||
for (let i = 0; i < 16; i++) {
|
||||
A = rol(add(add(add(A, G(B, C, D)), X[r2[i]]), 0x5a827999), [3, 5, 9, 13][i & 3])
|
||||
;[A, B, C, D] = [D, A, B, C]
|
||||
}
|
||||
// Round 3: H, shifts 3,9,11,15, word order 0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15
|
||||
const r3 = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]
|
||||
for (let i = 0; i < 16; i++) {
|
||||
A = rol(add(add(add(A, H(B, C, D)), X[r3[i]]), 0x6ed9eba1), [3, 9, 11, 15][i & 3])
|
||||
;[A, B, C, D] = [D, A, B, C]
|
||||
}
|
||||
|
||||
a = add(a, A); b = add(b, B); c = add(c, C); d = add(d, D)
|
||||
}
|
||||
|
||||
const out = Buffer.alloc(16)
|
||||
out.writeUInt32LE(a, 0); out.writeUInt32LE(b, 4)
|
||||
out.writeUInt32LE(c, 8); out.writeUInt32LE(d, 12)
|
||||
return out
|
||||
}
|
||||
|
||||
// ── NTLM message builder ───────────────────────────────────────────────────────
|
||||
|
||||
const NTLMSSP_SIG = Buffer.from('NTLMSSP\0', 'ascii')
|
||||
|
||||
// Negotiate flags for NTLMv2
|
||||
// UNICODE | REQUEST_TARGET | NTLM | ALWAYS_SIGN | EXTENDED_SESSION_SECURITY | 128bit | 56bit
|
||||
const NTLM_FLAGS = 0xa0088215
|
||||
|
||||
/** Build Type 1 (Negotiate) message. Returns the full Authorization header value. */
|
||||
export function buildNegotiateHeader(): string {
|
||||
const buf = Buffer.alloc(40)
|
||||
NTLMSSP_SIG.copy(buf)
|
||||
buf.writeUInt32LE(1, 8) // MessageType = NTLMSSP_NEGOTIATE
|
||||
buf.writeUInt32LE(NTLM_FLAGS, 12)
|
||||
// DomainName: empty
|
||||
buf.writeUInt16LE(0, 16); buf.writeUInt16LE(0, 18); buf.writeUInt32LE(40, 20)
|
||||
// Workstation: empty
|
||||
buf.writeUInt16LE(0, 24); buf.writeUInt16LE(0, 26); buf.writeUInt32LE(40, 28)
|
||||
return 'NTLM ' + buf.toString('base64')
|
||||
}
|
||||
|
||||
/** Parse the server's Type 2 (Challenge) message from the WWW-Authenticate header value. */
|
||||
export function parseChallenge(headerValue: string): {
|
||||
challenge: Buffer
|
||||
targetInfo: Buffer
|
||||
/** NetBIOS domain name from the server (e.g. "S7"). Use as domain fallback when none in username. */
|
||||
targetName: string
|
||||
} {
|
||||
const b64 = headerValue.replace(/^NTLM\s+/i, '').trim()
|
||||
const buf = Buffer.from(b64, 'base64')
|
||||
|
||||
const serverChallenge = buf.slice(24, 32)
|
||||
|
||||
// TargetNameFields at offset 12: Len(2) MaxLen(2) Offset(4) — the server's NetBIOS domain
|
||||
let targetName = ''
|
||||
if (buf.length >= 20) {
|
||||
const len = buf.readUInt16LE(12)
|
||||
const offset = buf.readUInt32LE(16)
|
||||
if (len > 0 && offset + len <= buf.length) {
|
||||
targetName = buf.slice(offset, offset + len).toString('utf16le')
|
||||
}
|
||||
}
|
||||
|
||||
// TargetInfoFields at offset 40: Len(2) MaxLen(2) Offset(4)
|
||||
let targetInfo = Buffer.alloc(0)
|
||||
if (buf.length >= 48) {
|
||||
const len = buf.readUInt16LE(40)
|
||||
const offset = buf.readUInt32LE(44)
|
||||
if (len > 0 && offset + len <= buf.length) {
|
||||
targetInfo = buf.slice(offset, offset + len)
|
||||
}
|
||||
}
|
||||
|
||||
return { challenge: serverChallenge, targetInfo, targetName }
|
||||
}
|
||||
|
||||
/** Split "DOMAIN\\user", "user@domain", or "user" into { user, domain }. */
|
||||
export function splitUser(username: string): { user: string; domain: string } {
|
||||
const bs = username.indexOf('\\')
|
||||
if (bs !== -1) return { domain: username.slice(0, bs), user: username.slice(bs + 1) }
|
||||
const at = username.indexOf('@')
|
||||
if (at !== -1) return { user: username.slice(0, at), domain: username.slice(at + 1) }
|
||||
return { user: username, domain: '' }
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Type 3 (Authenticate) message.
|
||||
* Returns the full Authorization header value (NTLMv2).
|
||||
*/
|
||||
export function buildAuthenticateHeader(
|
||||
username: string,
|
||||
domain: string,
|
||||
password: string,
|
||||
serverChallenge: Buffer,
|
||||
targetInfo: Buffer
|
||||
): string {
|
||||
// NT hash and NTLMv2 session key
|
||||
const ntHashBuf = md4(Buffer.from(password, 'utf16le'))
|
||||
const responseKeyNT = crypto
|
||||
.createHmac('md5', ntHashBuf)
|
||||
.update(Buffer.from((username.toUpperCase() + domain.toUpperCase()), 'utf16le'))
|
||||
.digest()
|
||||
|
||||
// Client challenge (random 8 bytes)
|
||||
const clientChallenge = crypto.randomBytes(8)
|
||||
|
||||
// Timestamp: 100ns intervals since 1601-01-01 (Windows FILETIME)
|
||||
const EPOCH_DIFF_MS = BigInt('11644473600000') // ms from 1601 to 1970
|
||||
const nowMs = BigInt(Date.now())
|
||||
const fileTime = (nowMs + EPOCH_DIFF_MS) * BigInt(10000)
|
||||
const timestamp = Buffer.alloc(8)
|
||||
timestamp.writeBigUInt64LE(fileTime)
|
||||
|
||||
// NTLMv2 blob (the "NTChallengeResponse blob")
|
||||
const blob = Buffer.concat([
|
||||
Buffer.from([0x01, 0x01, 0x00, 0x00]), // Signature
|
||||
Buffer.from([0x00, 0x00, 0x00, 0x00]), // Reserved
|
||||
timestamp, // Timestamp
|
||||
clientChallenge, // ChallengeFromClient
|
||||
Buffer.from([0x00, 0x00, 0x00, 0x00]), // Reserved
|
||||
targetInfo, // AvPairs from server Type 2
|
||||
Buffer.from([0x00, 0x00, 0x00, 0x00]), // AvPairs list terminator
|
||||
])
|
||||
|
||||
// NTProofStr = HMAC-MD5(ResponseKeyNT, ServerChallenge + blob)
|
||||
const ntProofStr = crypto
|
||||
.createHmac('md5', responseKeyNT)
|
||||
.update(Buffer.concat([serverChallenge, blob]))
|
||||
.digest()
|
||||
|
||||
const ntResponse = Buffer.concat([ntProofStr, blob])
|
||||
const lmResponse = Buffer.alloc(24, 0) // empty LM response
|
||||
|
||||
const userBuf = Buffer.from(username, 'utf16le')
|
||||
const domBuf = Buffer.from(domain, 'utf16le')
|
||||
const wsBuf = Buffer.alloc(0)
|
||||
const skBuf = Buffer.alloc(0) // no session key
|
||||
|
||||
// Build Type 3 header (88 bytes fixed) + payload
|
||||
let payOff = 88
|
||||
const lmOff = payOff; payOff += lmResponse.length
|
||||
const ntOff = payOff; payOff += ntResponse.length
|
||||
const domOff = payOff; payOff += domBuf.length
|
||||
const usrOff = payOff; payOff += userBuf.length
|
||||
const wsOff = payOff; payOff += wsBuf.length
|
||||
const skOff = payOff
|
||||
|
||||
const msg = Buffer.alloc(skOff + skBuf.length)
|
||||
NTLMSSP_SIG.copy(msg)
|
||||
msg.writeUInt32LE(3, 8) // MessageType = NTLMSSP_AUTH
|
||||
|
||||
const writeField = (off: number, len: number, dataOff: number) => {
|
||||
msg.writeUInt16LE(len, off); msg.writeUInt16LE(len, off + 2); msg.writeUInt32LE(dataOff, off + 4)
|
||||
}
|
||||
writeField(12, lmResponse.length, lmOff)
|
||||
writeField(20, ntResponse.length, ntOff)
|
||||
writeField(28, domBuf.length, domOff)
|
||||
writeField(36, userBuf.length, usrOff)
|
||||
writeField(44, wsBuf.length, wsOff)
|
||||
writeField(52, skBuf.length, skOff)
|
||||
msg.writeUInt32LE(NTLM_FLAGS, 60)
|
||||
// Version at 64 (8 bytes) and MIC at 72 (16 bytes) left as zeros
|
||||
|
||||
lmResponse.copy(msg, lmOff)
|
||||
ntResponse.copy(msg, ntOff)
|
||||
domBuf.copy(msg, domOff)
|
||||
userBuf.copy(msg, usrOff)
|
||||
|
||||
return 'NTLM ' + msg.toString('base64')
|
||||
}
|
||||
421
src/main/providers/caldav.provider.ts
Normal file
421
src/main/providers/caldav.provider.ts
Normal file
|
|
@ -0,0 +1,421 @@
|
|||
/**
|
||||
* Exchange calendar provider via EWS (Exchange Web Services) SOAP API.
|
||||
*
|
||||
* Uses only Node.js built-in `https`/`http` — no extra npm deps.
|
||||
* Auth: tries HTTP Basic first; if server demands NTLM, falls back to NTLMv2.
|
||||
* EWS endpoint: POST /EWS/Exchange.asmx
|
||||
*/
|
||||
|
||||
import https from 'node:https'
|
||||
import http from 'node:http'
|
||||
import type { IncomingMessage } from 'node:http'
|
||||
import type { AccountConfig, ImapCredentials } from '@shared/types/account'
|
||||
import type { CalendarInfo, CalendarEvent } from '@shared/types/calendar'
|
||||
import {
|
||||
buildNegotiateHeader,
|
||||
parseChallenge,
|
||||
buildAuthenticateHeader,
|
||||
splitUser
|
||||
} from '../lib/ntlm'
|
||||
|
||||
// ── HTTP helper ────────────────────────────────────────────────────────────────
|
||||
|
||||
interface RequestOptions {
|
||||
protocol: 'https' | 'http'
|
||||
hostname: string
|
||||
port: number
|
||||
path: string
|
||||
method: string
|
||||
headers: Record<string, string>
|
||||
body?: string
|
||||
allowSelfSigned?: boolean
|
||||
agent?: https.Agent | http.Agent
|
||||
}
|
||||
|
||||
interface RequestResult {
|
||||
status: number
|
||||
headers: IncomingMessage['headers']
|
||||
body: string
|
||||
}
|
||||
|
||||
function rawRequest(opts: RequestOptions): Promise<RequestResult> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const module_ = opts.protocol === 'https' ? https : http
|
||||
const req = module_.request(
|
||||
{
|
||||
hostname: opts.hostname,
|
||||
port: opts.port,
|
||||
path: opts.path,
|
||||
method: opts.method,
|
||||
headers: opts.headers,
|
||||
rejectUnauthorized: !opts.allowSelfSigned,
|
||||
timeout: 15_000,
|
||||
agent: opts.agent
|
||||
},
|
||||
(res) => {
|
||||
let data = ''
|
||||
res.setEncoding('utf8')
|
||||
res.on('data', (chunk) => { data += chunk })
|
||||
res.on('end', () => {
|
||||
resolve({ status: res.statusCode ?? 0, headers: res.headers, body: data })
|
||||
})
|
||||
}
|
||||
)
|
||||
req.on('timeout', () => { req.destroy(new Error('Request timed out')) })
|
||||
req.on('error', reject)
|
||||
if (opts.body) req.write(opts.body)
|
||||
req.end()
|
||||
})
|
||||
}
|
||||
|
||||
// ── EWS Provider ──────────────────────────────────────────────────────────────
|
||||
|
||||
type AuthMode = 'basic' | 'ntlm'
|
||||
|
||||
const EWS_PATH = '/EWS/Exchange.asmx'
|
||||
|
||||
export class CalDavProvider {
|
||||
private readonly hostname: string
|
||||
private readonly protocol: 'https' | 'http'
|
||||
private readonly port: number
|
||||
private readonly username: string
|
||||
private readonly email: string
|
||||
private readonly password: string
|
||||
private readonly allowSelfSigned: boolean
|
||||
private readonly basicAuthHeader: string
|
||||
|
||||
private authMode: AuthMode = 'basic'
|
||||
private connected = false
|
||||
|
||||
constructor(config: AccountConfig) {
|
||||
const creds = config.credentials as ImapCredentials
|
||||
|
||||
const calSecure = creds.caldavSecure ?? creds.secure
|
||||
this.hostname = (creds.caldavHost || creds.host).replace(/\/+$/, '')
|
||||
this.protocol = calSecure ? 'https' : 'http'
|
||||
this.port = creds.caldavPort ?? (calSecure ? 443 : 80)
|
||||
this.username = creds.username
|
||||
this.email = config.email || creds.username
|
||||
this.password = creds.password
|
||||
this.allowSelfSigned = creds.caldavAllowSelfSigned ?? creds.smtpAllowSelfSigned ?? false
|
||||
this.basicAuthHeader = 'Basic ' + Buffer.from(`${this.username}:${this.password}`).toString('base64')
|
||||
}
|
||||
|
||||
// ── Connection ────────────────────────────────────────────────────────────
|
||||
|
||||
async connect(): Promise<void> {
|
||||
const result = await this.ewsReq('GetFolder', `
|
||||
<m:GetFolder>
|
||||
<m:FolderShape><t:BaseShape>Default</t:BaseShape></m:FolderShape>
|
||||
<m:FolderIds><t:DistinguishedFolderId Id="calendar"/></m:FolderIds>
|
||||
</m:GetFolder>`)
|
||||
|
||||
if (result.status !== 200) {
|
||||
const hint = result.status === 401 || result.status === 403
|
||||
? '\nПроверьте логин и пароль.'
|
||||
: result.status === 404
|
||||
? '\nEWS не найден на сервере. Убедитесь что Exchange доступен по этому адресу.'
|
||||
: ''
|
||||
throw new Error(`EWS ${this.hostname} вернул HTTP ${result.status}.${hint}`)
|
||||
}
|
||||
|
||||
if (!result.body.includes('ResponseClass="Success"')) {
|
||||
const err = result.body.match(/<[mt]:MessageText>([^<]+)<\/[mt]:MessageText>/)
|
||||
throw new Error(`EWS ошибка: ${err ? err[1] : result.body.slice(0, 300)}`)
|
||||
}
|
||||
|
||||
this.connected = true
|
||||
}
|
||||
|
||||
isConnected(): boolean { return this.connected }
|
||||
|
||||
// ── Diagnostics ───────────────────────────────────────────────────────────
|
||||
|
||||
async probePaths(): Promise<{ path: string; status: number; note: string }[]> {
|
||||
const results: { path: string; status: number; note: string }[] = []
|
||||
|
||||
// Test EWS endpoint
|
||||
try {
|
||||
const r = await this.ewsReq('GetFolder', `
|
||||
<m:GetFolder>
|
||||
<m:FolderShape><t:BaseShape>Default</t:BaseShape></m:FolderShape>
|
||||
<m:FolderIds><t:DistinguishedFolderId Id="calendar"/></m:FolderIds>
|
||||
</m:GetFolder>`)
|
||||
const ok = r.status === 200 && r.body.includes('ResponseClass="Success"')
|
||||
results.push({
|
||||
path: EWS_PATH,
|
||||
status: r.status,
|
||||
note: ok ? '✓ EWS работает' : `HTTP ${r.status}`
|
||||
})
|
||||
} catch (err) {
|
||||
results.push({ path: EWS_PATH, status: 0, note: (err as Error).message })
|
||||
}
|
||||
|
||||
// Test Autodiscover
|
||||
try {
|
||||
const ad = await this.tryAutodiscover()
|
||||
results.push({
|
||||
path: '/autodiscover/autodiscover.xml',
|
||||
status: ad ? 200 : 404,
|
||||
note: ad ? `✓ EWS URL: ${ad.ewsUrl}` : 'Autodiscover недоступен'
|
||||
})
|
||||
} catch (err) {
|
||||
results.push({ path: '/autodiscover/autodiscover.xml', status: 0, note: (err as Error).message })
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
// ── List calendars ────────────────────────────────────────────────────────
|
||||
|
||||
async listCalendars(accountId: string): Promise<CalendarInfo[]> {
|
||||
// Get the main calendar folder's display name
|
||||
const mainName = await this.ewsGetFolderName('calendar')
|
||||
|
||||
// Get sub-calendars (FindFolder returns children, NOT the parent itself)
|
||||
const subResult = await this.ewsReq('FindFolder', `
|
||||
<m:FindFolder Traversal="Shallow">
|
||||
<m:FolderShape><t:BaseShape>Default</t:BaseShape></m:FolderShape>
|
||||
<m:ParentFolderIds><t:DistinguishedFolderId Id="calendar"/></m:ParentFolderIds>
|
||||
</m:FindFolder>`)
|
||||
|
||||
const calendars: CalendarInfo[] = [
|
||||
{ id: 'calendar', name: mainName, accountId }
|
||||
]
|
||||
|
||||
if (subResult.status === 200) {
|
||||
const re = /<t:CalendarFolder>([\s\S]*?)<\/t:CalendarFolder>/g
|
||||
let m: RegExpExecArray | null
|
||||
while ((m = re.exec(subResult.body)) !== null) {
|
||||
const block = m[1]
|
||||
const idM = block.match(/<t:FolderId\s+Id="([^"]+)"/)
|
||||
const nameM = block.match(/<t:DisplayName>([^<]+)<\/t:DisplayName>/)
|
||||
if (idM) calendars.push({ id: idM[1], name: nameM ? nameM[1] : 'Calendar', accountId })
|
||||
}
|
||||
}
|
||||
|
||||
return calendars
|
||||
}
|
||||
|
||||
// ── List events ───────────────────────────────────────────────────────────
|
||||
|
||||
async listEvents(accountId: string, calendarId: string, start: Date, end: Date): Promise<CalendarEvent[]> {
|
||||
const startStr = start.toISOString().slice(0, 19) + 'Z'
|
||||
const endStr = end.toISOString().slice(0, 19) + 'Z'
|
||||
const folderEl = calendarId === 'calendar'
|
||||
? `<t:DistinguishedFolderId Id="calendar"/>`
|
||||
: `<t:FolderId Id="${calendarId}"/>`
|
||||
|
||||
const result = await this.ewsReq('FindItem', `
|
||||
<m:FindItem Traversal="Shallow">
|
||||
<m:ItemShape>
|
||||
<t:BaseShape>IdOnly</t:BaseShape>
|
||||
<t:AdditionalProperties>
|
||||
<t:FieldURI FieldURI="item:Subject"/>
|
||||
<t:FieldURI FieldURI="item:Body"/>
|
||||
<t:FieldURI FieldURI="calendar:Start"/>
|
||||
<t:FieldURI FieldURI="calendar:End"/>
|
||||
<t:FieldURI FieldURI="calendar:Location"/>
|
||||
<t:FieldURI FieldURI="calendar:IsAllDayEvent"/>
|
||||
<t:FieldURI FieldURI="calendar:LegacyFreeBusyStatus"/>
|
||||
<t:FieldURI FieldURI="calendar:Organizer"/>
|
||||
</t:AdditionalProperties>
|
||||
</m:ItemShape>
|
||||
<m:CalendarView MaxReturnsPerPage="500" StartDate="${startStr}" EndDate="${endStr}"/>
|
||||
<m:ParentFolderIds>${folderEl}</m:ParentFolderIds>
|
||||
</m:FindItem>`)
|
||||
|
||||
if (result.status !== 200) return []
|
||||
return this.parseEwsEvents(result.body, accountId, calendarId)
|
||||
}
|
||||
|
||||
// ── EWS helpers ───────────────────────────────────────────────────────────
|
||||
|
||||
private ewsReq(action: string, soapBody: string): Promise<RequestResult> {
|
||||
const full = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
|
||||
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
|
||||
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
|
||||
<soap:Header><t:RequestServerVersion Version="Exchange2013"/></soap:Header>
|
||||
<soap:Body>${soapBody}</soap:Body>
|
||||
</soap:Envelope>`
|
||||
return this.req('POST', EWS_PATH, {
|
||||
'Content-Type': 'text/xml; charset=utf-8',
|
||||
'SOAPAction': `"http://schemas.microsoft.com/exchange/services/2006/messages/${action}"`
|
||||
}, full)
|
||||
}
|
||||
|
||||
private async ewsGetFolderName(distinguishedId: string): Promise<string> {
|
||||
try {
|
||||
const result = await this.ewsReq('GetFolder', `
|
||||
<m:GetFolder>
|
||||
<m:FolderShape><t:BaseShape>Default</t:BaseShape></m:FolderShape>
|
||||
<m:FolderIds><t:DistinguishedFolderId Id="${distinguishedId}"/></m:FolderIds>
|
||||
</m:GetFolder>`)
|
||||
if (result.status === 200) {
|
||||
const m = result.body.match(/<t:DisplayName>([^<]+)<\/t:DisplayName>/)
|
||||
if (m) return m[1]
|
||||
}
|
||||
} catch { /* fall through */ }
|
||||
return distinguishedId === 'calendar' ? 'Календарь' : distinguishedId
|
||||
}
|
||||
|
||||
private parseEwsEvents(xml: string, accountId: string, calendarId: string): CalendarEvent[] {
|
||||
const events: CalendarEvent[] = []
|
||||
const re = /<t:CalendarItem>([\s\S]*?)<\/t:CalendarItem>/g
|
||||
let m: RegExpExecArray | null
|
||||
while ((m = re.exec(xml)) !== null) {
|
||||
const block = m[1]
|
||||
const get = (tag: string): string => {
|
||||
const r = block.match(new RegExp(`<t:${tag}(?:\\s[^>]*)?>([\\s\\S]*?)<\\/t:${tag}>`))
|
||||
return r ? r[1].replace(/<[^>]+>/g, '').trim() : ''
|
||||
}
|
||||
const idM = block.match(/<t:ItemId\s+Id="([^"]+)"/)
|
||||
if (!idM) continue
|
||||
const startStr = get('Start')
|
||||
if (!startStr) continue
|
||||
const start = new Date(startStr)
|
||||
const endStr = get('End')
|
||||
const end = endStr ? new Date(endStr) : new Date(start.getTime() + 3_600_000)
|
||||
const isAllDay = get('IsAllDayEvent') === 'true'
|
||||
const fbStatus = get('LegacyFreeBusyStatus').toLowerCase()
|
||||
const organizerM = block.match(/<t:Organizer>[\s\S]*?<t:EmailAddress>([^<]+)<\/t:EmailAddress>/)
|
||||
events.push({
|
||||
id: `ews::${idM[1]}`,
|
||||
uid: idM[1],
|
||||
calendarId,
|
||||
accountId,
|
||||
title: get('Subject') || '(без темы)',
|
||||
start: start.toISOString(),
|
||||
end: end.toISOString(),
|
||||
isAllDay,
|
||||
location: get('Location') || undefined,
|
||||
description: get('Body') || undefined,
|
||||
organizer: organizerM ? organizerM[1] : undefined,
|
||||
attendees: [],
|
||||
status: fbStatus === 'tentative' ? 'tentative' : 'confirmed'
|
||||
})
|
||||
}
|
||||
return events
|
||||
}
|
||||
|
||||
private async tryAutodiscover(): Promise<{ ewsUrl: string } | null> {
|
||||
const body = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
|
||||
<Request>
|
||||
<EMailAddress>${this.email}</EMailAddress>
|
||||
<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
|
||||
</Request>
|
||||
</Autodiscover>`
|
||||
const headers = { 'Content-Type': 'text/xml; charset=utf-8' }
|
||||
for (const path of ['/autodiscover/autodiscover.xml', '/Autodiscover/Autodiscover.xml']) {
|
||||
try {
|
||||
const result = await this.req('POST', path, headers, body)
|
||||
if (result.status === 200) {
|
||||
const m = result.body.match(/<EwsUrl>([^<]+)<\/EwsUrl>/i)
|
||||
if (m) return { ewsUrl: m[1].trim() }
|
||||
}
|
||||
} catch { /* try next */ }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// ── Authenticated HTTP request ─────────────────────────────────────────────
|
||||
|
||||
private async req(
|
||||
method: string,
|
||||
path: string,
|
||||
extraHeaders: Record<string, string> = {},
|
||||
body?: string
|
||||
): Promise<RequestResult> {
|
||||
if (this.authMode === 'ntlm') {
|
||||
return this.reqNtlm(method, path, extraHeaders, body)
|
||||
}
|
||||
|
||||
const result = await this.rawReq(method, path, { Authorization: this.basicAuthHeader, ...extraHeaders }, body)
|
||||
|
||||
if (result.status === 401 && this.needsNtlm(result.headers)) {
|
||||
this.authMode = 'ntlm'
|
||||
return this.reqNtlm(method, path, extraHeaders, body)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* NTLMv2 3-way handshake. Both Type 1 and Type 3 must use the same TCP
|
||||
* connection — achieved with a fresh keepAlive Agent (maxSockets: 1).
|
||||
*/
|
||||
private async reqNtlm(
|
||||
method: string,
|
||||
path: string,
|
||||
extraHeaders: Record<string, string> = {},
|
||||
body?: string
|
||||
): Promise<RequestResult> {
|
||||
const agentOpts = { keepAlive: true, maxSockets: 1, rejectUnauthorized: !this.allowSelfSigned }
|
||||
const agent = this.protocol === 'https'
|
||||
? new https.Agent(agentOpts)
|
||||
: new http.Agent({ keepAlive: true, maxSockets: 1 })
|
||||
|
||||
try {
|
||||
const type1Result = await this.rawReq(
|
||||
method, path,
|
||||
{ Authorization: buildNegotiateHeader(), ...extraHeaders },
|
||||
undefined,
|
||||
agent
|
||||
)
|
||||
|
||||
const wwwAuth = this.extractNtlmChallenge(type1Result.headers)
|
||||
if (!wwwAuth) return type1Result
|
||||
|
||||
const { challenge, targetInfo, targetName } = parseChallenge(wwwAuth)
|
||||
const { user, domain: explicitDomain } = splitUser(this.username)
|
||||
const domain = explicitDomain || targetName
|
||||
const type3Header = buildAuthenticateHeader(user, domain, this.password, challenge, targetInfo)
|
||||
|
||||
return await this.rawReq(
|
||||
method, path,
|
||||
{ Authorization: type3Header, ...extraHeaders },
|
||||
body,
|
||||
agent
|
||||
)
|
||||
} finally {
|
||||
agent.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
private rawReq(
|
||||
method: string,
|
||||
path: string,
|
||||
headers: Record<string, string>,
|
||||
body?: string,
|
||||
agent?: https.Agent | http.Agent
|
||||
): Promise<RequestResult> {
|
||||
const allHeaders: Record<string, string> = { 'User-Agent': 'AeroMail/1.0', ...headers }
|
||||
if (body) allHeaders['Content-Length'] = Buffer.byteLength(body, 'utf8').toString()
|
||||
|
||||
return rawRequest({
|
||||
protocol: this.protocol,
|
||||
hostname: this.hostname,
|
||||
port: this.port,
|
||||
path,
|
||||
method,
|
||||
headers: allHeaders,
|
||||
body,
|
||||
allowSelfSigned: this.allowSelfSigned,
|
||||
agent
|
||||
})
|
||||
}
|
||||
|
||||
private extractNtlmChallenge(headers: IncomingMessage['headers']): string | null {
|
||||
const auth = headers['www-authenticate']
|
||||
const list = Array.isArray(auth) ? auth : typeof auth === 'string' ? auth.split(',') : []
|
||||
return list.map((s) => s.trim()).find((s) => /^NTLM\s+/i.test(s)) ?? null
|
||||
}
|
||||
|
||||
private needsNtlm(headers: IncomingMessage['headers']): boolean {
|
||||
const auth = headers['www-authenticate']
|
||||
const s = Array.isArray(auth) ? auth.join(',') : auth ?? ''
|
||||
return /NTLM|Negotiate/i.test(s)
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,9 @@ import type { AccountConfig, ImapCredentials } from '@shared/types/account'
|
|||
import { AccountType } from '@shared/types/account'
|
||||
import type { IEmailProvider, FolderListResult, MessageListResult } from '@shared/types/provider'
|
||||
import type { MessageBody, MessageFlags, MessageEnvelope, ComposeData } from '@shared/types/message'
|
||||
import type { CalendarInfo, CalendarEvent } from '@shared/types/calendar'
|
||||
import { ImapProvider } from '../providers/imap.provider'
|
||||
import { CalDavProvider } from '../providers/caldav.provider'
|
||||
import { CredentialStore } from './credential-store'
|
||||
import Store from 'electron-store'
|
||||
|
||||
|
|
@ -16,6 +18,7 @@ const RECONNECT_CODES = new Set(['NoConnection', 'ECONNRESET', 'ECONNREFUSED', '
|
|||
|
||||
export class AccountManager {
|
||||
private providers = new Map<string, IEmailProvider>()
|
||||
private calendarProviders = new Map<string, CalDavProvider>()
|
||||
private store: Store<AccountStoreSchema>
|
||||
private credentialStore: CredentialStore
|
||||
private mainWindow: BrowserWindow | null = null
|
||||
|
|
@ -72,6 +75,7 @@ export class AccountManager {
|
|||
await provider.disconnect()
|
||||
this.providers.delete(accountId)
|
||||
}
|
||||
this.calendarProviders.delete(accountId)
|
||||
await this.credentialStore.remove(accountId)
|
||||
|
||||
const accounts = this.store.get('accounts', [])
|
||||
|
|
@ -205,6 +209,69 @@ export class AccountManager {
|
|||
)
|
||||
}
|
||||
|
||||
// ── Calendar ────────────────────────────────────────────
|
||||
|
||||
async listCalendars(accountId: string): Promise<CalendarInfo[]> {
|
||||
const provider = await this.getOrCreateCalendarProvider(accountId)
|
||||
return provider.listCalendars(accountId)
|
||||
}
|
||||
|
||||
async listCalendarEvents(
|
||||
accountId: string,
|
||||
calendarId: string,
|
||||
start: Date,
|
||||
end: Date
|
||||
): Promise<CalendarEvent[]> {
|
||||
const provider = await this.getOrCreateCalendarProvider(accountId)
|
||||
return provider.listEvents(accountId, calendarId, start, end)
|
||||
}
|
||||
|
||||
async probeCalendarPaths(accountId: string): Promise<{ path: string; status: number; note: string }[]> {
|
||||
// Create a fresh provider (no cached state) and probe without connecting
|
||||
const accounts = this.store.get('accounts', [])
|
||||
const accMeta = accounts.find((a) => a.id === accountId)
|
||||
if (!accMeta) throw new Error(`Account ${accountId} not found`)
|
||||
|
||||
const credRaw = this.credentialStore.get(accountId)
|
||||
if (!credRaw) throw new Error(`Credentials for ${accountId} not found`)
|
||||
|
||||
let credentials: AccountConfig['credentials']
|
||||
try {
|
||||
credentials = JSON.parse(credRaw)
|
||||
} catch {
|
||||
throw new Error('Corrupted credentials')
|
||||
}
|
||||
|
||||
const config: AccountConfig = { ...accMeta, credentials }
|
||||
const provider = new CalDavProvider(config)
|
||||
return provider.probePaths()
|
||||
}
|
||||
|
||||
private async getOrCreateCalendarProvider(accountId: string): Promise<CalDavProvider> {
|
||||
const existing = this.calendarProviders.get(accountId)
|
||||
if (existing?.isConnected()) return existing
|
||||
|
||||
const accounts = this.store.get('accounts', [])
|
||||
const accMeta = accounts.find((a) => a.id === accountId)
|
||||
if (!accMeta) throw new Error(`Account ${accountId} not found`)
|
||||
|
||||
const credRaw = this.credentialStore.get(accountId)
|
||||
if (!credRaw) throw new Error(`Credentials for ${accountId} not found`)
|
||||
|
||||
let credentials: AccountConfig['credentials']
|
||||
try {
|
||||
credentials = JSON.parse(credRaw)
|
||||
} catch {
|
||||
throw new Error('Corrupted credentials')
|
||||
}
|
||||
|
||||
const config: AccountConfig = { ...accMeta, credentials }
|
||||
const provider = new CalDavProvider(config)
|
||||
await provider.connect()
|
||||
this.calendarProviders.set(accountId, provider)
|
||||
return provider
|
||||
}
|
||||
|
||||
// ── Auto-reconnect ──────────────────────────────────────
|
||||
|
||||
private async withAutoReconnect<T>(accountId: string, fn: () => Promise<T>): Promise<T> {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export type IconName =
|
|||
| 'pdf'
|
||||
| 'image'
|
||||
| 'bell-off'
|
||||
| 'calendar'
|
||||
|
||||
const props = defineProps<{
|
||||
name: IconName
|
||||
|
|
@ -141,6 +142,12 @@ const paths: Record<IconName, string> = {
|
|||
<path d="M18 8a6 6 0 0 0-9.33-5"/>
|
||||
<line x1="1" y1="1" x2="23" y2="23"/>
|
||||
`,
|
||||
calendar: `
|
||||
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"/>
|
||||
<line x1="16" y1="2" x2="16" y2="6"/>
|
||||
<line x1="8" y1="2" x2="8" y2="6"/>
|
||||
<line x1="3" y1="10" x2="21" y2="10"/>
|
||||
`,
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,13 @@ const smtpSecure = ref(false)
|
|||
const smtpAllowSelfSigned = ref(false)
|
||||
const showSmtp = ref(false)
|
||||
|
||||
const caldavHost = ref('')
|
||||
const caldavPort = ref(443)
|
||||
const caldavSecure = ref(true)
|
||||
const caldavPath = ref('')
|
||||
const caldavAllowSelfSigned = ref(false)
|
||||
const showCaldav = ref(false)
|
||||
|
||||
function generateId(): string {
|
||||
return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
||||
}
|
||||
|
|
@ -57,6 +64,15 @@ async function handleSubmit(): Promise<void> {
|
|||
smtpSecure: smtpSecure.value,
|
||||
...(smtpAllowSelfSigned.value ? { smtpAllowSelfSigned: true } : {})
|
||||
}
|
||||
: {}),
|
||||
...(showCaldav.value && caldavHost.value
|
||||
? {
|
||||
caldavHost: caldavHost.value,
|
||||
caldavPort: caldavPort.value,
|
||||
caldavSecure: caldavSecure.value,
|
||||
...(caldavPath.value.trim() ? { caldavPath: caldavPath.value.trim() } : {}),
|
||||
...(caldavAllowSelfSigned.value ? { caldavAllowSelfSigned: true } : {})
|
||||
}
|
||||
: {})
|
||||
}
|
||||
const config: AccountConfig = {
|
||||
|
|
@ -173,6 +189,46 @@ const isFormValid = computed(() => imapHost.value && imapUsername.value && imapP
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CalDAV (опционально) -->
|
||||
<div class="smtp-section">
|
||||
<button type="button" class="smtp-toggle" @click="showCaldav = !showCaldav">
|
||||
<svg :style="{ transform: showCaldav ? 'rotate(90deg)' : 'none', transition: 'transform 0.18s' }"
|
||||
width="12" height="12" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="9 18 15 12 9 6"/>
|
||||
</svg>
|
||||
Настройки CalDAV (для календаря)
|
||||
</button>
|
||||
<div v-if="showCaldav" class="smtp-fields">
|
||||
<div class="form-row">
|
||||
<div class="form-group flex-1">
|
||||
<label>CalDAV сервер</label>
|
||||
<input v-model="caldavHost" type="text" placeholder="mailsrv.example.com" />
|
||||
</div>
|
||||
<div class="form-group" style="width: 80px">
|
||||
<label>Порт</label>
|
||||
<input v-model.number="caldavPort" type="number" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input v-model="caldavSecure" type="checkbox" />
|
||||
SSL/TLS (HTTPS)
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Путь CalDAV (необязательно)</label>
|
||||
<input v-model="caldavPath" type="text" placeholder="/EWS/Calendar/ (пусто = автоопределение)" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input v-model="caldavAllowSelfSigned" type="checkbox" />
|
||||
Разрешить самоподписанные сертификаты
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="submit-btn" :disabled="!isFormValid || testing">
|
||||
{{ testing ? 'Подключение...' : 'Добавить аккаунт' }}
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -32,6 +32,13 @@ const smtpPort = ref(creds.smtpPort ?? 587)
|
|||
const smtpSecure = ref(creds.smtpSecure ?? false)
|
||||
const showSmtp = ref(!!creds.smtpHost)
|
||||
|
||||
const caldavHost = ref(creds.caldavHost ?? '')
|
||||
const caldavPort = ref(creds.caldavPort ?? 443)
|
||||
const caldavSecure = ref(creds.caldavSecure ?? true)
|
||||
const caldavPath = ref(creds.caldavPath ?? '')
|
||||
const caldavAllowSelfSigned = ref(creds.caldavAllowSelfSigned ?? false)
|
||||
const showCaldav = ref(!!creds.caldavHost)
|
||||
|
||||
async function handleSubmit(): Promise<void> {
|
||||
testing.value = true
|
||||
error.value = ''
|
||||
|
|
@ -45,6 +52,15 @@ async function handleSubmit(): Promise<void> {
|
|||
password: imapPassword.value,
|
||||
...(showSmtp.value && smtpHost.value
|
||||
? { smtpHost: smtpHost.value, smtpPort: smtpPort.value, smtpSecure: smtpSecure.value }
|
||||
: {}),
|
||||
...(showCaldav.value && caldavHost.value
|
||||
? {
|
||||
caldavHost: caldavHost.value,
|
||||
caldavPort: caldavPort.value,
|
||||
caldavSecure: caldavSecure.value,
|
||||
...(caldavPath.value.trim() ? { caldavPath: caldavPath.value.trim() } : {}),
|
||||
...(caldavAllowSelfSigned.value ? { caldavAllowSelfSigned: true } : {})
|
||||
}
|
||||
: {})
|
||||
}
|
||||
const config: AccountConfig = {
|
||||
|
|
@ -155,6 +171,46 @@ const isFormValid = computed(() => imapHost.value && imapUsername.value)
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CalDAV (опционально) -->
|
||||
<div class="smtp-section">
|
||||
<button type="button" class="smtp-toggle" @click="showCaldav = !showCaldav">
|
||||
<svg :style="{ transform: showCaldav ? 'rotate(90deg)' : 'none', transition: 'transform 0.18s' }"
|
||||
width="12" height="12" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="9 18 15 12 9 6"/>
|
||||
</svg>
|
||||
Настройки CalDAV (для календаря)
|
||||
</button>
|
||||
<div v-if="showCaldav" class="smtp-fields">
|
||||
<div class="form-row">
|
||||
<div class="form-group flex-1">
|
||||
<label>CalDAV сервер</label>
|
||||
<input v-model="caldavHost" type="text" placeholder="mailsrv.example.com" />
|
||||
</div>
|
||||
<div class="form-group" style="width: 80px">
|
||||
<label>Порт</label>
|
||||
<input v-model.number="caldavPort" type="number" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input v-model="caldavSecure" type="checkbox" />
|
||||
SSL/TLS (HTTPS)
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Путь CalDAV (необязательно)</label>
|
||||
<input v-model="caldavPath" type="text" placeholder="/EWS/Calendar/ (пусто = автоопределение)" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input v-model="caldavAllowSelfSigned" type="checkbox" />
|
||||
Разрешить самоподписанные сертификаты
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="submit-btn" :disabled="!isFormValid || testing">
|
||||
{{ testing ? 'Сохранение...' : 'Сохранить изменения' }}
|
||||
</button>
|
||||
|
|
|
|||
92
src/renderer/src/components/calendar/EventBlock.vue
Normal file
92
src/renderer/src/components/calendar/EventBlock.vue
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { format } from 'date-fns'
|
||||
import type { CalendarEvent } from '@shared/types/calendar'
|
||||
|
||||
const props = defineProps<{
|
||||
event: CalendarEvent
|
||||
style?: Record<string, string>
|
||||
color?: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ click: [event: CalendarEvent] }>()
|
||||
|
||||
const timeLabel = computed(() => {
|
||||
if (props.event.isAllDay) return 'All day'
|
||||
const start = new Date(props.event.start)
|
||||
const end = new Date(props.event.end)
|
||||
return `${format(start, 'HH:mm')} – ${format(end, 'HH:mm')}`
|
||||
})
|
||||
|
||||
const statusClass = computed(() => {
|
||||
if (props.event.status === 'cancelled') return 'cancelled'
|
||||
if (props.event.status === 'tentative') return 'tentative'
|
||||
return ''
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="event-block"
|
||||
:class="statusClass"
|
||||
:style="{ ...(style ?? {}), '--event-color': color ?? 'var(--accent)' }"
|
||||
@click.stop="emit('click', event)"
|
||||
>
|
||||
<div class="event-title">{{ event.title }}</div>
|
||||
<div class="event-time">{{ timeLabel }}</div>
|
||||
<div v-if="event.location" class="event-location">{{ event.location }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.event-block {
|
||||
position: absolute;
|
||||
left: 2px;
|
||||
right: 2px;
|
||||
border-radius: 6px;
|
||||
padding: 3px 6px;
|
||||
font-size: 11px;
|
||||
line-height: 1.3;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
background: color-mix(in srgb, var(--event-color) 22%, transparent);
|
||||
border-left: 3px solid var(--event-color);
|
||||
color: var(--text-primary);
|
||||
transition: filter var(--transition-fast), transform var(--transition-fast);
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.event-block:hover {
|
||||
filter: brightness(1.15);
|
||||
transform: scale(1.01);
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
.event-block.cancelled {
|
||||
opacity: 0.45;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.event-block.tentative {
|
||||
border-left-style: dashed;
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.event-title {
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.event-time,
|
||||
.event-location {
|
||||
font-size: 10px;
|
||||
color: var(--text-secondary);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
||||
200
src/renderer/src/components/calendar/EventDetailPopup.vue
Normal file
200
src/renderer/src/components/calendar/EventDetailPopup.vue
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { format } from 'date-fns'
|
||||
import { ru } from 'date-fns/locale'
|
||||
import type { CalendarEvent } from '@shared/types/calendar'
|
||||
import AppIcon from '../AppIcon.vue'
|
||||
|
||||
const props = defineProps<{
|
||||
event: CalendarEvent
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ close: [] }>()
|
||||
|
||||
const dateLabel = computed(() => {
|
||||
const start = new Date(props.event.start)
|
||||
const end = new Date(props.event.end)
|
||||
|
||||
if (props.event.isAllDay) {
|
||||
const isSameDay = start.toDateString() === end.toDateString()
|
||||
if (isSameDay) return format(start, 'd MMMM yyyy', { locale: ru })
|
||||
const endAdjusted = new Date(end.getTime() - 1) // all-day end is exclusive
|
||||
return `${format(start, 'd MMMM', { locale: ru })} – ${format(endAdjusted, 'd MMMM yyyy', { locale: ru })}`
|
||||
}
|
||||
|
||||
const sameDay = start.toDateString() === end.toDateString()
|
||||
if (sameDay) {
|
||||
return `${format(start, 'd MMMM yyyy, HH:mm', { locale: ru })} – ${format(end, 'HH:mm')}`
|
||||
}
|
||||
return `${format(start, 'd MMMM HH:mm', { locale: ru })} – ${format(end, 'd MMMM HH:mm yyyy', { locale: ru })}`
|
||||
})
|
||||
|
||||
const statusLabel: Record<string, string> = {
|
||||
confirmed: 'Подтверждено',
|
||||
tentative: 'Предварительно',
|
||||
cancelled: 'Отменено'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="popup-backdrop" @click.self="emit('close')">
|
||||
<div class="popup">
|
||||
<div class="popup-header">
|
||||
<h3 class="popup-title">{{ event.title }}</h3>
|
||||
<button class="close-btn" @click="emit('close')">
|
||||
<AppIcon name="close" :size="14" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="popup-body">
|
||||
<div class="meta-row">
|
||||
<span class="meta-icon">📅</span>
|
||||
<span>{{ dateLabel }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="event.status && event.status !== 'confirmed'" class="meta-row status" :class="event.status">
|
||||
<span class="meta-icon">●</span>
|
||||
<span>{{ statusLabel[event.status] ?? event.status }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="event.location" class="meta-row">
|
||||
<span class="meta-icon">📍</span>
|
||||
<span>{{ event.location }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="event.organizer" class="meta-row">
|
||||
<span class="meta-icon">👤</span>
|
||||
<span>{{ event.organizer }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="event.attendees.length > 0" class="meta-row attendees">
|
||||
<span class="meta-icon">👥</span>
|
||||
<div class="attendee-list">
|
||||
<span v-for="a in event.attendees" :key="a" class="attendee-chip">{{ a }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="event.description" class="description">
|
||||
{{ event.description }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.popup-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.popup {
|
||||
width: 400px;
|
||||
max-width: 90vw;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
border-radius: var(--radius-xl);
|
||||
border: 1px solid var(--glass-border-strong);
|
||||
background:
|
||||
linear-gradient(160deg, rgba(255,255,255,0.09) 0%, rgba(255,255,255,0.03) 100%),
|
||||
rgba(14, 14, 22, 0.94);
|
||||
backdrop-filter: blur(48px) saturate(2);
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255,255,255,0.14),
|
||||
var(--shadow-xl);
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.popup-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.popup-title {
|
||||
flex: 1;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
flex-shrink: 0;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--text-muted);
|
||||
background: var(--glass-bg);
|
||||
border: 1px solid var(--glass-border);
|
||||
transition: background var(--transition-fast), color var(--transition-fast);
|
||||
}
|
||||
|
||||
.close-btn:hover {
|
||||
background: var(--glass-bg-hover);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.popup-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.meta-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.meta-icon {
|
||||
flex-shrink: 0;
|
||||
font-size: 14px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.meta-row.tentative { color: var(--warning); }
|
||||
.meta-row.cancelled { color: var(--danger); }
|
||||
|
||||
.attendees {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.attendee-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.attendee-chip {
|
||||
font-size: 11px;
|
||||
padding: 2px 8px;
|
||||
border-radius: var(--radius-full);
|
||||
background: var(--glass-bg-raised);
|
||||
border: 1px solid var(--glass-border);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
white-space: pre-wrap;
|
||||
line-height: 1.5;
|
||||
border-top: 1px solid var(--glass-border);
|
||||
padding-top: 10px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
520
src/renderer/src/components/calendar/WeekView.vue
Normal file
520
src/renderer/src/components/calendar/WeekView.vue
Normal file
|
|
@ -0,0 +1,520 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, watch } from 'vue'
|
||||
import { format, addDays, isSameDay, isToday } from 'date-fns'
|
||||
import { ru } from 'date-fns/locale'
|
||||
import EventBlock from './EventBlock.vue'
|
||||
import type { CalendarEvent } from '@shared/types/calendar'
|
||||
|
||||
const props = defineProps<{
|
||||
weekStart: Date
|
||||
events: CalendarEvent[]
|
||||
loading?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ eventClick: [event: CalendarEvent] }>()
|
||||
|
||||
const scrollEl = ref<HTMLElement | null>(null)
|
||||
const HOUR_HEIGHT = 56 // px per hour
|
||||
const HOURS = Array.from({ length: 24 }, (_, i) => i)
|
||||
|
||||
// ── Days of the week ────────────────────────────────────────────────────────
|
||||
|
||||
const days = computed(() =>
|
||||
Array.from({ length: 7 }, (_, i) => {
|
||||
const date = addDays(props.weekStart, i)
|
||||
return {
|
||||
date,
|
||||
dayName: format(date, 'EEE', { locale: ru }),
|
||||
dayNum: format(date, 'd'),
|
||||
monthLabel: format(date, 'MMM', { locale: ru }),
|
||||
isToday: isToday(date)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
// ── Current time indicator ──────────────────────────────────────────────────
|
||||
|
||||
const now = ref(new Date())
|
||||
let timerId: ReturnType<typeof setInterval>
|
||||
|
||||
onMounted(() => {
|
||||
timerId = setInterval(() => { now.value = new Date() }, 60_000)
|
||||
// Scroll to business hours (8:00)
|
||||
scrollEl.value?.scrollTo({ top: 8 * HOUR_HEIGHT - 20, behavior: 'smooth' })
|
||||
})
|
||||
|
||||
// Re-scroll when week changes
|
||||
watch(() => props.weekStart, () => {
|
||||
scrollEl.value?.scrollTo({ top: 8 * HOUR_HEIGHT - 20, behavior: 'smooth' })
|
||||
})
|
||||
|
||||
import { onUnmounted } from 'vue'
|
||||
onUnmounted(() => clearInterval(timerId))
|
||||
|
||||
const nowTop = computed(() => {
|
||||
const h = now.value.getHours()
|
||||
const m = now.value.getMinutes()
|
||||
return (h + m / 60) * HOUR_HEIGHT
|
||||
})
|
||||
|
||||
const todayColumnIndex = computed(() =>
|
||||
days.value.findIndex((d) => d.isToday)
|
||||
)
|
||||
|
||||
// ── Event layout ────────────────────────────────────────────────────────────
|
||||
|
||||
interface LayoutEvent {
|
||||
event: CalendarEvent
|
||||
dayIndex: number
|
||||
top: number
|
||||
height: number
|
||||
column: number
|
||||
totalColumns: number
|
||||
}
|
||||
|
||||
const allDayEvents = computed(() => {
|
||||
return props.events.filter((e) => e.isAllDay)
|
||||
})
|
||||
|
||||
const timedEvents = computed(() => {
|
||||
return props.events.filter((e) => !e.isAllDay)
|
||||
})
|
||||
|
||||
/**
|
||||
* Lay out timed events per day, detecting overlaps.
|
||||
* Events in the same day that overlap in time are split into columns.
|
||||
*/
|
||||
const layoutEvents = computed((): LayoutEvent[] => {
|
||||
const result: LayoutEvent[] = []
|
||||
|
||||
for (let dayIndex = 0; dayIndex < 7; dayIndex++) {
|
||||
const dayDate = days.value[dayIndex].date
|
||||
|
||||
const dayEvs = timedEvents.value.filter((e) => {
|
||||
const eStart = new Date(e.start)
|
||||
const eEnd = new Date(e.end)
|
||||
return isSameDay(eStart, dayDate) ||
|
||||
(eStart < dayDate && eEnd > dayDate)
|
||||
})
|
||||
|
||||
// Simple overlap detection: group overlapping events
|
||||
const columns: CalendarEvent[][] = []
|
||||
for (const ev of dayEvs) {
|
||||
const eStart = new Date(ev.start).getTime()
|
||||
const eEnd = new Date(ev.end).getTime()
|
||||
|
||||
let placed = false
|
||||
for (const col of columns) {
|
||||
const lastInCol = col[col.length - 1]
|
||||
const lastEnd = new Date(lastInCol.end).getTime()
|
||||
if (eStart >= lastEnd) {
|
||||
col.push(ev)
|
||||
placed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!placed) columns.push([ev])
|
||||
}
|
||||
|
||||
// Build LayoutEvent for each event
|
||||
for (let colIdx = 0; colIdx < columns.length; colIdx++) {
|
||||
for (const ev of columns[colIdx]) {
|
||||
const eStart = new Date(ev.start)
|
||||
const eEnd = new Date(ev.end)
|
||||
|
||||
// Clamp to day boundaries
|
||||
const dayStart = new Date(dayDate)
|
||||
dayStart.setHours(0, 0, 0, 0)
|
||||
const dayEnd = new Date(dayDate)
|
||||
dayEnd.setHours(24, 0, 0, 0)
|
||||
|
||||
const clampedStart = eStart < dayStart ? dayStart : eStart
|
||||
const clampedEnd = eEnd > dayEnd ? dayEnd : eEnd
|
||||
|
||||
const startHours = clampedStart.getHours() + clampedStart.getMinutes() / 60
|
||||
const durationHours = (clampedEnd.getTime() - clampedStart.getTime()) / 3_600_000
|
||||
|
||||
// Find how many columns this event belongs to (for width calculation)
|
||||
const totalCols = columns.filter((col) => {
|
||||
const eS = new Date(ev.start).getTime()
|
||||
const eE = new Date(ev.end).getTime()
|
||||
return col.some((other) => {
|
||||
if (other === ev) return false
|
||||
const oS = new Date(other.start).getTime()
|
||||
const oE = new Date(other.end).getTime()
|
||||
return eS < oE && eE > oS
|
||||
})
|
||||
}).length + 1
|
||||
|
||||
result.push({
|
||||
event: ev,
|
||||
dayIndex,
|
||||
top: startHours * HOUR_HEIGHT,
|
||||
height: Math.max(durationHours * HOUR_HEIGHT, 18),
|
||||
column: colIdx,
|
||||
totalColumns: totalCols
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
/** Events per day index for rendering into the correct column. */
|
||||
function eventsForDay(dayIndex: number): LayoutEvent[] {
|
||||
return layoutEvents.value.filter((e) => e.dayIndex === dayIndex)
|
||||
}
|
||||
|
||||
function allDayEventsForDay(dayIndex: number): CalendarEvent[] {
|
||||
const d = days.value[dayIndex].date
|
||||
return allDayEvents.value.filter((e) => {
|
||||
const s = new Date(e.start)
|
||||
const end = new Date(e.end)
|
||||
return isSameDay(s, d) || (s < d && end > d)
|
||||
})
|
||||
}
|
||||
|
||||
function formatHour(h: number): string {
|
||||
return h === 0 ? '00:00' : `${String(h).padStart(2, '0')}:00`
|
||||
}
|
||||
|
||||
function eventStyle(layout: LayoutEvent): Record<string, string> {
|
||||
const colWidth = 100 / layout.totalColumns
|
||||
return {
|
||||
top: `${layout.top}px`,
|
||||
height: `${layout.height}px`,
|
||||
left: `${layout.column * colWidth + 0.5}%`,
|
||||
right: `${(layout.totalColumns - layout.column - 1) * colWidth + 0.5}%`,
|
||||
position: 'absolute'
|
||||
}
|
||||
}
|
||||
|
||||
// Accent color palette for calendars (cycle through)
|
||||
const CAL_COLORS = ['#a8e600', '#38bdf8', '#a78bfa', '#f472b6', '#fb923c', '#4ade80', '#f87171']
|
||||
function calendarColor(calendarId: string): string {
|
||||
let hash = 0
|
||||
for (let i = 0; i < calendarId.length; i++) hash = (hash * 31 + calendarId.charCodeAt(i)) & 0xffffff
|
||||
return CAL_COLORS[Math.abs(hash) % CAL_COLORS.length]
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="week-view">
|
||||
<!-- Day header row -->
|
||||
<div class="day-headers">
|
||||
<div class="time-gutter" />
|
||||
<div
|
||||
v-for="(day, i) in days"
|
||||
:key="i"
|
||||
class="day-header"
|
||||
:class="{ today: day.isToday }"
|
||||
>
|
||||
<span class="day-name">{{ day.dayName }}</span>
|
||||
<span class="day-num">{{ day.dayNum }}</span>
|
||||
<span class="month-label">{{ day.monthLabel }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- All-day event row (shown only when there are all-day events) -->
|
||||
<div
|
||||
v-if="events.some((e) => e.isAllDay)"
|
||||
class="allday-row"
|
||||
>
|
||||
<div class="time-gutter allday-gutter">
|
||||
<span class="allday-label">весь день</span>
|
||||
</div>
|
||||
<div v-for="(day, i) in days" :key="i" class="allday-col">
|
||||
<div
|
||||
v-for="ev in allDayEventsForDay(i)"
|
||||
:key="ev.id"
|
||||
class="allday-event"
|
||||
:style="{ '--event-color': calendarColor(ev.calendarId) }"
|
||||
@click="emit('eventClick', ev)"
|
||||
>
|
||||
{{ ev.title }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Scrollable time grid -->
|
||||
<div class="grid-scroll" ref="scrollEl">
|
||||
<div class="time-grid" :style="{ height: `${24 * HOUR_HEIGHT}px` }">
|
||||
<!-- Hour labels -->
|
||||
<div class="time-gutter-col">
|
||||
<div
|
||||
v-for="h in HOURS"
|
||||
:key="h"
|
||||
class="hour-label"
|
||||
:style="{ top: `${h * HOUR_HEIGHT}px` }"
|
||||
>
|
||||
{{ formatHour(h) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Day columns -->
|
||||
<div
|
||||
v-for="(day, i) in days"
|
||||
:key="i"
|
||||
class="day-col"
|
||||
:class="{ today: day.isToday }"
|
||||
>
|
||||
<!-- Hour grid lines -->
|
||||
<div
|
||||
v-for="h in HOURS"
|
||||
:key="h"
|
||||
class="hour-row"
|
||||
:style="{ top: `${h * HOUR_HEIGHT}px`, height: `${HOUR_HEIGHT}px` }"
|
||||
/>
|
||||
|
||||
<!-- Current time indicator -->
|
||||
<div
|
||||
v-if="day.isToday"
|
||||
class="now-line"
|
||||
:style="{ top: `${nowTop}px` }"
|
||||
>
|
||||
<div class="now-dot" />
|
||||
</div>
|
||||
|
||||
<!-- Timed events -->
|
||||
<EventBlock
|
||||
v-for="layout in eventsForDay(i)"
|
||||
:key="layout.event.id"
|
||||
:event="layout.event"
|
||||
:style="eventStyle(layout)"
|
||||
:color="calendarColor(layout.event.calendarId)"
|
||||
@click="emit('eventClick', layout.event)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Loading overlay -->
|
||||
<div v-if="loading" class="loading-overlay">
|
||||
<span class="spinner" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.week-view {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ── Day headers ── */
|
||||
.day-headers {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid var(--glass-border);
|
||||
background: rgba(10, 10, 18, 0.5);
|
||||
}
|
||||
|
||||
.time-gutter {
|
||||
width: 52px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.day-header {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 8px 4px;
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
border-left: 1px solid var(--glass-border);
|
||||
gap: 2px;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.day-header.today .day-num {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
color: var(--accent-text);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.day-name {
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.day-num {
|
||||
font-size: 18px;
|
||||
font-weight: 300;
|
||||
color: var(--text-primary);
|
||||
line-height: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
}
|
||||
|
||||
.month-label {
|
||||
font-size: 10px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
/* ── All-day row ── */
|
||||
.allday-row {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid var(--glass-border);
|
||||
min-height: 28px;
|
||||
}
|
||||
|
||||
.allday-gutter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
.allday-label {
|
||||
font-size: 9px;
|
||||
color: var(--text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
|
||||
.allday-col {
|
||||
flex: 1;
|
||||
border-left: 1px solid var(--glass-border);
|
||||
padding: 2px 3px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.allday-event {
|
||||
font-size: 11px;
|
||||
padding: 1px 6px;
|
||||
border-radius: 4px;
|
||||
background: color-mix(in srgb, var(--event-color) 22%, transparent);
|
||||
border-left: 3px solid var(--event-color);
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.allday-event:hover {
|
||||
filter: brightness(1.15);
|
||||
}
|
||||
|
||||
/* ── Scrollable grid ── */
|
||||
.grid-scroll {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.time-grid {
|
||||
display: flex;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* ── Time gutter column ── */
|
||||
.time-gutter-col {
|
||||
width: 52px;
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.hour-label {
|
||||
position: absolute;
|
||||
right: 8px;
|
||||
font-size: 10px;
|
||||
color: var(--text-muted);
|
||||
transform: translateY(-50%);
|
||||
user-select: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* ── Day column ── */
|
||||
.day-col {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
border-left: 1px solid var(--glass-border);
|
||||
}
|
||||
|
||||
.day-col.today {
|
||||
background: rgba(168, 230, 0, 0.022);
|
||||
}
|
||||
|
||||
/* ── Hour rows (grid lines) ── */
|
||||
.hour-row {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.05);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.hour-row:nth-child(2n) {
|
||||
border-top-color: transparent;
|
||||
border-top: 1px dashed rgba(255, 255, 255, 0.03);
|
||||
}
|
||||
|
||||
/* ── Current time line ── */
|
||||
.now-line {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 2px;
|
||||
background: var(--accent);
|
||||
opacity: 0.75;
|
||||
pointer-events: none;
|
||||
z-index: 4;
|
||||
}
|
||||
|
||||
.now-dot {
|
||||
position: absolute;
|
||||
left: -4px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
box-shadow: 0 0 6px var(--accent);
|
||||
}
|
||||
|
||||
/* ── Loading overlay ── */
|
||||
.loading-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(9, 9, 14, 0.45);
|
||||
backdrop-filter: blur(4px);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: 2px solid var(--glass-border);
|
||||
border-top-color: var(--accent);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
</style>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import { useAccountsStore } from '../../stores/accounts.store'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import AppIcon from '../AppIcon.vue'
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
|
@ -9,6 +9,7 @@ const emit = defineEmits<{
|
|||
|
||||
const accountsStore = useAccountsStore()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
function getInitial(email: string): string {
|
||||
return email.charAt(0).toUpperCase()
|
||||
|
|
@ -44,6 +45,24 @@ function getAccountColor(index: number): string {
|
|||
|
||||
<div class="spacer" />
|
||||
|
||||
<button
|
||||
class="account-btn nav-btn"
|
||||
:class="{ 'nav-active': route.path === '/' || route.path === '' }"
|
||||
v-tooltip="'Почта'"
|
||||
@click="router.push('/')"
|
||||
>
|
||||
<AppIcon name="envelope" :size="15" class="nav-icon" />
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="account-btn nav-btn"
|
||||
:class="{ 'nav-active': route.path === '/calendar' }"
|
||||
v-tooltip="'Календарь'"
|
||||
@click="router.push('/calendar')"
|
||||
>
|
||||
<AppIcon name="calendar" :size="15" class="nav-icon" />
|
||||
</button>
|
||||
|
||||
<button class="account-btn settings-btn" v-tooltip="'Настройки'" @click="router.push('/settings')">
|
||||
<AppIcon name="settings" :size="15" class="settings-icon" />
|
||||
</button>
|
||||
|
|
@ -138,13 +157,24 @@ function getAccountColor(index: number): string {
|
|||
}
|
||||
|
||||
.add-icon,
|
||||
.settings-icon {
|
||||
.settings-icon,
|
||||
.nav-icon {
|
||||
color: var(--text-muted);
|
||||
transition: color var(--transition-fast);
|
||||
}
|
||||
|
||||
.add-btn:hover .add-icon,
|
||||
.settings-btn:hover .settings-icon {
|
||||
.settings-btn:hover .settings-icon,
|
||||
.nav-btn:hover .nav-icon {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.nav-btn.nav-active {
|
||||
background: var(--accent-muted);
|
||||
border-color: color-mix(in srgb, var(--accent) 35%, transparent);
|
||||
}
|
||||
|
||||
.nav-btn.nav-active .nav-icon {
|
||||
color: var(--accent);
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ const router = createRouter({
|
|||
name: 'settings',
|
||||
component: () => import('./views/SettingsView.vue')
|
||||
},
|
||||
{
|
||||
path: '/calendar',
|
||||
name: 'calendar',
|
||||
component: () => import('./views/CalendarView.vue')
|
||||
},
|
||||
{
|
||||
path: '/compose',
|
||||
name: 'compose',
|
||||
|
|
|
|||
135
src/renderer/src/stores/calendar.store.ts
Normal file
135
src/renderer/src/stores/calendar.store.ts
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
import { ref, computed } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { startOfWeek, endOfWeek, addWeeks, subWeeks } from 'date-fns'
|
||||
import { useIpc } from '../composables/useIpc'
|
||||
import { useAccountsStore } from './accounts.store'
|
||||
import type { CalendarInfo, CalendarEvent } from '@shared/types/calendar'
|
||||
|
||||
export const useCalendarStore = defineStore('calendar', () => {
|
||||
const { invoke } = useIpc()
|
||||
const accountsStore = useAccountsStore()
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const calendars = ref<CalendarInfo[]>([])
|
||||
const events = ref<CalendarEvent[]>([])
|
||||
const selectedCalendarIds = ref<Set<string>>(new Set())
|
||||
const selectedEvent = ref<CalendarEvent | null>(null)
|
||||
const currentWeekStart = ref<Date>(startOfWeek(new Date(), { weekStartsOn: 1 }))
|
||||
const loading = ref(false)
|
||||
const loadingCalendars = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
// ── Computed ───────────────────────────────────────────────────────────────
|
||||
|
||||
const currentWeekEnd = computed(() => endOfWeek(currentWeekStart.value, { weekStartsOn: 1 }))
|
||||
|
||||
const visibleEvents = computed(() => {
|
||||
if (selectedCalendarIds.value.size === 0) return events.value
|
||||
return events.value.filter((e) => selectedCalendarIds.value.has(e.calendarId))
|
||||
})
|
||||
|
||||
// ── Calendars ──────────────────────────────────────────────────────────────
|
||||
|
||||
async function loadCalendars(): Promise<void> {
|
||||
const accountId = accountsStore.activeAccountId
|
||||
if (!accountId) return
|
||||
|
||||
loadingCalendars.value = true
|
||||
error.value = null
|
||||
try {
|
||||
calendars.value = await invoke('calendar:list', { accountId })
|
||||
// Select all calendars by default
|
||||
selectedCalendarIds.value = new Set(calendars.value.map((c) => c.id))
|
||||
} catch (err) {
|
||||
error.value = (err as Error).message
|
||||
calendars.value = []
|
||||
} finally {
|
||||
loadingCalendars.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function toggleCalendar(calendarId: string): void {
|
||||
const s = new Set(selectedCalendarIds.value)
|
||||
if (s.has(calendarId)) s.delete(calendarId)
|
||||
else s.add(calendarId)
|
||||
selectedCalendarIds.value = s
|
||||
}
|
||||
|
||||
// ── Events ─────────────────────────────────────────────────────────────────
|
||||
|
||||
async function loadEvents(): Promise<void> {
|
||||
const accountId = accountsStore.activeAccountId
|
||||
if (!accountId || calendars.value.length === 0) return
|
||||
|
||||
loading.value = true
|
||||
error.value = null
|
||||
|
||||
try {
|
||||
const start = currentWeekStart.value.toISOString()
|
||||
// Expand end by 1 day to include events that start on Sunday
|
||||
const end = new Date(currentWeekEnd.value.getTime() + 24 * 60 * 60 * 1000).toISOString()
|
||||
|
||||
const allEvents: CalendarEvent[] = []
|
||||
for (const cal of calendars.value) {
|
||||
try {
|
||||
const calEvents = await invoke('calendar:events', {
|
||||
accountId,
|
||||
calendarId: cal.id,
|
||||
start,
|
||||
end
|
||||
})
|
||||
allEvents.push(...calEvents)
|
||||
} catch {
|
||||
// Skip calendars that fail individually
|
||||
}
|
||||
}
|
||||
events.value = allEvents
|
||||
} catch (err) {
|
||||
error.value = (err as Error).message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Navigation ─────────────────────────────────────────────────────────────
|
||||
|
||||
async function goToToday(): Promise<void> {
|
||||
currentWeekStart.value = startOfWeek(new Date(), { weekStartsOn: 1 })
|
||||
await loadEvents()
|
||||
}
|
||||
|
||||
async function prevWeek(): Promise<void> {
|
||||
currentWeekStart.value = subWeeks(currentWeekStart.value, 1)
|
||||
await loadEvents()
|
||||
}
|
||||
|
||||
async function nextWeek(): Promise<void> {
|
||||
currentWeekStart.value = addWeeks(currentWeekStart.value, 1)
|
||||
await loadEvents()
|
||||
}
|
||||
|
||||
function selectEvent(event: CalendarEvent | null): void {
|
||||
selectedEvent.value = event
|
||||
}
|
||||
|
||||
return {
|
||||
calendars,
|
||||
events,
|
||||
selectedCalendarIds,
|
||||
selectedEvent,
|
||||
currentWeekStart,
|
||||
currentWeekEnd,
|
||||
loading,
|
||||
loadingCalendars,
|
||||
error,
|
||||
visibleEvents,
|
||||
loadCalendars,
|
||||
loadEvents,
|
||||
toggleCalendar,
|
||||
goToToday,
|
||||
prevWeek,
|
||||
nextWeek,
|
||||
selectEvent
|
||||
}
|
||||
})
|
||||
587
src/renderer/src/views/CalendarView.vue
Normal file
587
src/renderer/src/views/CalendarView.vue
Normal file
|
|
@ -0,0 +1,587 @@
|
|||
<script setup lang="ts">
|
||||
import { onMounted, watch, ref } from 'vue'
|
||||
import { format } from 'date-fns'
|
||||
import { ru } from 'date-fns/locale'
|
||||
import { useCalendarStore } from '../stores/calendar.store'
|
||||
import { useAccountsStore } from '../stores/accounts.store'
|
||||
import AccountSwitcher from '../components/sidebar/AccountSwitcher.vue'
|
||||
import WeekView from '../components/calendar/WeekView.vue'
|
||||
import EventDetailPopup from '../components/calendar/EventDetailPopup.vue'
|
||||
import AddAccountDialog from '../components/accounts/AddAccountDialog.vue'
|
||||
import NotificationContainer from '../components/notifications/NotificationContainer.vue'
|
||||
import AppIcon from '../components/AppIcon.vue'
|
||||
import type { CalendarEvent } from '@shared/types/calendar'
|
||||
|
||||
const calStore = useCalendarStore()
|
||||
const accountsStore = useAccountsStore()
|
||||
const showAddAccount = ref(false)
|
||||
|
||||
// CalDAV path probe
|
||||
const probeResults = ref<{ path: string; status: number; note: string }[] | null>(null)
|
||||
const probing = ref(false)
|
||||
|
||||
async function probeCalDAV(): Promise<void> {
|
||||
if (!accountsStore.activeAccountId) return
|
||||
probing.value = true
|
||||
probeResults.value = null
|
||||
try {
|
||||
probeResults.value = await window.api.invoke('calendar:probe', { accountId: accountsStore.activeAccountId })
|
||||
} catch (e) {
|
||||
probeResults.value = [{ path: '(error)', status: 0, note: (e as Error).message }]
|
||||
} finally {
|
||||
probing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Calendar color palette, same as WeekView
|
||||
const CAL_COLORS = ['#a8e600', '#38bdf8', '#a78bfa', '#f472b6', '#fb923c', '#4ade80', '#f87171']
|
||||
function calendarColor(calendarId: string): string {
|
||||
let hash = 0
|
||||
for (let i = 0; i < calendarId.length; i++) hash = (hash * 31 + calendarId.charCodeAt(i)) & 0xffffff
|
||||
return CAL_COLORS[Math.abs(hash) % CAL_COLORS.length]
|
||||
}
|
||||
|
||||
const weekLabel = () => {
|
||||
const s = calStore.currentWeekStart
|
||||
const e = calStore.currentWeekEnd
|
||||
const sStr = format(s, 'd MMM', { locale: ru })
|
||||
const eStr = format(e, 'd MMM yyyy', { locale: ru })
|
||||
return `${sStr} – ${eStr}`
|
||||
}
|
||||
|
||||
async function reload(): Promise<void> {
|
||||
await calStore.loadCalendars()
|
||||
await calStore.loadEvents()
|
||||
}
|
||||
|
||||
onMounted(reload)
|
||||
watch(() => accountsStore.activeAccountId, reload)
|
||||
|
||||
function handleEventClick(ev: CalendarEvent): void {
|
||||
calStore.selectEvent(ev)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="calendar-shell">
|
||||
<div class="content-area">
|
||||
<!-- Account switcher (same as mail view) -->
|
||||
<div class="account-bar">
|
||||
<AccountSwitcher @add-account="showAddAccount = true" />
|
||||
</div>
|
||||
|
||||
<!-- Calendar sidebar -->
|
||||
<div class="cal-sidebar">
|
||||
<div class="sidebar-header">
|
||||
<AppIcon name="calendar" :size="15" class="cal-icon" />
|
||||
<span>Календарь</span>
|
||||
</div>
|
||||
|
||||
<!-- Error state -->
|
||||
<div v-if="calStore.error" class="sidebar-error">
|
||||
<p class="error-title">CalDAV недоступен</p>
|
||||
<p class="error-detail">{{ calStore.error }}</p>
|
||||
|
||||
<button class="retry-btn" @click="reload">Повторить</button>
|
||||
<button class="retry-btn probe-btn" :disabled="probing" @click="probeCalDAV">
|
||||
{{ probing ? 'Сканирование…' : 'Найти CalDAV путь' }}
|
||||
</button>
|
||||
|
||||
<!-- Probe results -->
|
||||
<div v-if="probeResults" class="probe-results">
|
||||
<p class="probe-title">Результаты сканирования:</p>
|
||||
<div
|
||||
v-for="r in probeResults"
|
||||
:key="r.path"
|
||||
class="probe-row"
|
||||
:class="{ 'probe-ok': r.status === 207 || r.status === 200 }"
|
||||
>
|
||||
<span class="probe-path">{{ r.path }}</span>
|
||||
<span class="probe-note">{{ r.note }}</span>
|
||||
</div>
|
||||
<p class="probe-hint">Скопируйте путь со статусом 207 в настройки CalDAV → «Путь».</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Calendar list -->
|
||||
<div v-else-if="!calStore.loadingCalendars" class="calendar-list">
|
||||
<div
|
||||
v-for="cal in calStore.calendars"
|
||||
:key="cal.id"
|
||||
class="cal-item"
|
||||
:class="{ active: calStore.selectedCalendarIds.has(cal.id) }"
|
||||
@click="calStore.toggleCalendar(cal.id)"
|
||||
>
|
||||
<span
|
||||
class="cal-dot"
|
||||
:style="{ background: calendarColor(cal.id) }"
|
||||
/>
|
||||
<span class="cal-name" :title="cal.name">{{ cal.name }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="calStore.calendars.length === 0 && !calStore.loadingCalendars && !calStore.error" class="no-calendars">
|
||||
Нет доступных календарей
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="sidebar-loading">
|
||||
<span class="spinner" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main calendar area -->
|
||||
<div class="calendar-main">
|
||||
<!-- Toolbar -->
|
||||
<div class="toolbar">
|
||||
<button class="nav-btn" @click="calStore.prevWeek()">
|
||||
<AppIcon name="chevron-right" :size="14" style="transform: rotate(180deg)" />
|
||||
</button>
|
||||
<button class="nav-btn today-btn" @click="calStore.goToToday()">Сегодня</button>
|
||||
<button class="nav-btn" @click="calStore.nextWeek()">
|
||||
<AppIcon name="chevron-right" :size="14" />
|
||||
</button>
|
||||
|
||||
<span class="week-label">{{ weekLabel() }}</span>
|
||||
|
||||
<button class="nav-btn refresh-btn" :disabled="calStore.loading" @click="calStore.loadEvents()">
|
||||
<AppIcon name="refresh" :size="14" :class="{ spinning: calStore.loading }" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Week view -->
|
||||
<div class="week-wrap">
|
||||
<WeekView
|
||||
:week-start="calStore.currentWeekStart"
|
||||
:events="calStore.visibleEvents"
|
||||
:loading="calStore.loading"
|
||||
@event-click="handleEventClick"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Event detail popup -->
|
||||
<EventDetailPopup
|
||||
v-if="calStore.selectedEvent"
|
||||
:event="calStore.selectedEvent"
|
||||
@close="calStore.selectEvent(null)"
|
||||
/>
|
||||
|
||||
<AddAccountDialog
|
||||
v-if="showAddAccount"
|
||||
@close="showAddAccount = false"
|
||||
/>
|
||||
|
||||
<NotificationContainer />
|
||||
|
||||
<!-- Empty state: no accounts -->
|
||||
<div
|
||||
v-if="accountsStore.accounts.length === 0 && !accountsStore.loading && !showAddAccount"
|
||||
class="empty-state"
|
||||
>
|
||||
<div class="empty-content">
|
||||
<div class="empty-icon">
|
||||
<AppIcon name="calendar" :size="64" />
|
||||
</div>
|
||||
<h2>Добро пожаловать в Aero Mail</h2>
|
||||
<p>Добавьте почтовый аккаунт для просмотра календаря</p>
|
||||
<button class="add-btn" @click="showAddAccount = true">Добавить аккаунт</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.calendar-shell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
background: #07070c;
|
||||
}
|
||||
|
||||
.content-area {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
min-height: 0;
|
||||
padding: 8px;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* Account bar — same styling as in AppShell */
|
||||
.account-bar {
|
||||
width: var(--sidebar-width);
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
z-index: 4;
|
||||
border-radius: 14px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.09);
|
||||
background:
|
||||
linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.02) 100%),
|
||||
rgba(8, 8, 13, 0.88);
|
||||
backdrop-filter: blur(40px) saturate(2.0);
|
||||
-webkit-backdrop-filter: blur(40px) saturate(2.0);
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.12),
|
||||
0 8px 32px rgba(0, 0, 0, 0.50);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Calendar sidebar */
|
||||
.cal-sidebar {
|
||||
width: 200px;
|
||||
flex-shrink: 0;
|
||||
border-radius: 14px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
background:
|
||||
linear-gradient(180deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.015) 100%),
|
||||
rgba(9, 9, 15, 0.80);
|
||||
backdrop-filter: blur(28px) saturate(1.8);
|
||||
-webkit-backdrop-filter: blur(28px) saturate(1.8);
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.10),
|
||||
0 8px 28px rgba(0, 0, 0, 0.40);
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
padding: 14px 14px 10px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
letter-spacing: 0.3px;
|
||||
text-transform: uppercase;
|
||||
border-bottom: 1px solid var(--glass-border);
|
||||
}
|
||||
|
||||
.cal-icon {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
/* Calendar list */
|
||||
.calendar-list {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.cal-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 14px;
|
||||
cursor: pointer;
|
||||
border-radius: 8px;
|
||||
margin: 0 4px;
|
||||
transition: background var(--transition-fast);
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.cal-item.active {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.cal-item:hover {
|
||||
background: var(--glass-bg-hover);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.cal-dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 0 4px currentColor;
|
||||
}
|
||||
|
||||
.cal-name {
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.cal-item.active .cal-name {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.no-calendars {
|
||||
padding: 16px;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Error state */
|
||||
.sidebar-error {
|
||||
padding: 12px 14px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.error-title {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.error-detail {
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
word-break: break-all;
|
||||
user-select: text;
|
||||
-webkit-user-select: text;
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
|
||||
.retry-btn {
|
||||
align-self: flex-start;
|
||||
font-size: 12px;
|
||||
padding: 4px 12px;
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--glass-bg-raised);
|
||||
border: 1px solid var(--glass-border);
|
||||
color: var(--text-secondary);
|
||||
transition: background var(--transition-fast);
|
||||
}
|
||||
.retry-btn:hover:not(:disabled) { background: var(--glass-bg-hover); }
|
||||
.retry-btn:disabled { opacity: 0.5; cursor: default; }
|
||||
|
||||
.probe-btn { margin-top: 2px; }
|
||||
|
||||
.probe-results {
|
||||
margin-top: 6px;
|
||||
border-top: 1px solid var(--glass-border);
|
||||
padding-top: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.probe-title {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.probe-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
padding: 3px 6px;
|
||||
border-radius: 5px;
|
||||
background: rgba(255,255,255,0.03);
|
||||
}
|
||||
|
||||
.probe-row.probe-ok {
|
||||
background: rgba(168, 230, 0, 0.08);
|
||||
}
|
||||
|
||||
.probe-path {
|
||||
font-size: 10px;
|
||||
font-family: monospace;
|
||||
color: var(--text-primary);
|
||||
word-break: break-all;
|
||||
user-select: text;
|
||||
-webkit-user-select: text;
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.probe-note {
|
||||
font-size: 10px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.probe-row.probe-ok .probe-note {
|
||||
color: #a8e600;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.probe-hint {
|
||||
font-size: 10px;
|
||||
color: var(--text-muted);
|
||||
line-height: 1.5;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.sidebar-loading {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
/* Main calendar */
|
||||
.calendar-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: 14px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
background:
|
||||
linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, transparent 100%),
|
||||
rgba(10, 10, 17, 0.55);
|
||||
backdrop-filter: blur(18px) saturate(1.3);
|
||||
-webkit-backdrop-filter: blur(18px) saturate(1.3);
|
||||
overflow: hidden;
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.08),
|
||||
0 8px 28px rgba(0, 0, 0, 0.32);
|
||||
}
|
||||
|
||||
/* Toolbar */
|
||||
.toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 10px 16px;
|
||||
border-bottom: 1px solid var(--glass-border);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
height: 28px;
|
||||
padding: 0 10px;
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--glass-bg);
|
||||
border: 1px solid var(--glass-border);
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
transition: background var(--transition-fast), color var(--transition-fast);
|
||||
}
|
||||
|
||||
.nav-btn:hover:not(:disabled) {
|
||||
background: var(--glass-bg-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.nav-btn:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.today-btn {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.week-label {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
margin-left: 4px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
margin-left: auto;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.spinning {
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
/* Week wrap */
|
||||
.week-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Spinner */
|
||||
.spinner {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid var(--glass-border);
|
||||
border-top-color: var(--accent);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
/* Empty state (no accounts) */
|
||||
.empty-state {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: transparent;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.empty-content {
|
||||
text-align: center;
|
||||
padding: 64px 72px;
|
||||
width: 480px;
|
||||
background: rgba(255, 255, 255, 0.11);
|
||||
backdrop-filter: blur(72px) saturate(2.8);
|
||||
-webkit-backdrop-filter: blur(72px) saturate(2.8);
|
||||
border-radius: 20px;
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.55),
|
||||
0 8px 32px rgba(0, 0, 0, 0.45),
|
||||
0 32px 80px rgba(0, 0, 0, 0.65);
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
margin-bottom: 24px;
|
||||
opacity: 0.28;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.empty-content h2 {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.empty-content p {
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
padding: 10px 32px;
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
color-mix(in srgb, var(--accent) 88%, white 12%) 0%,
|
||||
var(--accent) 100%
|
||||
);
|
||||
color: var(--accent-text);
|
||||
border-radius: var(--radius-md);
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.40),
|
||||
0 2px 10px color-mix(in srgb, var(--accent) 30%, transparent);
|
||||
}
|
||||
|
||||
.add-btn:hover {
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
color-mix(in srgb, var(--accent-hover) 88%, white 12%) 0%,
|
||||
var(--accent-hover) 100%
|
||||
);
|
||||
}
|
||||
</style>
|
||||
|
|
@ -14,6 +14,12 @@ export interface ImapCredentials {
|
|||
smtpSecure?: boolean
|
||||
// Разрешить самоподписанные сертификаты — только для корпоративных серверов
|
||||
smtpAllowSelfSigned?: boolean
|
||||
// CalDAV — опционально; если не указан хост, используется IMAP-хост
|
||||
caldavHost?: string
|
||||
caldavPort?: number
|
||||
caldavSecure?: boolean
|
||||
caldavPath?: string // базовый путь, например /EWS/Calendar/ (если пуст — autodiscovery)
|
||||
caldavAllowSelfSigned?: boolean // разрешить самоподписанные/недоверенные сертификаты
|
||||
}
|
||||
|
||||
export type AccountCredentials = ImapCredentials
|
||||
|
|
|
|||
22
src/shared/types/calendar.ts
Normal file
22
src/shared/types/calendar.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
export interface CalendarInfo {
|
||||
id: string
|
||||
name: string
|
||||
color?: string
|
||||
accountId: string
|
||||
}
|
||||
|
||||
export interface CalendarEvent {
|
||||
id: string
|
||||
uid: string
|
||||
calendarId: string
|
||||
accountId: string
|
||||
title: string
|
||||
start: string // ISO 8601
|
||||
end: string // ISO 8601
|
||||
isAllDay: boolean
|
||||
location?: string
|
||||
description?: string
|
||||
organizer?: string
|
||||
attendees: string[]
|
||||
status?: 'tentative' | 'confirmed' | 'cancelled'
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import type { AccountConfig } from './account'
|
||||
import type { FolderListResult, MessageListResult } from './provider'
|
||||
import type { MessageBody, MessageFlags, MessageEnvelope, ComposeData, ComposeSession } from './message'
|
||||
import type { CalendarInfo, CalendarEvent } from './calendar'
|
||||
|
||||
export interface IpcChannelMap {
|
||||
'accounts:list': [void, AccountConfig[]]
|
||||
|
|
@ -47,6 +48,16 @@ export interface IpcChannelMap {
|
|||
|
||||
'app:setZoom': [{ factor: number }, void]
|
||||
'app:isEncryptionAvailable': [void, boolean]
|
||||
|
||||
'calendar:list': [{ accountId: string }, CalendarInfo[]]
|
||||
'calendar:events': [
|
||||
{ accountId: string; calendarId: string; start: string; end: string },
|
||||
CalendarEvent[]
|
||||
]
|
||||
'calendar:probe': [
|
||||
{ accountId: string },
|
||||
{ path: string; status: number; note: string }[]
|
||||
]
|
||||
}
|
||||
|
||||
export interface IpcEventMap {
|
||||
|
|
|
|||
Loading…
Reference in a new issue