Merge pull request #2371 from yougotwill/debug_log_window_updates

Debug Log Window updates
pull/2376/head
Audric Ackermann 3 years ago committed by GitHub
commit e8ddeafa3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,6 +15,11 @@
style-src 'self' 'unsafe-inline';" style-src 'self' 'unsafe-inline';"
/> />
<link href="dist/manifest.css" rel="stylesheet" type="text/css" /> <link href="dist/manifest.css" rel="stylesheet" type="text/css" />
<style>
body {
background-color: #000;
}
</style>
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>

@ -1,72 +0,0 @@
.debug-log {
&.modal {
padding: 50px;
.content {
margin: 0;
max-width: 100%;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
textarea {
flex-grow: 1;
width: 100%;
resize: none;
min-height: 100px;
font-family: Monaco, Consolas, 'Courier New', Courier, monospace;
font-size: 12px;
}
}
}
.result {
$link-max-width: 400px;
$open-width: 72px;
$open-height: 36px;
text-align: center;
$group-max-width: $link-max-width + $open-width;
.input-group {
display: inline-block;
width: 100%;
max-width: $group-max-width;
}
$open-pad-x: calc(($open-width - $button-height - 2px) / 2);
$open-pad-y: calc(($open-height - $button-height - 2px) / 2);
.open {
float: left;
display: inline-block;
width: $open-width;
height: $open-height;
padding: $open-pad-y $open-pad-x;
cursor: pointer;
border: solid 1px #ccc;
border-radius: 0 $border-radius $border-radius 0;
background: $grey_l;
&:before {
content: '';
display: block;
width: $button-height;
height: $button-height;
@include header-icon-black('../images/open_link.svg');
}
}
.link {
border-radius: $border-radius 0 0 $border-radius;
float: left;
width: calc(100% - #{$open-width});
max-width: $link-max-width;
height: $open-height;
padding: 0 10px;
outline-offset: -4px;
border: solid 1px #ccc;
border-right: none;
}
}
}

@ -39,9 +39,9 @@ textarea {
input, input,
textarea { textarea {
user-select: text; user-select: text;
a { a {
word-break: break-all; word-break: break-all;
} }
} }
} }

@ -16,7 +16,6 @@
// Components // Components
@import 'modal'; @import 'modal';
@import 'debugLog';
@import 'lightbox'; @import 'lightbox';
@import 'emoji'; @import 'emoji';
@import 'mentions'; @import 'mentions';

