-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
94 lines (73 loc) · 2.32 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const electron = require('electron');
const url = require('url');
const path = require('path');
const db = require('./lib/connection').db;
const { app, BrowserWindow, ipcMain } = electron;
let mainWindow;
let todoList = [];
app.on('ready', () => {
console.log('Program başladı');
mainWindow = new BrowserWindow(
{width: 450, height: 750,frame:false,
webPreferences: {
nodeIntegration: true
}
}
);
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, "main.html"),
protocol: "file:",
slashes: true
})
);
ipcMain.on("key:newGoal", (err, data) => {
if (data) {
let todo = {
id: todoList.length + 1,
text: data
};
todoList.push(todo);
db.query("INSERT INTO goals SET text = ?", data, (e,r,f) => {
if (r.affectedRows > 0) {
console.log('Gorev basariyla eklendi');
}
});
mainWindow.webContents.send("key:addItem", todo);
}
});
// Çıkış butonu
ipcMain.on("key:exitButton", (err, data) =>{
process.exit()
});
// İlk render işlemi
mainWindow.webContents.once("dom-ready", () => {
db.query("SELECT * FROM goals WHERE completed = 0 ORDER BY 'id' DESC", (error, results, fields) => {
mainWindow.webContents.send("init", results);
});
});
// Silme işlemi
ipcMain.on("deleteGoal", (err, data) => {
db.query("DELETE FROM goals WHERE id = ?", data, (e,r,f) => {
if (r.affectedRows > 0) {
console.log("Basariyla silindi");
}
});
});
// Tamamlanan görev işlemi
ipcMain.on("completeGoal", (err, data) => {
db.query("UPDATE goals SET completed = 1 WHERE id = ?",data, (e,r,f) => {
if (r.affectedRows > 0) {
console.log("Basariyla guncellendi");
}
});
});
// Temizlik işlemi
ipcMain.on("deleteAll", (err, data) => {
db.query("DELETE FROM goals",data, (e,r,f) => {
if (r.affectedRows > 0) {
console.log("Tum gorevler silindi");
}
});
});
});