2023-08-05 08:07:34 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
2023-08-12 07:33:07 +02:00
|
|
|
import { Subject } from 'rxjs';
|
2023-08-05 08:07:34 +02:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class MyElectronService {
|
2023-08-12 07:33:07 +02:00
|
|
|
detectedLangSubject = new Subject<DetectedLang[]>();
|
|
|
|
|
2023-08-05 08:07:34 +02:00
|
|
|
constructor() {
|
2023-08-12 07:33:07 +02:00
|
|
|
try {
|
|
|
|
if ((<any>window).api) {
|
|
|
|
(<any>window).api.receive("detectedLang", (data) => {
|
|
|
|
const result = [];
|
|
|
|
for (const l of data) {
|
|
|
|
let newLang = new DetectedLang(l[0], l[1]);
|
|
|
|
result.push(newLang);
|
|
|
|
}
|
|
|
|
this.detectedLangSubject.next(result);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.detectLang("ceci est une phrase");
|
2023-08-05 08:07:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setLang(lang: string) {
|
|
|
|
try {
|
2023-08-05 08:48:24 +02:00
|
|
|
if ((<any>window).api) {
|
2023-08-06 00:03:22 +02:00
|
|
|
(<any>window).api.send("changeSpellchecker", lang);
|
2023-08-05 08:48:24 +02:00
|
|
|
}
|
2023-08-05 08:07:34 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
2023-08-12 07:33:07 +02:00
|
|
|
|
|
|
|
detectLang(text: string) {
|
|
|
|
try {
|
|
|
|
if ((<any>window).api) {
|
|
|
|
(<any>window).api.send("detectLang", text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class DetectedLang {
|
|
|
|
constructor(
|
|
|
|
public lang: string,
|
|
|
|
public score: number
|
|
|
|
) {}
|
2023-08-05 08:07:34 +02:00
|
|
|
}
|