@ -1,12 +1,45 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import {
SessionTheme,
switchHtmlToDarkTheme,
switchHtmlToLightTheme,
} from '../state/ducks/SessionTheme';
import { fetch } from '../util/logging'; import { fetch } from '../util/logging';
import { SessionButton } from './basic/SessionButton';
const StyledContent = styled.div` const StyledContent = styled.div`
background-color: var(--color-modal-background);
color: var(--color-text);
font-family: var(--font-default);
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 10px; padding: 20px;
height: 100%; height: 100%;
.session-button {
margin: 1em auto 1em 0;
padding: 1em;
width: fit-content;
}
h1 {
color: var(--color-text);
}
textarea {
flex-grow: 1;
width: 100%;
box-sizing: border-box;
padding: var(--margins-sm);
border: 2px solid var(--color-session-border);
resize: none;
min-height: 100px;
font-family: Monaco, Consolas, 'Courier New', Courier, monospace;
font-size: 12px;
}
`; `;
const DebugLogTextArea = (props: { content: string }) => { const DebugLogTextArea = (props: { content: string }) => {
@ -18,21 +51,16 @@ const DebugLogTextArea = (props: { content: string }) => {
const DebugLogButtons = (props: { content: string }) => { const DebugLogButtons = (props: { content: string }) => {
return ( return (
<div className="buttons"> <div className="buttons">
<button <SessionButton
className="grey submit" text={window.i18n('saveLogToDesktop')}
onClick={e => { onClick={() => {
e.preventDefault();
if (props.content.length <= 20) { if (props.content.length <= 20) {
// loading // loading
return; return;
} }
(window as any).saveLog(props.content); (window as any).saveLog(props.content);
(window as any).closeDebugLog();
}} }}
> />
{window.i18n('saveLogToDesktop')}
</button>
</div> </div>
); );
}; };
@ -65,20 +93,30 @@ const DebugLogViewAndSave = () => {
}; };
export const DebugLogView = () => { export const DebugLogView = () => {
useEffect(() => {
if ((window as any).theme === 'dark') {
switchHtmlToDarkTheme();
} else {
switchHtmlToLightTheme();
}
}, []);
return ( return (
<StyledContent> <SessionTheme>
<div> <StyledContent>
<button <div>
className="x close" <button
aria-label="close debug log" className="x close"
onClick={() => { aria-label="close debug log"
(window as any).closeDebugLog(); onClick={() => {
}} (window as any).closeDebugLog();
/> }}
<h1> {window.i18n('debugLog')} </h1> />
<p> {window.i18n('debugLogExplanation')}</p> <h1> {window.i18n('debugLog')} </h1>
</div> <p> {window.i18n('debugLogExplanation')}</p>
<DebugLogViewAndSave /> </div>
</StyledContent> <DebugLogViewAndSave />
</StyledContent>
</SessionTheme>
); );
}; };

@ -3,6 +3,7 @@
import { import {
app, app,
BrowserWindow, BrowserWindow,
dialog,
ipcMain as ipc, ipcMain as ipc,
Menu, Menu,
protocol as electronProtocol, protocol as electronProtocol,
@ -645,6 +646,7 @@ async function showDebugLogWindow() {
title: locale.messages.debugLog, title: locale.messages.debugLog,
autoHideMenuBar: true, autoHideMenuBar: true,
backgroundColor: '#000', backgroundColor: '#000',
shadow: true,
show: false, show: false,
modal: true, modal: true,
webPreferences: { webPreferences: {
@ -668,10 +670,37 @@ async function showDebugLogWindow() {
}); });
debugLogWindow.once('ready-to-show', () => { debugLogWindow.once('ready-to-show', () => {
debugLogWindow?.setBackgroundColor('#000');
debugLogWindow?.show(); debugLogWindow?.show();
}); });
} }
async function saveDebugLog(_event: any, logText: any) {
const options: Electron.SaveDialogOptions = {
title: 'Save debug log',
defaultPath: path.join(app.getPath('desktop'), `session_debug_${Date.now()}.txt`),
properties: ['createDirectory'],
};
try {
const result = await dialog.showSaveDialog(options);
const outputPath = result.filePath;
console.info(`Trying to save logs to ${outputPath}`);
if (result === undefined || outputPath === undefined || outputPath === '') {
throw Error("User clicked Save button but didn't create a file");
}
// tslint:disable: non-literal-fs-path
fs.writeFile(outputPath, logText, err => {
if (err) {
throw Error(`${err}`);
}
console.info(`Saved log - ${outputPath}`);
});
} catch (err) {
console.error('Error saving debug log', err);
}
}
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
@ -1020,20 +1049,7 @@ ipc.on('close-debug-log', () => {
debugLogWindow.close(); debugLogWindow.close();
} }
}); });
ipc.on('save-debug-log', (_event, logText) => { ipc.on('save-debug-log', saveDebugLog);
const osSpecificDesktopFolder = app.getPath('desktop');
console.info(`Trying to save logs to log Desktop ${osSpecificDesktopFolder}`);
const outputPath = path.join(osSpecificDesktopFolder, `session_debug_${Date.now()}.log`);
// tslint:disable: non-literal-fs-path
fs.writeFile(outputPath, logText, err => {
if (err) {
console.error(`Error saving debug log to ${outputPath}`);
return;
}
console.info(`Saved log - ${outputPath}`);
});
});
// This should be called with an ipc sendSync // This should be called with an ipc sendSync
ipc.on('get-media-permissions', event => { ipc.on('get-media-permissions', event => {

Loading…
Cancel
Save