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

Add Persistent Notification System with Toast Notification #1071

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion src/lang/ar-ye.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/be-by.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/bn-bd.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/cs-cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Sind sie sicher, das Sie {count} Einträge löschen wollen?",
"deleting items": "Löschen von {count} Einträgen...",
"import project zip": "Projekt(-Zip) importieren",
"changelog": "Änderungsbericht"
"changelog": "Änderungsbericht",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/es-sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/fr-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/hi-in.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/hu-hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Biztosan töröl {count} elemet?",
"deleting items": "{count} elem törlése…",
"import project zip": "Projekt importálása zip-ből",
"changelog": "Változásnapló"
"changelog": "Változásnapló",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/id-id.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/ir-fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/it-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/ja-jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/ko-kr.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/ml-in.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/mm-unicode.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/mm-zawgyi.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/pl-pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/pu-in.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/ru-ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/tl-ph.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/tr-tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/uk-ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/uz-uz.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/vi-vn.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,7 @@
"delete entries": "Bạn có chắc muốn xoá {count} mục?",
"deleting items": "Đang xoá {count} mục...",
"import project zip": "Nhập Dự Án(zip)",
"changelog": "Nhật Ký Thay Đổi"
"changelog": "Nhật Ký Thay Đổi",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/zh-hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
4 changes: 3 additions & 1 deletion src/lang/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,7 @@
"delete entries": "Are you sure you want to delete {count} items?",
"deleting items": "Deleting {count} items...",
"import project zip": "Import Project(zip)",
"changelog": "Change Log"
"changelog": "Change Log",
"notifications": "Notifications",
"no_unread_notifications": "No unread notifications"
}
26 changes: 26 additions & 0 deletions src/lib/acode.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import commands from "lib/commands";
import EditorFile from "lib/editorFile";
import files from "lib/fileList";
import fonts from "lib/fonts";
import NotificationManager from "lib/notificationManager";
import openFolder from "lib/openFolder";
import projects from "lib/projects";
import selectionMenu from "lib/selectionMenu";
Expand Down Expand Up @@ -416,4 +417,29 @@ export default class Acode {
url = await helpers.toInternalUri(url);
return url;
}
/**
* Push a notification
* @param {string} title Title of the notification
* @param {string} message Message body of the notification
* @param {Object} options Notification options
* @param {string} [options.icon] Icon for the notification, can be a URL or a base64 encoded image or icon class or svg string
* @param {boolean} [options.autoClose=true] Whether notification should auto close
* @param {Function} [options.action=null] Action callback when notification is clicked
* @param {('info'|'warning'|'error'|'success')} [options.type='info'] Type of notification
*/
pushNotification(
title,
message,
{ icon, autoClose = true, action = null, type = "info" } = {},
) {
const nm = new NotificationManager();
nm.pushNotification({
title,
message,
icon,
autoClose,
action,
type,
});
}
}
31 changes: 13 additions & 18 deletions src/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { setKeyBindings } from "ace/commands";
import { initModes } from "ace/modelist";
import { keydownState } from "handlers/keyboard";
import { initFileList } from "lib/fileList";
import NotificationManager from "lib/notificationManager";
import { addedFolder } from "lib/openFolder";
import { getEncoding, initEncodings } from "utils/encodings";
import constants from "./constants";
Expand Down Expand Up @@ -369,32 +370,26 @@ async function loadApp() {
});
//#endregion

window.log("info", "Started app and services...");
const notificationManager = new NotificationManager();
notificationManager.init();

window.log("info", "Started app and its services...");

new EditorFile();

checkPluginsUpdate()
.then((updates) => {
if (!updates.length) return;
const $icon = (
<span
onclick={() => {
acode.pushNotification(
"Plugin Updates",
`${updates.length} plugin${updates.length > 1 ? "s" : ""} ${updates.length > 1 ? "have" : "has"} new version${updates.length > 1 ? "s" : ""} available.`,
{
icon: "extension",
action: () => {
plugins(updates);
$icon.remove();
}}
attr-action=""
style={{ fontSize: "1.2rem" }}
className="icon notifications"
></span>
},
},
);

if ($editMenuToggler.isConnected) {
$header.insertBefore($icon, $editMenuToggler);
} else if ($runBtn.isConnected) {
$header.insertBefore($icon, $runBtn);
} else {
$header.insertBefore($icon, $menuToggler);
}
})
.catch(console.error);

Expand Down
Loading