WIP to handle outside of electron build
This commit is contained in:
@@ -33,12 +33,64 @@ export class AppComponent {
|
|||||||
protected ws: WebsocketService = inject(WebsocketService);
|
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
|
// TODO: Set with dynamic address and port
|
||||||
this.ws.connect('ws://localhost:7272').subscribe(msg => {
|
this.ws.connect('ws://localhost:7272').subscribe(msg => {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
|
console.log(window.fs);
|
||||||
// this.ws.send("{ 'text': 'Hello server!' }");
|
// this.ws.send("{ 'text': 'Hello server!' }");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export class LspManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getLspConfigData(): Promise<string> {
|
private getLspConfigData(): Promise<string> {
|
||||||
return window.fs.getLspConfigData();
|
return window?.fs.getLspConfigData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseAndReturnLSPConfigData(): {} {
|
private parseAndReturnLSPConfigData(): {} {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export class FilesService {
|
|||||||
|
|
||||||
public unset(file: NewtonFile) {
|
public unset(file: NewtonFile) {
|
||||||
file.session.destroy();
|
file.session.destroy();
|
||||||
window.fs.closeFile(file.path);
|
window?.fs.closeFile(file.path);
|
||||||
this.files.delete(file.path);
|
this.files.delete(file.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ export class FilesService {
|
|||||||
): Promise<NewtonFile | undefined | null> {
|
): Promise<NewtonFile | undefined | null> {
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const file = files[i];
|
const file = files[i];
|
||||||
const path = window.fs.getPathForFile(file);
|
const path = window?.fs.getPathForFile(file);
|
||||||
|
|
||||||
if (!file || !path) continue;
|
if (!file || !path) continue;
|
||||||
if ( this.files.get(path) ) continue;
|
if ( this.files.get(path) ) continue;
|
||||||
@@ -101,7 +101,7 @@ export class FilesService {
|
|||||||
file.hash = btoa(file.path);
|
file.hash = btoa(file.path);
|
||||||
|
|
||||||
if (loadFileContents)
|
if (loadFileContents)
|
||||||
data = await window.fs.getFileContents(file.path);
|
data = await window?.fs.getFileContents(file.path);
|
||||||
|
|
||||||
file.session = new EditSession(data);
|
file.session = new EditSession(data);
|
||||||
file.session["id"] = path;
|
file.session["id"] = path;
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ export class CodeViewBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public toggleFullScreen() {
|
public toggleFullScreen() {
|
||||||
window.main.toggleFullScreen();
|
window?.main.toggleFullScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
public setAsReadOnly() {
|
public setAsReadOnly() {
|
||||||
@@ -300,7 +300,7 @@ export class CodeViewBase {
|
|||||||
startDir = pathParts.join( '/' );
|
startDir = pathParts.join( '/' );
|
||||||
}
|
}
|
||||||
|
|
||||||
window.fs.openFiles(startDir);
|
window?.fs.openFiles(startDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected saveFile() {
|
protected saveFile() {
|
||||||
@@ -312,18 +312,18 @@ export class CodeViewBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const text = this.activeFile.session.getValue();
|
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();
|
this.activeFile.session.getUndoManager().markClean();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected saveFileAs() {
|
protected saveFileAs() {
|
||||||
window.fs.saveFileAs().then((path: string) => {
|
window?.fs.saveFileAs().then((path: string) => {
|
||||||
if (!path) return;
|
if (!path) return;
|
||||||
|
|
||||||
let file: NewtonFile = new File([""], path, {});
|
let file: NewtonFile = new File([""], path, {});
|
||||||
const text = this.editor.session.getValue();
|
const text = this.editor.session.getValue();
|
||||||
|
|
||||||
window.fs.saveFile(path, text);
|
window?.fs.saveFile(path, text);
|
||||||
this.filesService.addFile(
|
this.filesService.addFile(
|
||||||
path,
|
path,
|
||||||
file,
|
file,
|
||||||
@@ -364,6 +364,6 @@ export class CodeViewBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private quit() {
|
private quit() {
|
||||||
window.main.quit();
|
window?.main.quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ export class EditorsComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private loadMainSubscribers() {
|
private loadMainSubscribers() {
|
||||||
window.main.onMenuActions(async (action: string) => {
|
window?.main.onMenuActions(async (action: string) => {
|
||||||
let editorComponent = this.editorsService.getActiveEditorComponent();
|
let editorComponent = this.editorsService.getActiveEditorComponent();
|
||||||
let editor = editorComponent.editor;
|
let editor = editorComponent.editor;
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ export class EditorsComponent {
|
|||||||
case "show-about":
|
case "show-about":
|
||||||
break;
|
break;
|
||||||
case "quit":
|
case "quit":
|
||||||
window.main.quit();
|
window?.main.quit();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
editor.execCommand(action);
|
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++) {
|
for (let i = 0; i < paths.length; i++) {
|
||||||
let file = new File([], "") as NewtonFile;
|
let file = new File([], "") as NewtonFile;
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ export class EditorsComponent {
|
|||||||
this.editorsService.setSession(file);
|
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);
|
let file = this.filesService.get(path);
|
||||||
file.session.setValue(data);
|
file.session.setValue(data);
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ export class EditorsComponent {
|
|||||||
this.tabsService.sendMessage(message);
|
this.tabsService.sendMessage(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.fs.onDeletedFile(async (path: string) => {
|
window?.fs.onDeletedFile(async (path: string) => {
|
||||||
let message = new ServiceMessage();
|
let message = new ServiceMessage();
|
||||||
message.action = "file-deleted";
|
message.action = "file-deleted";
|
||||||
message.filePath = path;
|
message.filePath = path;
|
||||||
@@ -156,7 +156,7 @@ export class EditorsComponent {
|
|||||||
this.filesService.sendMessage(message);
|
this.filesService.sendMessage(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.fs.onSavedFile(async (path: string) => {
|
window?.fs.onSavedFile(async (path: string) => {
|
||||||
let message = new ServiceMessage();
|
let message = new ServiceMessage();
|
||||||
message.action = "file-saved";
|
message.action = "file-saved";
|
||||||
message.filePath = path;
|
message.filePath = path;
|
||||||
@@ -164,7 +164,7 @@ export class EditorsComponent {
|
|||||||
this.tabsService.sendMessage(message);
|
this.tabsService.sendMessage(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.fs.onUpdateFilePath(async (path: string) => {
|
window?.fs.onUpdateFilePath(async (path: string) => {
|
||||||
console.log("TODO (onUpdateFilePath) :", path);
|
console.log("TODO (onUpdateFilePath) :", path);
|
||||||
// this.tabsService.sendMessage(message);
|
// this.tabsService.sendMessage(message);
|
||||||
// this.filesService.sendMessage(message);
|
// this.filesService.sendMessage(message);
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ export class LspManagerComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public setWorkspaceFolder() {
|
public setWorkspaceFolder() {
|
||||||
window.fs.chooseFolder().then((folder: string) => {
|
window?.fs.chooseFolder().then((folder: string) => {
|
||||||
if (!folder) return;
|
if (!folder) return;
|
||||||
|
|
||||||
this.lspManagerService.workspaceFolder = folder;
|
this.lspManagerService.workspaceFolder = folder;
|
||||||
|
|||||||
@@ -11,33 +11,35 @@
|
|||||||
import 'zone.js'; // Included with Angular CLI.
|
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 {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
electron: {
|
electron: {
|
||||||
node: () => Promise<string>,
|
node: any,
|
||||||
chrome: () => Promise<string>,
|
chrome: any,
|
||||||
electron: () => Promise<string>,
|
electron: any,
|
||||||
},
|
},
|
||||||
main: {
|
main: {
|
||||||
onMenuActions: (arg0: any) => Promise<string>,
|
onMenuActions: any,
|
||||||
onTerminalActions: (arg0: any) => Promise<string>,
|
onTerminalActions: any,
|
||||||
quit: any,
|
quit: any,
|
||||||
toggleFullScreen: any,
|
toggleFullScreen: any,
|
||||||
},
|
},
|
||||||
fs: {
|
fs: {
|
||||||
getLspConfigData: () => Promise<string>,
|
getLspConfigData: any,
|
||||||
getFileContents: (arg0: any) => Promise<string>,
|
getFileContents: any,
|
||||||
openFiles: (arg0) => Promise<string>,
|
openFiles: any,
|
||||||
saveFile: (arg0: any, arg1: any) => Promise<string>,
|
saveFile: any,
|
||||||
saveFileAs: () => Promise<string>,
|
saveFileAs: any,
|
||||||
chooseFolder: () => Promise<string>,
|
chooseFolder: any,
|
||||||
closeFile: (arg0: any) => Promise<string>,
|
closeFile: any,
|
||||||
getPathForFile: any,
|
getPathForFile: any,
|
||||||
onLoadFiles: (arg0: any) => Promise<string>,
|
onLoadFiles: any,
|
||||||
onUpdateFilePath: (arg0: any) => Promise<string>,
|
onUpdateFilePath: any,
|
||||||
onSavedFile: (arg0: any) => Promise<string>,
|
onSavedFile: any,
|
||||||
onChangedFile: (arg0: any) => Promise<string>,
|
onChangedFile: any,
|
||||||
onDeletedFile: (arg0: any) => Promise<string>,
|
onDeletedFile: any,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user