-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
132 lines (116 loc) · 3.2 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
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
const { app, BrowserWindow, ipcMain, dialog, session } = require('electron')
const path = require('path')
const fs = require('fs')
//const env = require('./static/js/env.js')
const {env} = require('./static/js/addon.js')
const Stemdb= env('StemdbDir')
const sqlite3 = require('sqlite3').verbose()
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
app.allowRendererProcessReuse = false
// Create a new db
const dbBuild = ()=>{
const db = new sqlite3.Database(Stemdb + '.db')
db.get('PRAGMA foreign_keys = ON')
db.run(`create table "File" (
"id" integer not null unique,
"name" text not null unique,
"file" text not null,
primary key("id" autoincrement)
)`,()=>{})
db.run(`create table "Tag" (
"id" integer not null unique,
"tag" text not null unique,
primary key("id" autoincrement)
)`,()=>{})
db.run(`create table "Ref" (
"id" integer not null unique,
"nameref" text,
"tagref" text,
primary key("id" autoincrement)
foreign key('nameref') references File(name) on delete cascade on update cascade,
foreign key('tagref') references Tag(tag) on delete cascade on update cascade,
unique(nameref,tagref)
)`,()=>{})
db.run(`create table "Monitor" (
"id" integer not null unique,
"parent" text,
"name" text not null unique,
primary key("id" autoincrement)
)`,()=>{})
}
// Check essential folders
const firstBuild = ()=>{
const dbStorage = env('StemdbStorage')
const mdbStorage = env('StemMGDir')
if (!fs.existsSync(dbStorage)){
fs.mkdir(dbStorage,{recursive:true},()=>{
if (!fs.existsSync(mdbStorage)){
fs.mkdir(mdbStorage,{recursive:true},()=>{})
}
})
}
}
// WindowsCreator
// Main Window
const WindowMain = async () => {
const win = new BrowserWindow({
width: env('Width'),
height: env('Height'),
webPreferences: {
disableBlinkFeatures: 'DisallowInsecureUsage,AllowLists',
allowlist:['style-src','self'],
preload: path.join(__dirname, 'preload.js'),
contextIsolation:true,
nodeIntegration: false
}
})
if (env('Debugmode')){
win.webContents.openDevTools()
}
win.loadFile(env('TemplateDir') + 'index.html')
// Communication Test
ipcMain.handle('tele-test',(event,v) =>{
// console.log('child' + v)
win.webContents.send('tele-test552',v)
})
ipcMain.handle('tele-test2',(event,v) =>{
console.log('father' + v)
})
}
//--- Test
/*
var exec = require('child_process').exec;
exec('NET SESSION', function(err,so,se) {
console.log(se.length === 0 ? "admin" : "not admin")
}) */
const init = () =>{
firstBuild()
dbBuild()
const Taskmanager = () =>{
/*
const funcScript = glob.sync(env('StaticDir') + '/js/*.js')
funcScript.forEach((i) =>{require(i)})*/
const scriptDir = env('StaticDir') + 'js/'
const filelist = fs.readdirSync(scriptDir)
for(var i=0;i<filelist.length;i++){
require(scriptDir + filelist[i])
}
}
Taskmanager()
app.whenReady().then(() => {
WindowMain()
// Prevent from multiple windows create
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
WindowMain()
}
})
})
}
init()
// Release all resources of the app
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})