WIP to handle outside of electron build

This commit is contained in:
2025-12-10 06:56:24 +00:00
parent da4e87d3cd
commit d179e1c42e
7 changed files with 91 additions and 37 deletions

View File

@@ -33,12 +33,64 @@ export class AppComponent {
protected ws: WebsocketService = inject(WebsocketService);
constructor() {}
constructor() {
this.checkIfNotElectronMode();
}
ngOnInit() {
ngOnInit() {}
checkIfNotElectronMode() {
if (
window.electron ||
window.main ||
window.fs
) { return; }
this.setupWebsocket();
this.setupWindowBindings();
}
setupWindowBindings() {
window.electron ??= {
node: () => { return "" },
chrome: () => { return "" },
electron: () => { return "" },
};
window.main ??= {
onMenuActions: () => {},
onTerminalActions: () => {},
quit: () => {},
toggleFullScreen: () => {},
};
window.fs ??= {
getLspConfigData: () => {
return new Promise((resolve, reject) => {
resolve("{}");
});
},
getFileContents: () => {},
openFiles: () => {},
saveFile: () => {},
saveFileAs: () => {},
chooseFolder: () => {},
closeFile: () => {},
getPathForFile: () => {},
onLoadFiles: () => {},
onUpdateFilePath: () => {},
onSavedFile: () => {},
onChangedFile: () => {},
onDeletedFile: () => {},
};
}
setupWebsocket() {
// TODO: Set with dynamic address and port
this.ws.connect('ws://localhost:7272').subscribe(msg => {
console.log(msg);
console.log(window.fs);
// this.ws.send("{ 'text': 'Hello server!' }");
});
}

View File

@@ -42,7 +42,7 @@ export class LspManagerService {
}
private getLspConfigData(): Promise<string> {
return window.fs.getLspConfigData();
return window?.fs.getLspConfigData();
}
private parseAndReturnLSPConfigData(): {} {

View File

@@ -55,7 +55,7 @@ export class FilesService {
public unset(file: NewtonFile) {
file.session.destroy();
window.fs.closeFile(file.path);
window?.fs.closeFile(file.path);
this.files.delete(file.path);
}
@@ -76,7 +76,7 @@ export class FilesService {
): Promise<NewtonFile | undefined | null> {
for (let i = 0; i < files.length; i++) {
const file = files[i];
const path = window.fs.getPathForFile(file);
const path = window?.fs.getPathForFile(file);
if (!file || !path) continue;
if ( this.files.get(path) ) continue;
@@ -101,7 +101,7 @@ export class FilesService {
file.hash = btoa(file.path);
if (loadFileContents)
data = await window.fs.getFileContents(file.path);
data = await window?.fs.getFileContents(file.path);
file.session = new EditSession(data);
file.session["id"] = path;

View File

@@ -187,7 +187,7 @@ export class CodeViewBase {
}
public toggleFullScreen() {
window.main.toggleFullScreen();
window?.main.toggleFullScreen();
}
public setAsReadOnly() {
@@ -300,7 +300,7 @@ export class CodeViewBase {
startDir = pathParts.join( '/' );
}
window.fs.openFiles(startDir);
window?.fs.openFiles(startDir);
}
protected saveFile() {
@@ -312,18 +312,18 @@ export class CodeViewBase {
}
const text = this.activeFile.session.getValue();
window.fs.saveFile(this.activeFile.path, text);
window?.fs.saveFile(this.activeFile.path, text);
this.activeFile.session.getUndoManager().markClean();
}
protected saveFileAs() {
window.fs.saveFileAs().then((path: string) => {
window?.fs.saveFileAs().then((path: string) => {
if (!path) return;
let file: NewtonFile = new File([""], path, {});
const text = this.editor.session.getValue();
window.fs.saveFile(path, text);
window?.fs.saveFile(path, text);
this.filesService.addFile(
path,
file,
@@ -364,6 +364,6 @@ export class CodeViewBase {
}
private quit() {
window.main.quit();
window?.main.quit();
}
}

View File

@@ -76,7 +76,7 @@ export class EditorsComponent {
}
private loadMainSubscribers() {
window.main.onMenuActions(async (action: string) => {
window?.main.onMenuActions(async (action: string) => {
let editorComponent = this.editorsService.getActiveEditorComponent();
let editor = editorComponent.editor;
@@ -112,7 +112,7 @@ export class EditorsComponent {
case "show-about":
break;
case "quit":
window.main.quit();
window?.main.quit();
break;
default:
editor.execCommand(action);
@@ -120,7 +120,7 @@ export class EditorsComponent {
}
});
window.fs.onLoadFiles(async (paths: []) => {
window?.fs.onLoadFiles(async (paths: []) => {
for (let i = 0; i < paths.length; i++) {
let file = new File([], "") as NewtonFile;
@@ -135,7 +135,7 @@ export class EditorsComponent {
this.editorsService.setSession(file);
});
window.fs.onChangedFile(async (path: string, data: string) => {
window?.fs.onChangedFile(async (path: string, data: string) => {
let file = this.filesService.get(path);
file.session.setValue(data);
@@ -147,7 +147,7 @@ export class EditorsComponent {
this.tabsService.sendMessage(message);
});
window.fs.onDeletedFile(async (path: string) => {
window?.fs.onDeletedFile(async (path: string) => {
let message = new ServiceMessage();
message.action = "file-deleted";
message.filePath = path;
@@ -156,7 +156,7 @@ export class EditorsComponent {
this.filesService.sendMessage(message);
});
window.fs.onSavedFile(async (path: string) => {
window?.fs.onSavedFile(async (path: string) => {
let message = new ServiceMessage();
message.action = "file-saved";
message.filePath = path;
@@ -164,7 +164,7 @@ export class EditorsComponent {
this.tabsService.sendMessage(message);
});
window.fs.onUpdateFilePath(async (path: string) => {
window?.fs.onUpdateFilePath(async (path: string) => {
console.log("TODO (onUpdateFilePath) :", path);
// this.tabsService.sendMessage(message);
// this.filesService.sendMessage(message);

View File

@@ -134,7 +134,7 @@ export class LspManagerComponent {
}
public setWorkspaceFolder() {
window.fs.chooseFolder().then((folder: string) => {
window?.fs.chooseFolder().then((folder: string) => {
if (!folder) return;
this.lspManagerService.workspaceFolder = folder;

View File

@@ -11,33 +11,35 @@
import 'zone.js'; // Included with Angular CLI.
// Note: Is set to 'any' b/c of desire to set 'render'
// side if running outside of electron mode.
declare global {
interface Window {
electron: {
node: () => Promise<string>,
chrome: () => Promise<string>,
electron: () => Promise<string>,
node: any,
chrome: any,
electron: any,
},
main: {
onMenuActions: (arg0: any) => Promise<string>,
onTerminalActions: (arg0: any) => Promise<string>,
onMenuActions: any,
onTerminalActions: any,
quit: any,
toggleFullScreen: any,
},
fs: {
getLspConfigData: () => Promise<string>,
getFileContents: (arg0: any) => Promise<string>,
openFiles: (arg0) => Promise<string>,
saveFile: (arg0: any, arg1: any) => Promise<string>,
saveFileAs: () => Promise<string>,
chooseFolder: () => Promise<string>,
closeFile: (arg0: any) => Promise<string>,
getLspConfigData: any,
getFileContents: any,
openFiles: any,
saveFile: any,
saveFileAs: any,
chooseFolder: any,
closeFile: any,
getPathForFile: any,
onLoadFiles: (arg0: any) => Promise<string>,
onUpdateFilePath: (arg0: any) => Promise<string>,
onSavedFile: (arg0: any) => Promise<string>,
onChangedFile: (arg0: any) => Promise<string>,
onDeletedFile: (arg0: any) => Promise<string>,
onLoadFiles: any,
onUpdateFilePath: any,
onSavedFile: any,
onChangedFile: any,
onDeletedFile: any,
}
}
}