Add logger

Console logger, not token logger
master
Drake 2 years ago
parent 2d063a8457
commit 9d51c98be8

2
dist/build.js vendored

File diff suppressed because one or more lines are too long

@ -1,5 +1,6 @@
// @flow
import { get, set } from 'idb-keyval';
import log from './utils/logger.js'
async function init(obj: Object): Promise<boolean> {
//TODO: check for enabled plugins in the idb, start them
@ -28,7 +29,7 @@ async function addPlugin(iife: string, metadata: Object): Promise<boolean> {
const globalSettings: Object = await get("demoncord");
/*try {
if (globalSettings["plugin"][metadata.name] !== undefined) {
console.error("[Demoncord] Cannot add plugin that already exists!")
log("Cannot add plugin that already exists!", "error", "Plugins")
return false
}
} catch (error) {*/
@ -41,7 +42,7 @@ async function addPlugin(iife: string, metadata: Object): Promise<boolean> {
async function delPlugin(name: string): Promise<boolean> {
const globalSettings = await get("demoncord")
if (globalSettings["plugin"][name] === undefined) {
console.error("[Demoncord] Cannot remove non-existant plugin!")
log("Cannot remove non-existant plugin!", "error", "Plugins")
return false
} else {
globalSettings["plugin"][name] = undefined
@ -54,16 +55,16 @@ async function delPlugin(name: string): Promise<boolean> {
async function startPlugin(name: string): Promise<boolean> {
const globalSettings = await get("demoncord")
if (globalSettings["plugin"][name] === undefined) {
console.error("[Demoncord] Cannot start non-existant plugin!")
log("Cannot start non-existant plugin!", "error", "Plugins")
return false
} else {
console.log(`[Demoncord] Starting ${name}...`)
log(`Starting ${name}...`, "log", "Plugins")
const plug = globalSettings["plugin"][name]
const exports: Object = (0, eval)(plug.iife)
const onStart: (ctx: Object)=>void = exports.onStart
let ctx = {} // ctx is how you're going to store things that need to be accessed in both onStart and onStop. dumb, i know
onStart(ctx)
console.log(`[Demoncord] Started ${name}!`)
log(`Started ${name}!`, "log", "Plugins")
window.demon.__plugins[name] = {status: 1, ctx: ctx}
return true
}
@ -72,15 +73,15 @@ async function startPlugin(name: string): Promise<boolean> {
async function stopPlugin(name: string): Promise<boolean> {
const globalSettings = await get("demoncord")
if (globalSettings["plugin"][name] === undefined ) {
console.error("[Demoncord] Cannot stop non-existant or non-running plugin!")
log("Cannot stop non-existant or non-running plugin!", "error", "Plugins")
return false
} else {
console.log(`[Demoncord] Stopping ${name}...`)
log(`Stopping ${name}...`, "log", "Plugins")
const plug = globalSettings["plugin"][name]
const exports: Object = (0, eval)(plug.iife)
const onStop: (ctx: Object)=>void = exports.onStop
onStop(window.demon.__plugins[name].ctx)
console.log(`[Demoncord] Stopped ${name}!`)
log(`Stopped ${name}!`, "log", "Plugins")
return true
}
}
@ -88,7 +89,7 @@ async function stopPlugin(name: string): Promise<boolean> {
async function togglePlugin(name: string): Promise<boolean> {
const globalSettings = await get("demoncord")
if (globalSettings["plugin"][name] === undefined) {
console.error("[Demoncord] Cannot enable non-existant plugin!")
log("Cannot toggle non-existant plugin!", "error", "Plugins")
return false
} else {
globalSettings["plugin"][name].enabled = !globalSettings["plugin"][name].enabled

@ -0,0 +1,19 @@
//@flow
//TODO: make setting to save logs in idb, for debugging and troubleshooting purposes
//bg: #aa8dd8
//fg: #553986
function log(message: string, type: string, ...locs: string[]): void {
let string = "%cDemoncord%c "
let style = []
for (let i = 0; i < locs.length; i++) {
const loc = locs[i]
style.push("@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@700&display=swap'); font-family: 'IBM Plex Mono', monospace; font-weight: 600; background-color: #aa8dd8; color: #1d1131; border-radius: 5px; padding: 0px 5px 1px 5px; font-size: 0.9em;", "")
string += `%c${loc}%c `
}
style.push("@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@700&display=swap'); font-family: 'IBM Plex Mono', monospace; font-weight: 600; background-color: #aa8dd8; color: #1d1131; border-radius: 5px; padding: 0px 5px 1px 5px; font-size: 0.9em;", "")
string += `%c${message}`
style.push("@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@700&display=swap'); font-family: 'IBM Plex Mono', monospace; font-weight: 500; font-size: 0.9em; color: #E2EECE;")
console[type](string, ...style)
}
export default log;
Loading…
Cancel
Save