Skip to content

Commit

Permalink
Merge branch 'main' into feature/ok-as-pause
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha authored Feb 26, 2024
2 parents ae9ee29 + 544671f commit 993ac17
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
4 changes: 0 additions & 4 deletions playlet-lib/src/components/VideoPlayer/VideoContentTask.bs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ function AddInstanceToUrlIfNeeded(streamUrls as object, instance as string)
end for
end function

' TODO:P2
' Captions are rate limited https://github.com/iv-org/invidious/issues/2567
' It's possible to loop through a list of backup instances hoping to find working subtitles.
' Caveat: searching for a working caption could cause a delay in the video player start.
function SetCaptions(metadata as object, service as object, contentNode as object) as void
if metadata.captions.Count() = 0
return
Expand Down
48 changes: 43 additions & 5 deletions tools/bs-plugins/logger-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export class LoggerPlugin implements CompilerPlugin {
}
}

this.generateLoggingFile(program, usedLogFunctions);
// @ts-ignore
const isDebug = !!program.options.debug;
this.generateLoggingFile(program, usedLogFunctions, isDebug);
}

beforeFileTranspile(event: BeforeFileTranspileEvent<BscFile>) {
Expand Down Expand Up @@ -133,20 +135,20 @@ export class LoggerPlugin implements CompilerPlugin {
}
}

generateLoggingFile(program: Program, usedLogFunctions: Map<string, LogFunction>) {
generateLoggingFile(program: Program, usedLogFunctions: Map<string, LogFunction>, isDebug: boolean) {
const file = program.getFile(loggingFilePath);
let content = file.fileContents;

content += '\n\' Start of auto-generated functions\n'
usedLogFunctions.forEach((logFunction, newFunctionName) => {
content += this.generateLoggingFunction(newFunctionName, logFunction.name, logFunction.argCount);
content += this.generateLoggingFunction(newFunctionName, logFunction.name, logFunction.argCount, isDebug);
});
content += '\n\' End of auto-generated functions\n'

program.setFile(loggingFilePath, content)
}

generateLoggingFunction(newFunctionName: string, level: string, argCount: number) {
generateLoggingFunction(newFunctionName: string, level: string, argCount: number, isDebug: boolean) {
const args: string[] = [];
const argsParams: string[] = [];
for (let i = 0; i < argCount; i++) {
Expand All @@ -160,13 +162,49 @@ export class LoggerPlugin implements CompilerPlugin {

const func = logFunctions[level as 'LogError' | 'LogWarn' | 'LogInfo' | 'LogDebug'];

// https://github.com/microsoft/vscode/issues/571
const USE_COLOR = false;

const RED = '[31m';
const YELLOW = '[33m';
const GREEN = '[32m';
const BOLD = '[1m';
const BOLD_RED = '[1;31m';
const BOLD_YELLOW = '[1;33m';
const BOLD_GREEN = '[1;32m';
const CLEAR = '[0m';

let logLine = '';

if (isDebug && USE_COLOR) {
switch (func.stringLevel) {
case 'ERROR':
logLine = `Chr(27) + "${BOLD_RED}" + "[${func.stringLevel}]" + Chr(27) + "${RED}" + ${msg} + Chr(27) + "${CLEAR}"`;
break;
case 'WARN':
logLine = `Chr(27) + "${BOLD_YELLOW}" + "[${func.stringLevel}]" + Chr(27) + "${YELLOW}" + ${msg} + Chr(27) + "${CLEAR}"`;
break;
case 'INFO':
logLine = `Chr(27) + "${BOLD}" + "[${func.stringLevel}]" + Chr(27) + "${CLEAR}" + ${msg}`;
break;
case 'DEBUG':
logLine = `Chr(27) + "${BOLD_GREEN}" + "[${func.stringLevel}]" + Chr(27) + "${GREEN}" + ${msg} + Chr(27) + "${CLEAR}"`;
break;
default:
throw new Error(`Unknown log level: ${func.stringLevel}`);
}
}
else {
logLine = `"[${func.stringLevel}]" + ${msg}`
}

return `
function ${newFunctionName}(${args.join(', ')}) as void
logger = m.global.logger
if logger.logLevel < ${func.level}
return
end if
logger.logLine = "[${func.stringLevel}]" + ${msg}
logger.logLine = ${logLine}
end function
`;
}
Expand Down

0 comments on commit 993ac17

Please sign in to comment.