Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/split more libs #558

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 34 additions & 36 deletions electron-shell.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as electron from 'electron';
import { app, BrowserWindow, dialog, ipcMain, Menu, MessageBoxSyncOptions, nativeImage, shell, Tray } from 'electron';
import * as os from 'os';
import {app, BrowserWindow, dialog, ipcMain, Menu, MessageBoxSyncOptions, nativeImage, shell, Tray} from 'electron';
import * as path from 'path';
import {join} from 'path';
import {NEW_CONFIG_PATH} from "./server/path.utils";
import {bootstrapTsED} from "./server/server.bootstrap";
import {getAppRootPath, getElectronPath, isInElectron} from "./server/file.utilts";
import { join } from 'path';
import { NEW_CONFIG_PATH } from "@memebox/server-common";
import { bootstrapTsED } from "./server/server.bootstrap";
import { getAppRootPath, getElectronPath, isInElectron } from "./server/file.utilts";

// TODO Refactor / Abstract the electron usages

Expand Down Expand Up @@ -42,14 +42,14 @@ const openExternalLinksInOSBrowser = (event, url) => {
const addPresentationIcons = (
target: electron.NativeImage,
source: electron.NativeImage,
baseSize: number,
baseSize: number
): void => {
[1, 1.25, 1.5, 2, 3].forEach(scale => {
target.addRepresentation({
scaleFactor: scale,
width: baseSize * scale,
height: baseSize * scale,
buffer: source.resize({ width: baseSize * scale, height: baseSize * scale }).toBitmap(),
buffer: source.resize({width: baseSize * scale, height: baseSize * scale}).toBitmap()
});
});
};
Expand Down Expand Up @@ -77,11 +77,10 @@ const createTrayIcon = (appRootPath: string): electron.NativeImage => {
};

var initPath = path.join(NEW_CONFIG_PATH, "init.json");
var data = { bounds: { width: 800, height: 600 }};
var data = {bounds: {width: 800, height: 600}};
try {
data = JSON.parse(fs.readFileSync(initPath, 'utf8'));
}
catch(e) {
} catch (e) {
}

let alreadyAllowedToBeHidden = false;
Expand All @@ -91,8 +90,8 @@ let tray;
* Create the application's tray icon in the system menu bar, setting up the platform dependent icon
* as well as menu items and further tray information.
*/
function createTray () {
function toggle () {
function createTray() {
function toggle() {
if (win !== null) {
win.close();
} else {
Expand Down Expand Up @@ -126,7 +125,7 @@ function createTray () {
var trayMenu = Menu.buildFromTemplate(template);
tray.setContextMenu(trayMenu);
tray.setToolTip('Meme-Box');
tray.addListener('double-click', (event: KeyboardEvent) => {
tray.addListener('double-click', (event: KeyboardEvent) => {
alreadyAllowedToBeHidden = true;
toggle();
});
Expand All @@ -137,7 +136,7 @@ function createWindow(): BrowserWindow {

const electronPath = getElectronPath();

console.info({ isInElectron, __dirname });
console.info({isInElectron, __dirname});

// Create the browser window.
win = new BrowserWindow({
Expand All @@ -148,8 +147,8 @@ function createWindow(): BrowserWindow {
// protect against prototype pollution
contextIsolation: true,
// Preload script
preload: path.join(electronPath, 'preload.js'),
},
preload: path.join(electronPath, 'preload.js')
}
});

portPromise.then((port) => {
Expand All @@ -162,35 +161,35 @@ function createWindow(): BrowserWindow {
});
win.loadURL(`http://localhost:4200?port=${port}`);
} else {
win.loadURL( `http://localhost:${port}`);
win.loadURL(`http://localhost:${port}`);
}
});

win.on("close", function(e) {
win.on("close", function (e) {
var data = {
bounds: win.getBounds()
};
fs.writeFileSync(initPath, JSON.stringify(data));

// ask it hide or close if its triggered from the Electron Window
if (!alreadyAllowedToBeHidden) {
const result = dialog.showMessageBoxSync(win, {
message: 'Hide to tray or quit?',
buttons: [
'To Tray',
'Quit Meme-Box'
]
} as MessageBoxSyncOptions);

if (result === 0) {
// do nothing :)
alreadyAllowedToBeHidden = true;
}
if (!alreadyAllowedToBeHidden) {
const result = dialog.showMessageBoxSync(win, {
message: 'Hide to tray or quit?',
buttons: [
'To Tray',
'Quit Meme-Box'
]
} as MessageBoxSyncOptions);

if (result === 0) {
// do nothing :)
alreadyAllowedToBeHidden = true;
}

if (result === 1) {
app.quit();
if (result === 1) {
app.quit();
}
}
}
});

const ipcSelectDirEvent = async (event) => {
Expand All @@ -199,7 +198,7 @@ function createWindow(): BrowserWindow {
})
console.log('directories selected', result.filePaths);

const arg = result.filePaths?.[0] ?? '';
const arg = result.filePaths?.[0] ?? '';

event.sender.send('dir-selected', arg);
};
Expand All @@ -224,7 +223,6 @@ function createWindow(): BrowserWindow {
}



try {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
Expand Down
95 changes: 76 additions & 19 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,51 @@
"default": {
"runner": "@nrwl/workspace/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "test", "lint", "package", "prepare"]
"cacheableOperations": [
"build",
"test",
"lint",
"package",
"prepare"
]
}
}
},
"targetDependencies": {
"prepare": [{ "target": "prepare", "projects": "dependencies" }],
"package": [{ "target": "package", "projects": "dependencies" }]
"prepare": [
{
"target": "prepare",
"projects": "dependencies"
}
],
"package": [
{
"target": "package",
"projects": "dependencies"
}
]
},
"affected": {
"defaultBase": "develop"
},
"workspaceLayout": {
"libsDir": "projects",
"appsDir": "projects"
},
"cli": {
"analytics": false,
"defaultCollection": "@nrwl/angular"
},
"affected": { "defaultBase": "develop" },
"workspaceLayout": { "libsDir": "projects", "appsDir": "projects" },
"cli": { "analytics": false, "defaultCollection": "@nrwl/angular" },
"generators": {
"@schematics/angular:component": {
"prefix": "app",
"style": "scss",
"skipTests": true
},
"@schematics/angular:directive": { "prefix": "app", "skipTests": true },
"@schematics/angular:directive": {
"prefix": "app",
"skipTests": true
},
"@nrwl/angular:application": {
"linter": "eslint",
"unitTestRunner": "jest"
Expand All @@ -37,17 +64,47 @@
},
"defaultProject": "memebox-app",
"projects": {
"action-variables": { "tags": [] },
"action-variables-ui": { "tags": [] },
"app-state": { "tags": [] },
"contracts": { "tags": [] },
"memebox-app": { "tags": [] },
"server": { "tags": [] },
"shared-state": { "tags": [] },
"state-components": { "tags": [] },
"ui-components": { "tags": [] },
"utils": { "tags": [] },
"recipe-core": { "tags": [] },
"recipe-ui": { "tags": [] }
"action-variables": {
"tags": []
},
"action-variables-ui": {
"tags": []
},
"app-state": {
"tags": []
},
"contracts": {
"tags": []
},
"memebox-app": {
"tags": []
},
"server": {
"tags": []
},
"shared-state": {
"tags": []
},
"state-components": {
"tags": []
},
"ui-components": {
"tags": []
},
"utils": {
"tags": []
},
"recipe-core": {
"tags": []
},
"recipe-ui": {
"tags": []
},
"server-common": {
"tags": []
},
"twitch-api": {
"tags": []
}
}
}
37 changes: 15 additions & 22 deletions projects/app-state/src/lib/services/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import {Injectable} from '@angular/core';
import {AppStore} from '../state/app.store';
import {HttpClient} from '@angular/common/http';
import {
Config,
ENDPOINTS,
ObsConfig,
TwitchAuthInformation,
TwitchConfig,
TwitchConnectionType
} from '@memebox/contracts';
import {DANGER_CLEAN_CONFIG_ENDPOINT, DANGER_IMPORT_ALL_ENDPOINT} from '../../../../../server/constants';
import {setDummyData} from '../state/app.dummy.data';
import {MemeboxWebsocketService} from "./memebox-websocket.service";
import {AppService} from "../state/app.service";
import {SnackbarService} from "./snackbar.service";
import {EXPRESS_BASE, MemeboxApiService} from "../state/memeboxApi.service";
import {ConnectionStateService} from "../state/connection-state.service";
import { Injectable } from '@angular/core';
import { AppStore } from '../state/app.store';
import { HttpClient } from '@angular/common/http';
import { Config, ENDPOINTS, ObsConfig, TwitchConfig, TwitchConnectionType } from '@memebox/contracts';
import { DANGER_CLEAN_CONFIG_ENDPOINT, DANGER_IMPORT_ALL_ENDPOINT } from '@memebox/server-common';
import { setDummyData } from '../state/app.dummy.data';
import { MemeboxWebsocketService } from "./memebox-websocket.service";
import { AppService } from "../state/app.service";
import { SnackbarService } from "./snackbar.service";
import { EXPRESS_BASE, MemeboxApiService } from "../state/memeboxApi.service";
import { ConnectionStateService } from "../state/connection-state.service";
import { TwitchAuthInformation } from "@memebox/twitch-api";

const NOT_POSSIBLE_OFFLINE = 'Not possible in Offline-Mode.';

Expand All @@ -35,7 +29,7 @@ export class ConfigService {

public async updateConfig(newConfig: Partial<Config>) {
// update path & await
await this.memeboxApi.put( this.configEndpoint(''), newConfig);
await this.memeboxApi.put(this.configEndpoint(''), newConfig);

// update state
this.appStore.update(state => {
Expand All @@ -49,7 +43,7 @@ export class ConfigService {
};

// update path & await
await this.memeboxApi.put( this.configEndpoint(ENDPOINTS.CONFIG.CUSTOM_PORT), newConfig);
await this.memeboxApi.put(this.configEndpoint(ENDPOINTS.CONFIG.CUSTOM_PORT), newConfig);

// add to the state
this.appStore.update(state => {
Expand Down Expand Up @@ -113,7 +107,6 @@ export class ConfigService {
}



public async openMediaFolder() {
if (this.connectionStateService.isOffline()) {
this.snackbar.sorry(NOT_POSSIBLE_OFFLINE);
Expand Down Expand Up @@ -159,7 +152,7 @@ export class ConfigService {
}


public loadTwitchAuthInformations(): Promise<TwitchAuthInformation[]|undefined> {
public loadTwitchAuthInformations(): Promise<TwitchAuthInformation[] | undefined> {
return this.memeboxApi.get<TwitchAuthInformation[]>(`${ENDPOINTS.TWITCH_DATA.PREFIX}${ENDPOINTS.TWITCH_DATA.AUTH_INFORMATIONS}`);
}

Expand Down
Loading