-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
94 lines (74 loc) · 2.57 KB
/
main.js
File metadata and controls
94 lines (74 loc) · 2.57 KB
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
import { app, BrowserWindow, ipcMain } from'electron';
import path from'path';
import serve from'electron-serve';
import Store from 'electron-store';
import { fileURLToPath } from 'url';
const loadURL = serve({ directory: 'build' });
const store = new Store()
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
let mainWindow;
function isDev() {
return !app.isPackaged;
}
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200, //1200
height: 585, // 600
webPreferences: {
nodeIntegration: false,
preload: path.join(__dirname, 'preload.ts'),
contextIsolation: true,
},
icon: isDev() ? path.join(process.cwd(), 'public/logo512.png') : path.join(__dirname, 'build/logo512.png'),
show: false
});
if (isDev()) {
mainWindow.loadURL('http://localhost:3000/');
} else {
loadURL(mainWindow);
}
mainWindow.on('closed', function () {
mainWindow = null
});
mainWindow.once('ready-to-show', () => {
mainWindow.show()
let lastUser = store.get('lastUser', {
name: "Rodrigo Oliveira",
id: "02f55375-b904-430e-a67e-23a69f755ddb"});
mainWindow.webContents.send('initial-user', lastUser);
});
}
function handleSetPokedex (event, pokedex, user) {
const pokedexPath = user.id + ".pokedex";
store.set(pokedexPath, pokedex);
}
function handleGetUserPokedex (event, user) {
store.set('lastUser', user);
const pokedexPath = user.id + ".pokedex"
let pokedex = store.get(pokedexPath, []);
return pokedex;
}
function handleTradePokemon(event, pokemon, userOwner, userDestiny) {
const ownerPokedexPath = userOwner.id + ".pokedex";
let ownerPokedex = store.get(ownerPokedexPath, []);
const destinyPokedexPath = userDestiny.id + ".pokedex";
let destinyPokedex = store.get(destinyPokedexPath, []);
ownerPokedex = ownerPokedex.filter(c => c.id !== pokemon.id);
destinyPokedex = [...destinyPokedex, pokemon];
store.set(ownerPokedexPath, ownerPokedex);
store.set(destinyPokedexPath, destinyPokedex);
return ownerPokedex;
}
app.whenReady().then(() => {
ipcMain.on('set-pokedex', handleSetPokedex);
ipcMain.handle('trade-pokemon', handleTradePokemon);
ipcMain.handle('get-user-pokedex', handleGetUserPokedex);
createWindow()
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
});
app.on('activate', function () {
if (mainWindow === null) createWindow()
});