Compare commits

..

2 Commits

13 changed files with 144 additions and 91 deletions

View File

@@ -48,7 +48,6 @@
"src/assets/css/ace-overrides.css" "src/assets/css/ace-overrides.css"
], ],
"scripts":[ "scripts":[
"src/libs/showdown.min.js"
], ],
"optimization": true "optimization": true
}, },

View File

@@ -13,14 +13,14 @@
"electron-start": "electron . --trace-warnings --start-as=build --ipc-port=4588", "electron-start": "electron . --trace-warnings --start-as=build --ipc-port=4588",
"electron-pack": "ng build --base-href ./ && electron-builder --dir", "electron-pack": "ng build --base-href ./ && electron-builder --dir",
"electron-dist": "ng build --base-href ./ && electron-builder", "electron-dist": "ng build --base-href ./ && electron-builder",
"electron-dist-appimage-linux": "ng build --base-href ./ && electron-builder --linux AppImage",
"electron-dist-deb-linux": "ng build --base-href ./ && electron-builder --linux deb",
"electron-dist-zip-linux": "ng build --base-href ./ && electron-builder --linux zip", "electron-dist-zip-linux": "ng build --base-href ./ && electron-builder --linux zip",
"electron-dist-deb-linux": "ng build --base-href ./ && electron-builder --linux deb",
"electron-dist-appimage-linux": "ng build --base-href ./ && electron-builder --linux AppImage",
"electron-dist-all-linux": "ng build --base-href ./ && electron-builder --linux deb zip AppImage", "electron-dist-all-linux": "ng build --base-href ./ && electron-builder --linux deb zip AppImage",
"electron-dist-all": "ng build --base-href ./ && electron-builder -mwl", "electron-dist-all": "ng build --base-href ./ && electron-builder -mwl",
"electron-concurrently": "concurrently 'ng serve' 'electron . --trace-warnings --start-as=ng-serve'", "electron-concurrently": "concurrently 'ng serve' 'electron . --trace-warnings --start-as=ng-serve'",
"ng-serve": "ng serve", "ng-serve": "ng serve",
"ng-build": "ng build", "ng-build": "ng build --base-href ./",
"ng-watch-build": "ng build --watch --configuration development", "ng-watch-build": "ng build --watch --configuration development",
"ng-test": "ng test", "ng-test": "ng test",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"

View File

@@ -1,4 +1,6 @@
import { Component } from '@angular/core'; import { Component, inject } from '@angular/core';
import { WebsocketService } from './common/services/websocket.service';
import { InfoBarComponent } from './editor/info-bar/info-bar.component'; import { InfoBarComponent } from './editor/info-bar/info-bar.component';
import { TabsComponent } from './editor/tabs/tabs.component'; import { TabsComponent } from './editor/tabs/tabs.component';
@@ -28,6 +30,69 @@ import { LspManagerComponent } from "./editor/lsp-manager/lsp-manager.component"
export class AppComponent { export class AppComponent {
title = 'Newton'; title = 'Newton';
constructor() {} protected ws: WebsocketService = inject(WebsocketService);
constructor() {
this.checkIfNotElectronMode();
}
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> { private getLspConfigData(): Promise<string> {
return window.fs.getLspConfigData(); return window?.fs.getLspConfigData();
} }
private parseAndReturnLSPConfigData(): {} { private parseAndReturnLSPConfigData(): {} {

View File

@@ -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;

View File

@@ -0,0 +1,35 @@
import { Injectable } from '@angular/core';
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class WebsocketService {
private socket$!: WebSocketSubject<any>;
connect(url: string): Observable<any> {
if (!this.socket$ || this.socket$.closed) {
this.socket$ = webSocket(
{
url,
deserializer: msg => msg.data
}
);
}
return this.socket$.asObservable();
}
send(message: any) {
if (this.socket$) {
this.socket$.next(message);
}
}
close() {
if (this.socket$) {
this.socket$.complete();
}
}
}

View File

@@ -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();
} }
} }

View File

@@ -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);

View File

@@ -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;

File diff suppressed because one or more lines are too long

View File

@@ -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,
} }
} }
} }

1
src/typings.d.ts vendored
View File

@@ -1 +0,0 @@
// declare var showdown: any;

View File

@@ -16,50 +16,6 @@
"declaration": false, "declaration": false,
"skipLibCheck": true, "skipLibCheck": true,
"strict": false, "strict": false,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true
},
"includes": [
"src/typings.d.ts"
]
} }
/*
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./build/app",
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"esModuleInterop": true,
"sourceMap": true,
"declaration": false,
"experimentalDecorators": true,
"moduleResolution": "bundler",
"importHelpers": true,
"target": "ES2022",
"module": "ES2022",
"useDefineForClassFields": false,
"lib": [
"ES2022",
"dom"
]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
},
"includes": [
"src/typings.d.ts"
]
} }
*/