Skip to content

Commit

Permalink
change: error dialog for emergencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Aetherinox committed Jul 20, 2024
1 parent 87bcd69 commit 1546217
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
58 changes: 51 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ let bDevTools = 0;
let bHotkeysEnabled = 0;
let bQuitOnClose = 0;

/*
Declare > Status
*/

let statusHasError = false;
let statusMessage;

/*
Declare > Fallback
Expand Down Expand Up @@ -163,19 +170,19 @@ const menu_Main = [
}
},
{
label: 'Self-hosting',
accelerator: 'CTRL+S',
label: 'URL',
accelerator: 'CTRL+U',
click: function () {
prompt(
{
title: 'Set Server Instance',
label: 'Server URL<div class="label-desc">This can either be the URL to the official ntfy.sh server, or your own self-hosted domain / ip.</div>',
label: 'Server URL<div class="label-desc">This can either be the URL to the official ntfy.sh server, or your own self-hosted domain / ip.<br><br>Remove everything to set back to official ntfy.sh server.</div>',
useHtmlLabel: true,
value: store.get('instanceURL'),
alwaysOnTop: true,
type: 'input',
customStylesheet: path.join(__dirname, `pages`, `css`, `prompt.css`),
height: 240,
height: 280,
icon: app.getAppPath() + '/ntfy.png',
inputAttrs: {
type: 'url'
Expand All @@ -185,8 +192,9 @@ const menu_Main = [
)
.then((response) => {
if (response !== null) {
store.set('instanceURL', response)
winMain.loadURL(response)
const newUrl = (response === "" ? _Instance : response)
store.set('instanceURL', newUrl)
winMain.loadURL(newUrl)
}
})
.catch((response) => {
Expand All @@ -207,7 +215,7 @@ const menu_Main = [
prompt(
{
title: 'Set API Token',
label: 'API Token<div class="label-desc">Generate an API token within ntfy.sh or your self-hosted instance and provide it below so that noficiations can be fetched.</div>',
label: 'API Token<div class="label-desc">Generate an API token within ntfy.sh or your self-hosted instance and provide it below to receive desktop push notifications.</div>',
useHtmlLabel: true,
value: store.get('apiToken'),
alwaysOnTop: true,
Expand Down Expand Up @@ -430,6 +438,9 @@ function ready() {

if (typeof (store.get('instanceURL')) !== 'string') {
store.set('instanceURL', _Instance);

statusHasError = true;
statusMessage = `Invalid instance URL specified; defaulting to ${_Instance}`;
}

winMain.loadURL(store.get('instanceURL'))
Expand Down Expand Up @@ -482,6 +493,39 @@ function ready() {
require('electron').shell.openExternal(url);
});

/*
Display footer div on website if something has gone wrong.
user shouldn't see this unless its something serious
*/

if (statusHasError === true ) {
winMain.webContents.on('did-finish-load', (e, url)=>{
winMain.webContents
.executeJavaScript(
`
const div = document.createElement("div");
div.style.position = "sticky";
div.style.height = "36px";
div.style.width = "100%";
div.style.zIndex = "3000";
div.style.overflow = "hidden";
div.style.marginTop = "-36px";
div.style.padding = "7px";
div.style.paddingLeft = "20px";
div.style.paddingRight = "20px";
div.style.backgroundColor = "rgb(151 63 63)";
const closeSpan = document.createElement("span");
closeSpan.setAttribute("class","sr-only");
closeSpan.textContent = '${statusMessage}';
div.appendChild(closeSpan);
document.body.appendChild(div);
`
)
});
}

/*
Event > Input
*/
Expand Down
2 changes: 1 addition & 1 deletion pages/css/prompt.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ body {
.label-desc {
padding-top: 4px;
padding-bottom: 7px;
font-size: 9.8pt;
font-size: 9.3pt;
white-space: normal;
color: #9f9f9f;
}
Expand Down

0 comments on commit 1546217

Please sign in to comment.