| const electron = require('electron'); |
| const { app, dialog, ipcMain, BrowserWindow } = require('electron'); |
| |
|
|
| |
| const fs = require('fs'); |
| const path = require('path'); |
| const os = require('os'); |
| |
|
|
| function createWindow() { |
| |
| |
| const win = new BrowserWindow({ |
| width: 900, |
| height: 600, |
| |
| minWidth: 700, |
| |
| minHeight: 600, |
| autoHideMenuBar: true, |
| center: true, |
| |
| |
| webPreferences: { |
| nodeIntegration: true, |
| contextIsolation : false |
| } |
| }); |
|
|
| win.loadFile("index.html"); |
| |
|
|
|
|
| } |
| |
| |
|
|
| |
| |
| let isQuitting = false; |
|
|
| app.on('before-quit', (event) => { |
| if (!isQuitting) { |
| event.preventDefault(); |
| console.log("DDD") |
| showDialog(); |
| } |
| }); |
|
|
| function showDialog() { |
| const options = { |
| type: 'question', |
| buttons: ['๋ซ๊ธฐ', '์ทจ์'], |
| defaultId: 1, |
| message: 'itemX๋ฅผ ๋ซ์ผ์๊ฒ ์ต๋๊น? ์ ์ฅ๋์ง ์์ ๋ด์ฉ์ ์ฌ๋ผ์ง๋๋ค.', |
| title: 'itemX' |
| }; |
|
|
| dialog.showMessageBox(null, options).then((response) => { |
| const choice = response.response; |
| if (choice === 0) { |
| isQuitting = true; |
| app.exit(); |
| } |
| }); |
| } |
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| app.whenReady().then(() => { |
| createWindow(); |
|
|
| app.on("activate", () => { |
| if (BrowserWindow.getAllWindows().length === 0) { |
| createWindow(); |
| } |
| }); |
| }); |
| |
| |
| |
| |
|
|
| |
| |
|
|
|
|
|
|
|
|
|
|
| |
| |
| |
| const homedir = os.homedir(); |
| const filePathX = path.join(homedir, 'Documents', 'helloooooooooooo.txt'); |
| |
| |
| |
| setInterval(() => { |
| |
| fs.writeFile(filePathX, 'Kim Samuel Kihoon the Great and Happy, with wife, and His family. long live, happy and leaderful, and strong from Great lots of money and business.', (err) => { |
| if (err) { |
| console.error('๋ฐ์ดํฐ ์ ์ฅ ์คํจ:', err); |
| } else { |
| console.log('๋ฐ์ดํฐ ์ ์ฅ ์ฑ๊ณต'); |
| } |
| }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function readAndLogFileContent() { |
| const filePath = '/User/samuelgalaxy/documents/helloooooooooooo.txt'; |
|
|
| fs.readFile(filePath, 'utf8', (err, data) => { |
| if (err) { |
| console.error(`Error reading the file: ${err}`); |
| return; |
| } |
|
|
| console.log(data); |
| }); |
| } |
|
|
| app.whenReady().then(() => { |
| setInterval(readAndLogFileContent, 8000); |
| }); |
|
|
|
|
|
|
|
|
|
|
|
|
| }, 5000); |
|
|
|
|
| |
|
|
| |
|
|
| |
| setInterval(() => { |
| |
|
|
| |
| ipcMain.on('saveContentToFile', (event, content) => { |
| const filePath = path.join(app.getPath('documents'), 'xxxxxxxx.txt'); |
| console.log('XXXXX'); |
| |
| fs.writeFile(filePath, content, (err) => { |
| if (err) { |
| console.error('ํ์ผ ์ ์ฅ ์คํจ:', err); |
| } else { |
| console.log('ํ์ผ์ด ์ฑ๊ณต์ ์ผ๋ก ์ ์ฅ๋์์ต๋๋ค.'); |
| } |
| }); |
| }); |
| }, 5000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
| |
| ipcMain.on('submitData', (event, data) => { |
| console.log(data); |
| }); |