-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
146 lines (135 loc) · 3.19 KB
/
main.js
File metadata and controls
146 lines (135 loc) · 3.19 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//
const electron = require('electron')
//
const { app,BrowserWindow, ipcMain, dialog, Menu,screen} = electron
//
const fs=require('fs')
//
const file_name_path = require('path');
//
let file_name,file_name1,file_name2,file_name3
//
const child = require('child_process');
//Warning about deprecating something to with this dont touch(Need to do more Research)
//electron.app.allowRendererProcessReuse = true;
//Window variable
let win
//
let newName,oldName
//
//When Our Main Process is ready
app.on('ready',()=>{
console.log('Main Process is Running')
})
//
app.whenReady().then(() => {
const { width, height } = screen.getPrimaryDisplay().workAreaSize
//win = new BrowserWindow({width:width,height:height})
win = new BrowserWindow({
width,
height,
//show: false ,
//frame:false,
webPreferences:{
nodeIntegration:true
}
});
win.loadFile('index.html');
})
//
ipcMain.on('open-example-game',(event,data)=>{
console.log("Madddiiis");
gameBox();
});
//
function gameBox(){
const { width, height } = screen.getPrimaryDisplay().workAreaSize
let gameBoxWin = new BrowserWindow({
width,
height,
webPreferences:{
nodeIntegration:true
}
});
gameBoxWin.loadFile('assets/hzint.org/matcher.html');
}
//Open Game1
ipcMain.on('open-game',(event,data) => {
//
oldName = data
let exten = oldName.slice(-4)
console.log(exten)
if (exten == '.txt'){
newName = oldName.replace(".txt",".exe")
console.log(newName)
//
fs.rename(oldName, newName, function (err) {
if (err) throw err;
console.log('File Renamed to ',newName);
});
let executablePath = newName;
child.execFile(executablePath, function(error, stdout, stderr) {
if(error){
console.error(error);
return;
}
console.log(stderr.toString());
console.log("Program closed");
fs.rename(newName, oldName, function (err) {
if (err) throw err;
console.log('File Renamed.',oldName);
});
});
}
})
//Reading from a file Xdoc
//f
function open_File(value){
//
file_name1='./assets/templates/starter.html'
file_name2='./assets/templates/book.html'
file_name3='./assets/templates/unit.html'
file_name4='./assets/templates/book_view.html'
file_name5='./assets/templates/unit_view.html'
//
//
let msg = `receive_file`+ value
if (value == `starter`){
file_name = file_name1
}
if (value == `book`){
file_name = file_name2
}
if (value == `unit`){
file_name = file_name3
}
if (value == `bookview`){
file_name = file_name4
}
if (value == `unitview`){
file_name = file_name5
}
//
//Extension test
let exten = file_name.slice(-5)
console.log(exten)
console.log(file_name)
console.log(msg)
//
if(exten == '.html' ){
fs.readFile(file_name,'utf-8',(err,data) => {
if (err) throw err
//
//console.log(data)
//
win.webContents.send(msg,data)
})
}else{
console.log('Not Correct file format')
}
}
//
ipcMain.on('need_file0',(event,data) => {
open_File(data);
console.log('need_file' + data)
})