From c493ce1d8e47f4b5fa5f1a3cec0e1e31018c0cc7 Mon Sep 17 00:00:00 2001 From: Jean Ribeiro Date: Thu, 16 May 2024 17:27:07 -0300 Subject: [PATCH 1/2] feat: adds restrictive content security policies --- packages/desktop/public/about.html | 22 ++++++++++++++++++++++ packages/desktop/public/error.html | 21 +++++++++++++++++++++ packages/desktop/public/index.html | 21 +++++++++++++++------ 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/packages/desktop/public/about.html b/packages/desktop/public/about.html index 8a9fa0475f..6bb9072408 100644 --- a/packages/desktop/public/about.html +++ b/packages/desktop/public/about.html @@ -6,6 +6,28 @@ name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> + + App icon

- - - - - + diff --git a/packages/desktop/public/about.js b/packages/desktop/public/about.js new file mode 100644 index 0000000000..206d65eaa9 --- /dev/null +++ b/packages/desktop/public/about.js @@ -0,0 +1,9 @@ +// https://github.com/electron/electron/issues/2863 +var exports = exports || {} + +window.about.getData().then((aboutData) => { + document.getElementById('title').textContent = aboutData.appName + document.getElementById('app-icon').src = aboutData.iconPath + document.getElementById('app-version').textContent = aboutData.version + document.getElementById('footer').textContent = `Bloom Labs Ltd. ${new Date().getFullYear()}` +}) diff --git a/packages/desktop/public/error.css b/packages/desktop/public/error.css new file mode 100644 index 0000000000..faf6c30129 --- /dev/null +++ b/packages/desktop/public/error.css @@ -0,0 +1,111 @@ +@font-face { + font-family: 'Silka'; + font-style: normal; + font-weight: 500; + font-display: swap; + src: url('./assets/fonts/silka/silka-medium-webfont.woff2') format('woff2'); +} + +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body, +html { + width: 100%; + height: 100%; + user-select: none; + -webkit-user-drag: none; + overflow: hidden; +} + +body { + display: flex; + justify-content: stretch; + color: #ffffff; + background-color: #161926; + font-size: 11px; + font-family: 'Silka'; +} + +a { + color: #b196ef; +} + +hr { + width: 100%; + border: 0; + border-top: 1px solid #212537; + margin: 1.5rem 0; +} + +button { + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + border: 0px solid rgb(150, 108, 230); + box-sizing: border-box; + cursor: pointer; + border-radius: 3rem; + padding-left: 1.5rem; + padding-right: 1.5rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + height: 3rem; + background-color: rgb(150, 108, 230); + width: fit-content; + color: white; + font-family: Silka; + font-size: 16px; +} + +.content { + flex: 1; + display: flex; + margin: 2rem; + display: flex; + flex-direction: column; +} + +#app-icon { + -webkit-user-drag: none; + margin: 1rem 0; +} + +#title { + margin: 1rem 0; +} + +#diagnostics { + margin: 1rem 0; +} + +#details { + margin: 1rem 0; + flex: 1; + overflow-y: auto; + white-space: pre-line; + min-height: 50px; +} + +.help { + color: #c4d1e8; + font-size: 0.8rem; + line-height: 1.5rem; +} + +::-webkit-scrollbar { + width: 8px; +} + +::-webkit-scrollbar-thumb { + background-color: #d8e3f5; + border-radius: 10px; +} + +::-webkit-scrollbar-track { + background-color: transparent; +} diff --git a/packages/desktop/public/error.html b/packages/desktop/public/error.html index 63f2b44688..7b67e51363 100644 --- a/packages/desktop/public/error.html +++ b/packages/desktop/public/error.html @@ -1,240 +1,58 @@ - - - - - - Bloom Error - - - - -
- App icon -

Unfortunately an error has occurred in Bloom.

-
-

-

-    

-    

-    
-    
- -
- - - - - - + + + + + Bloom Error + + + +
+ App icon +

Unfortunately an error has occurred in Bloom.

+
+

+

+            

+            

+            
+            
+ +
+ + diff --git a/packages/desktop/public/error.js b/packages/desktop/public/error.js new file mode 100644 index 0000000000..d78debfec9 --- /dev/null +++ b/packages/desktop/public/error.js @@ -0,0 +1,65 @@ +// https://github.com/electron/electron/issues/2863 +var exports = exports || {} + +let errorData + +window.error.getData().then((err) => { + errorData = err + document.getElementById('app-icon').src = errorData.iconPath + document.getElementById('version').textContent = `App Version: ${errorData.version}` + document.getElementById('diagnostics').textContent = errorData.diagnostics + document.getElementById('errorType').textContent = `Error Type: ${errorData.errorType}` + document.getElementById('details').textContent = formatError() +}) + +function formatError() { + let formatted = [] + + if (errorData.error) { + if (errorData.error instanceof Error || errorData.error.stack || errorData.error.message) { + if (errorData.error.stack) { + formatted.push(errorData.error.stack) + } else if (errorData.error.message) { + formatted.push(errorData.error.message) + } + } else if (typeof errorData.error == 'string') { + formatted.push(errorData.error) + } else { + formatted.push(JSON.stringify(errorData.error)) + } + } + + return formatted.join('\r\n') +} + +function copy() { + let content = `App Version: ${errorData.version}\r\n\r\n` + content += errorData.diagnostics + '\r\n\r\n' + content += `Error Type: ${errorData.errorType}` + '\r\n\r\n' + content += formatError() + copyToClipboard(content) +} + +function copyToClipboard(input) { + try { + const textArea = document.createElement('textarea') + textArea.value = input + document.body.appendChild(textArea) + + if (navigator.userAgent.match(/ipad|iphone/i)) { + const range = document.createRange() + range.selectNodeContents(textArea) + const selection = window.getSelection() + selection.removeAllRanges() + selection.addRange(range) + textArea.setSelectionRange(0, 999999) + } else { + textArea.select() + } + + document.execCommand('copy') + document.body.removeChild(textArea) + } catch (err) {} +} + +copyButton.addEventListener('click', copy)