From 160c6d83db34b07babc9a289f82c495cded404a6 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 30 Jun 2019 17:24:10 +0200 Subject: [PATCH] Udated a lot of stuff --- github | 2 +- modules/core/app-updater/index.ts | 5 +- modules/core/main_window.ts | 19 +- modules/core/teaspeak-forum/index.ts | 6 +- modules/core/ui-loader/graphical.ts | 62 +++--- modules/core/ui-loader/ui/loading_screen.html | 18 ++ modules/core/url-preview/index.ts | 24 ++- modules/core/window.ts | 109 +++++++++++ modules/renderer/context-menu.ts | 181 ++++++++++++++++++ modules/renderer/index.ts | 27 +++ modules/shared/process-arguments/index.ts | 1 + native/CMakeLists.txt | 2 +- .../src/audio/AudioOutput.cpp | 4 +- .../src/audio/AudioResampler.cpp | 2 +- .../src/audio/codec/Converter.h | 3 + .../src/audio/codec/OpusConverter.cpp | 95 +++++++-- .../src/audio/codec/OpusConverter.h | 10 + .../src/connection/ServerConnection.cpp | 2 - .../src/connection/audio/AudioSender.cpp | 76 ++++++-- .../src/connection/audio/AudioSender.h | 6 +- .../src/connection/audio/VoiceClient.cpp | 45 +++-- .../src/connection/audio/VoiceClient.h | 5 +- .../src/connection/audio/VoiceConnection.cpp | 6 +- native/serverconnection/test/js/flood.ts | 66 +------ package.json | 42 ++-- 25 files changed, 642 insertions(+), 176 deletions(-) create mode 100644 modules/core/window.ts create mode 100644 modules/renderer/context-menu.ts diff --git a/github b/github index 0866874..06391c6 160000 --- a/github +++ b/github @@ -1 +1 @@ -Subproject commit 0866874725f393c2804f2926687ea3d858d88653 +Subproject commit 06391c6cdd772c2f83c1387960f7224f7cd9f514 diff --git a/modules/core/app-updater/index.ts b/modules/core/app-updater/index.ts index ac3d6fe..d398413 100644 --- a/modules/core/app-updater/index.ts +++ b/modules/core/app-updater/index.ts @@ -22,6 +22,7 @@ import {PassThrough} from "stream"; import {prevent_instant_close} from "../../core/main_window"; import ErrnoException = NodeJS.ErrnoException; import {EPERM} from "constants"; +import * as winmgr from "../window"; const is_debug = false; export function server_url() : string { @@ -684,6 +685,8 @@ export async function execute_graphical(channel: string, ask_install: boolean) : } await new Promise(resolve => window.on('ready-to-show', resolve)); window.show(); + await winmgr.apply_bounds('update-installer', window); + winmgr.track_bounds('update-installer', window); const current_vers = await current_version(); console.log("Current version: " + current_vers.toString(true)); @@ -824,7 +827,7 @@ async function check_update(channel: string) { update_question_open = true; dialog.showMessageBox({ buttons: ["update now", "remind me later"], - title: "Update available", + title: "TeaClient: Update available", message: "There is an update available!\n" + "Should we update now?\n" + diff --git a/modules/core/main_window.ts b/modules/core/main_window.ts index 7ff1681..0c0f1ec 100644 --- a/modules/core/main_window.ts +++ b/modules/core/main_window.ts @@ -1,5 +1,7 @@ import {BrowserWindow, Menu, MenuItem, MessageBoxOptions, app, dialog} from "electron"; import * as electron from "electron"; +import * as winmgr from "./window"; + export let prevent_instant_close: boolean = true; export let is_debug: boolean; export let allow_dev_tools: boolean; @@ -102,7 +104,8 @@ function spawn_main_window(entry_point: string) { show: false, webPreferences: { webSecurity: false, - nodeIntegrationInWorker: true + nodeIntegrationInWorker: true, + nodeIntegration: true }, }); @@ -124,11 +127,15 @@ function spawn_main_window(entry_point: string) { main_window.once('ready-to-show', () => { main_window.show(); - main_window.focus(); - loader.ui.cleanup(); - if(allow_dev_tools && !main_window.webContents.isDevToolsOpened()) - main_window.webContents.openDevTools(); - prevent_instant_close = false; /* just to ensure that the client could be unloaded */ + winmgr.apply_bounds('main-window', main_window).then(() => { + winmgr.track_bounds('main-window', main_window); + + main_window.focus(); + loader.ui.cleanup(); + if(allow_dev_tools && !main_window.webContents.isDevToolsOpened()) + main_window.webContents.openDevTools(); + prevent_instant_close = false; /* just to ensure that the client could be unloaded */ + }); }); main_window.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => { diff --git a/modules/core/teaspeak-forum/index.ts b/modules/core/teaspeak-forum/index.ts index 18bccc6..ad12236 100644 --- a/modules/core/teaspeak-forum/index.ts +++ b/modules/core/teaspeak-forum/index.ts @@ -6,6 +6,7 @@ import {BrowserWindow, ipcMain as ipc} from "electron"; import {Arguments, process_args} from "../../shared/process-arguments"; import UserData = forum.UserData; import {main_window} from "../main_window"; +import * as winmgr from "../window"; let current_window: BrowserWindow; let _current_data: UserData; @@ -64,10 +65,13 @@ export function open_login(enforce: boolean = false) : Promise { show: true, parent: main_window, webPreferences: { - webSecurity: false + webSecurity: false, + nodeIntegration: true }, }); current_window.setMenu(null); + winmgr.apply_bounds('forum-manager', current_window); + winmgr.track_bounds('forum-manager', current_window); console.log("Main: " + main_window); current_window.loadFile(path.join(path.dirname(module.filename), "ui", "index.html")); diff --git a/modules/core/ui-loader/graphical.ts b/modules/core/ui-loader/graphical.ts index ea2147a..58bf834 100644 --- a/modules/core/ui-loader/graphical.ts +++ b/modules/core/ui-loader/graphical.ts @@ -5,6 +5,8 @@ import {screen} from "electron"; import {Arguments, process_args} from "../../shared/process-arguments"; import * as loader from "./loader"; import * as updater from "../app-updater"; +import * as winmgr from "../window"; +import {main_window} from "../main_window"; export namespace ui { let gui: electron.BrowserWindow; @@ -26,11 +28,12 @@ export namespace ui { export function cleanup() { if(gui) { + promise = undefined; + resolve = undefined; + gui.destroy(); gui = undefined; - promise = undefined; - resolve = undefined; reject = error => { if(error) console.error("Received error from loader after it had been closed... Error: %o", error); @@ -71,47 +74,56 @@ export namespace ui { gui.webContents.send('await-update'); } - function spawn_gui(close_callback: () => any) { + function spawn_gui() { console.log("Spawn window!"); - - const WINDOW_WIDTH = 340; - const WINDOW_HEIGHT = 400; - - let bounds = screen.getPrimaryDisplay().bounds; - let x = (bounds.width - WINDOW_WIDTH) / 2; - let y = (bounds.height - WINDOW_HEIGHT) / 2; - let dev_tools = false; + const WINDOW_WIDTH = 340 + (dev_tools ? 1000 : 0); + const WINDOW_HEIGHT = 400 + (process.platform == "win32" ? 40 : 0); + + let bounds = screen.getPrimaryDisplay().bounds; + let x = bounds.x + (bounds.width - WINDOW_WIDTH) / 2; + let y = bounds.y + (bounds.height - WINDOW_HEIGHT) / 2; + console.log("Bounds: %o; Move loader window to %ox%o", bounds, x, y); + gui = new electron.BrowserWindow({ - width: dev_tools ? WINDOW_WIDTH + 1000 : WINDOW_WIDTH, - height: WINDOW_HEIGHT + (process.platform == "win32" ? 40 : 0), - frame: true, + width: WINDOW_WIDTH, + height: WINDOW_HEIGHT, + frame: dev_tools, resizable: dev_tools, show: false, autoHideMenuBar: true, - //frame: false, webPreferences: { webSecurity: false, - nodeIntegrationInWorker: true + nodeIntegrationInWorker: false, + nodeIntegration: true } }); gui.setMenu(null); gui.loadFile(path.join(path.dirname(module.filename), "ui", "loading_screen.html")); - gui.on('closed', close_callback); + gui.on('closed', () => { + if(resolve) + resolve(); + gui = undefined; + cleanup(); + }); gui.on('ready-to-show', () => { gui.show(); + gui.setPosition(x, y); + winmgr.apply_bounds('ui-load-window', gui, undefined, { apply_size: false }).then(() => { + winmgr.track_bounds('ui-load-window', gui); - const call_loader = () => load_files().catch(reject); - if(!process_args.has_flag(...Arguments.DISABLE_ANIMATION)) - setTimeout(call_loader, 1000); - else - setImmediate(call_loader); + const call_loader = () => load_files().catch(reject); + if(!process_args.has_flag(...Arguments.DISABLE_ANIMATION)) + setTimeout(call_loader, 1000); + else + setImmediate(call_loader); - if(dev_tools) - gui.webContents.openDevTools(); + if(dev_tools) + gui.webContents.openDevTools(); + }); }); } @@ -123,7 +135,7 @@ export namespace ui { console.error("Failed to load UI files! Error: %o", error) }); - spawn_gui(() => reject(undefined)); + spawn_gui(); }); } diff --git a/modules/core/ui-loader/ui/loading_screen.html b/modules/core/ui-loader/ui/loading_screen.html index 8a055ab..7ab97ca 100644 --- a/modules/core/ui-loader/ui/loading_screen.html +++ b/modules/core/ui-loader/ui/loading_screen.html @@ -7,10 +7,27 @@