-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
141 lines (119 loc) · 4.16 KB
/
renderer.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
133
134
135
136
137
138
139
140
141
const { ipcRenderer } = require('electron')
const ipc = ipcRenderer
const marked = require('marked')
const DOMPurify = require('dompurify');
const fs = require('fs');
const path = require('path');
const { BlockList } = require('net');
let userDataPath = process.env.APPDATA;
if (process.platform == 'darwin') {
userDataPath = process.env.HOME + '/Library/Preferences/'
} else if (process.platform == 'linux') {
userDataPath = process.env.HOME + '/.local/share/';
}
const minimizeButton = document.getElementById("minimize-btn");
const maxUnmaxButton = document.getElementById("maximize-btn");
const closeButton = document.getElementById("close-btn");
const iconMax = document.getElementById('icons-btn-max');
minimizeButton.addEventListener('click', ()=>{
ipc.send('minimizeApp')
})
maxUnmaxButton.addEventListener('click', ()=>{
ipc.send('maximizeRestoreApp')
})
function changeMaxResBtn(isMaximizedApp){
if(isMaximizedApp){
iconMax.classList.remove("fa-window-maximize");
iconMax.classList.add("fa-window-restore");
maxUnmaxButton.title = 'Restaurer'
} else {
iconMax.classList.add("fa-window-maximize");
iconMax.classList.remove("fa-window-restore");
maxUnmaxButton.title = 'Maximiser'
}
}
ipc.on('isMaximized', ()=>{ changeMaxResBtn(true) })
ipc.on('isRestored', ()=>{ changeMaxResBtn(false) })
closeButton.addEventListener('click', ()=>{
ipc.send('closeApp')
})
const titreApp = document.getElementById('titreApp')
if (titreApp !== null) {
titreApp.addEventListener('click', ()=>{
ipc.send('titreApp')
})
}
let launch = true;
function exchangeMessages() {
marked.setOptions({
renderer: new marked.Renderer(),
highlight: function(code, lang) {
const hljs = require('highlight.js');
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
return hljs.highlight(code, { language }).value;
},
langPrefix: 'hljs language-', // highlight.js css expects a top-level 'hljs' class.
pedantic: false,
gfm: true,
breaks: false,
sanitize: false,
smartypants: false,
xhtml: false
});
let first = true
let messages = document.getElementById("messages");
let question = document.getElementById("question").value;
document.getElementById("question").setAttribute('value', '');
document.getElementById("question").value = "";
// send username to main.js
ipc.send('asynchronous-message', question)
if (!launch) {
question = DOMPurify.sanitize(marked.parse(question));
if (messages.innerHTML !== '') {
messages.innerHTML += "<br><br><div id='Utilisateur'>Utilisateur : </div>" + question;
} else {
messages.innerHTML = "<div id='Utilisateur'>Utilisateur : </div>" + question;
}
}
launch = false;
// receive message from main.js
ipc.on('asynchronous-reply', (event, responseGPT) => {
if (first) {
responseGPT = DOMPurify.sanitize(marked.parse(responseGPT));
if (messages.innerHTML !== '') {
messages.innerHTML += "<br><br><div id='chatGPT'>Marv : </div>" + responseGPT;
} else {
messages.innerHTML += "<div id='chatGPT'>Marv : </div>" + responseGPT;
}
first = false;
}
})
messages.scrollTop = messages.scrollHeight;
}
exchangeMessages();
const submit = document.getElementById("submitButton");
submit.addEventListener('click', (event) => {
exchangeMessages();
});
const textarea = document.getElementById("question");
textarea.addEventListener("keydown", (event) => {
if (event.key === 'Enter') {
exchangeMessages();
}
});
const settings = document.getElementById('settings');
const close = document.getElementById('close');
let myModal = document.getElementById('myModal');
settings.addEventListener('click', (event) => {
showModal();
});
close.addEventListener('click', (event) => {
showModal();
});
function showModal() {
if (myModal.style.display === 'none') {
myModal.style.display = 'block';
} else {
myModal.style.display = 'none'
}
}