()
| 1598 | } |
| 1599 | |
| 1600 | // Close HTTP server |
| 1601 | server.close(() => { |
| 1602 | console.log('HTTP server closed'); |
| 1603 | if (httpServerEpoch === epoch) { |
| 1604 | httpServer = null; |
| 1605 | wsClients = null; |
| 1606 | global.broadcastEvent = null; |
| 1607 | global.sendEvent = null; |
| 1608 | } |
| 1609 | resolve(); |
| 1610 | }); |
| 1611 | |
| 1612 | // Force close after timeout if graceful shutdown doesn't complete |
| 1613 | setTimeout(() => { |
| 1614 | if (httpServerEpoch !== epoch) return; |
| 1615 | if (httpServer === server) { |
| 1616 | console.log('Force closing HTTP server...'); |
| 1617 | try { |
| 1618 | server.close(); |
| 1619 | } catch (error) { |
| 1620 | console.error('Error force closing server:', error); |
| 1621 | } |
| 1622 | httpServer = null; |
| 1623 | wsClients = null; |
| 1624 | wss = null; |
| 1625 | global.broadcastEvent = null; |
| 1626 | global.sendEvent = null; |
| 1627 | resolve(); |
| 1628 | } |
| 1629 | }, 5000); |
| 1630 | }); |
| 1631 | } |
| 1632 | |
| 1633 | function getSettingValueOr(key, fallback) { |
| 1634 | try { |
| 1635 | if (!db) return fallback; |
| 1636 | const row = db.prepare('SELECT value FROM settings WHERE key = ?').get(key); |
| 1637 | if (row && row.value != null && row.value !== '') return row.value; |
| 1638 | } catch (_) { /* ignore */ } |
| 1639 | return fallback; |
| 1640 | } |
| 1641 | |
| 1642 | let extensionInboxTimer = null; |
| 1643 | let extensionInboxImporting = false; |
| 1644 | |
| 1645 | function getExtensionInboxDirectory() { |
| 1646 | return extensionInbox.resolveInboxDirectory(getSettingValueOr('extensionInboxDirectory', '')); |
| 1647 | } |
| 1648 | |
| 1649 | function getExtensionInboxDirectories() { |
| 1650 | const custom = (getSettingValueOr('extensionInboxDirectory', '') || '').trim(); |
| 1651 | return extensionInbox.uniqueInboxDirectories([ |
| 1652 | custom || null, |
| 1653 | extensionInbox.defaultInboxDirectory(), |
| 1654 | extensionInbox.inboxDirectoryBesideDatabase(getDatabasePath()) |
| 1655 | ]); |
| 1656 | } |
| 1657 |
no test coverage detected