feat: initialize electron main process, tray icon, and MariaDB operation service
This commit is contained in:
+12
-5
@@ -8,8 +8,10 @@ let tray: Tray | null = null
|
||||
let mainWindow: BrowserWindow | null = null
|
||||
|
||||
function createTray(): void {
|
||||
// Use a simple colored pixel if no icon is available for now
|
||||
const icon = nativeImage.createFromPath(join(__dirname, '../../resources/icon.png'))
|
||||
const iconPath = process.platform === 'win32'
|
||||
? join(__dirname, '../../resources/icon.ico')
|
||||
: join(__dirname, '../../resources/icon.png')
|
||||
const icon = nativeImage.createFromPath(iconPath)
|
||||
tray = new Tray(icon.isEmpty() ? nativeImage.createEmpty() : icon)
|
||||
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
@@ -17,7 +19,7 @@ function createTray(): void {
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: 'Göster/Gizle', click: () => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
||||
if (mainWindow.isVisible()) mainWindow.hide()
|
||||
else mainWindow.show()
|
||||
}
|
||||
@@ -38,7 +40,7 @@ function createTray(): void {
|
||||
tray.setContextMenu(contextMenu)
|
||||
|
||||
tray.on('double-click', () => {
|
||||
if (mainWindow) mainWindow.show()
|
||||
if (mainWindow && !mainWindow.isDestroyed()) mainWindow.show()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -48,6 +50,7 @@ function createWindow(): void {
|
||||
height: 800,
|
||||
show: false,
|
||||
autoHideMenuBar: true,
|
||||
icon: join(__dirname, '../../resources/icon.png'),
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
sandbox: false
|
||||
@@ -55,7 +58,11 @@ function createWindow(): void {
|
||||
})
|
||||
|
||||
mainWindow.on('ready-to-show', () => {
|
||||
if (mainWindow) mainWindow.show()
|
||||
if (mainWindow && !mainWindow.isDestroyed()) mainWindow.show()
|
||||
})
|
||||
|
||||
mainWindow.on('closed', () => {
|
||||
mainWindow = null
|
||||
})
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
|
||||
@@ -143,10 +143,48 @@ export class MariaDbOperationService {
|
||||
|
||||
// Pipe the file content to stdin
|
||||
const fileStream = fs.createReadStream(sqlFilePath)
|
||||
|
||||
// Performance optimizations
|
||||
child.stdin.write('SET foreign_key_checks = 0;\n')
|
||||
child.stdin.write('SET unique_checks = 0;\n')
|
||||
child.stdin.write('SET autocommit = 0;\n')
|
||||
child.stdin.write('SET sql_log_bin = 0;\n')
|
||||
|
||||
fileStream.on('error', (err) => {
|
||||
onProgress?.(`File read error: ${err.message}`)
|
||||
})
|
||||
fileStream.pipe(child.stdin)
|
||||
|
||||
fileStream.on('data', (chunk) => {
|
||||
if (child.stdin.writable) {
|
||||
try {
|
||||
child.stdin.write(chunk)
|
||||
} catch (e: any) {
|
||||
if (e.code === 'EPIPE') {
|
||||
onProgress?.(`Warning: EPIPE error encountered. The child process may have closed the pipe early.`)
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
fileStream.on('end', () => {
|
||||
if (child.stdin.writable) {
|
||||
child.stdin.write('\nCOMMIT;\n')
|
||||
child.stdin.write('SET foreign_key_checks = 1;\n')
|
||||
child.stdin.write('SET unique_checks = 1;\n')
|
||||
child.stdin.write('SET autocommit = 1;\n')
|
||||
child.stdin.end()
|
||||
}
|
||||
})
|
||||
|
||||
child.stdin.on('error', (err: any) => {
|
||||
if (err.code === 'EPIPE') {
|
||||
onProgress?.(`Notice: Broken pipe (EPIPE). This usually means MariaDB finished or aborted before we finished writing.`)
|
||||
} else {
|
||||
onProgress?.(`Stdin error: ${err.message}`)
|
||||
}
|
||||
})
|
||||
|
||||
child.stdout.on('data', (data) => onProgress?.(data.toString()))
|
||||
child.stderr.on('data', (data) => onProgress?.(data.toString()))
|
||||
@@ -199,6 +237,9 @@ export class MariaDbOperationService {
|
||||
`--host=${config.host}`,
|
||||
`--port=${config.port}`,
|
||||
`--user=${config.rootUser}`,
|
||||
'--quick',
|
||||
'--single-transaction',
|
||||
'--max_allowed_packet=1G',
|
||||
dbName,
|
||||
'--routines',
|
||||
'--triggers'
|
||||
|
||||
Reference in New Issue
Block a user