style: minor changes to numerous blocks of code

This commit is contained in:
Aetherinox 2024-04-21 04:10:31 -07:00
parent ce3fcdf1c6
commit beb4b8c35b
No known key found for this signature in database
GPG Key ID: CB5C4C30CD0D4028
9 changed files with 37 additions and 25 deletions

View File

@ -171,7 +171,8 @@ const AutoType = {
} else { } else {
if (!windowInfo.url) { if (!windowInfo.url) {
// try to find a URL in the title // try to find a URL in the title
const urlMatcher = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\\+.~#?&\/=]*)/; const urlMatcher =
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\\+.~#?&\/=]*)/;
const urlMatches = urlMatcher.exec(windowInfo.title); const urlMatches = urlMatcher.exec(windowInfo.title);
windowInfo.url = urlMatches && urlMatches.length > 0 ? urlMatches[0] : null; windowInfo.url = urlMatches && urlMatches.length > 0 ? urlMatches[0] : null;
} }

View File

@ -467,7 +467,6 @@ class EntryModel extends Model {
if (otpUrl.isProtected) { if (otpUrl.isProtected) {
otpUrl = otpUrl.getText(); otpUrl = otpUrl.getText();
} }
// called only if secret provided, no formatted url
if (Otp.isSecret(otpUrl.replace(/\s/g, ''))) { if (Otp.isSecret(otpUrl.replace(/\s/g, ''))) {
otpUrl = Otp.makeUrl(otpUrl.replace(/\s/g, '').toUpperCase()); otpUrl = Otp.makeUrl(otpUrl.replace(/\s/g, '').toUpperCase());
} else if (otpUrl.toLowerCase().lastIndexOf('otpauth:', 0) !== 0) { } else if (otpUrl.toLowerCase().lastIndexOf('otpauth:', 0) !== 0) {

View File

@ -27,6 +27,7 @@ const ThemeVars = {
apply(cssStyle) { apply(cssStyle) {
this.init(); this.init();
const matches = ThemeVarsScss.replace(this.newLineRegEx, '').matchAll(this.themeVarsRegEx); const matches = ThemeVarsScss.replace(this.newLineRegEx, '').matchAll(this.themeVarsRegEx);
// eslint-disable-next-line prefer-const
for (let [, name, def, last] of matches) { for (let [, name, def, last] of matches) {
if (last && def.endsWith(')')) { if (last && def.endsWith(')')) {
// definitions are written like this: // definitions are written like this:

View File

@ -74,8 +74,7 @@ class StorageDropbox extends StorageBase {
_getOAuthConfig() { _getOAuthConfig() {
return { return {
scope: scope: 'files.content.read files.content.write files.metadata.read files.metadata.write',
'files.content.read files.content.write files.metadata.read files.metadata.write',
url: 'https://www.dropbox.com/oauth2/authorize', url: 'https://www.dropbox.com/oauth2/authorize',
tokenUrl: 'https://api.dropboxapi.com/oauth2/token', tokenUrl: 'https://api.dropboxapi.com/oauth2/token',
clientId: this._getKey(), clientId: this._getKey(),

View File

@ -33,7 +33,7 @@ class StorageBase {
this.enabled = enabled; this.enabled = enabled;
} }
} }
this.logger = new Logger('storage-' + this.name); // this.logger = new Logger('storage-' + this.name);
return this; return this;
} }
@ -55,7 +55,8 @@ class StorageBase {
} }
_xhr(config) { _xhr(config) {
this.logger.info('HTTP request', config.method || 'GET', config.url); // this.logger.info(JSON.stringify(config));
// this.logger.info('HTTP request', config.method || 'GET', config.url);
if (config.data) { if (config.data) {
if (!config.dataType) { if (!config.dataType) {
config.dataType = 'application/octet-stream'; config.dataType = 'application/octet-stream';
@ -71,12 +72,14 @@ class StorageBase {
'Authorization': 'Bearer ' + this._oauthToken.accessToken 'Authorization': 'Bearer ' + this._oauthToken.accessToken
}; };
} }
this._httpRequest(config, (response) => { this._httpRequest(config, (response) => {
this.logger.info('HTTP response', response.status); // this.logger.info('inside status response', response.status);
const statuses = config.statuses || [200]; const statuses = config.statuses || [200];
if (statuses.indexOf(response.status) >= 0) { if (statuses.indexOf(response.status) >= 0) {
return config.success && config.success(response.response, response); return config.success && config.success(response.response, response);
} }
// this.logger.info(response.status);
if (response.status === 401 && this._oauthToken) { if (response.status === 401 && this._oauthToken) {
this._oauthGetNewToken((err) => { this._oauthGetNewToken((err) => {
if (err) { if (err) {
@ -140,7 +143,7 @@ class StorageBase {
} }
_httpRequestLauncher(config, onLoad) { _httpRequestLauncher(config, onLoad) {
Launcher.remoteApp().httpRequest( Launcher.remoteApp().httpRequestQuery(
config, config,
(level, ...args) => this.logger[level](...args), (level, ...args) => this.logger[level](...args),
({ status, response, headers }) => { ({ status, response, headers }) => {
@ -173,13 +176,13 @@ class StorageBase {
const winWidth = window.innerWidth const winWidth = window.innerWidth
? window.innerWidth ? window.innerWidth
: document.documentElement.clientWidth : document.documentElement.clientWidth
? document.documentElement.clientWidth ? document.documentElement.clientWidth
: screen.width; : screen.width;
const winHeight = window.innerHeight const winHeight = window.innerHeight
? window.innerHeight ? window.innerHeight
: document.documentElement.clientHeight : document.documentElement.clientHeight
? document.documentElement.clientHeight ? document.documentElement.clientHeight
: screen.height; : screen.height;
const left = winWidth / 2 - width / 2 + dualScreenLeft; const left = winWidth / 2 - width / 2 + dualScreenLeft;
const top = winHeight / 2 - height / 2 + dualScreenTop; const top = winHeight / 2 - height / 2 + dualScreenTop;
@ -221,6 +224,7 @@ class StorageBase {
} }
if (oldToken && oldToken.refreshToken) { if (oldToken && oldToken.refreshToken) {
// this.logger.debug('_oauthAuthorize 1');
return this._oauthExchangeRefreshToken(callback); return this._oauthExchangeRefreshToken(callback);
} }
@ -437,7 +441,6 @@ class StorageBase {
} }
_oauthExchangeRefreshToken(callback) { _oauthExchangeRefreshToken(callback) {
this.logger.debug('Exchanging refresh token');
const { refreshToken } = this.runtimeData[this.name + 'OAuthToken']; const { refreshToken } = this.runtimeData[this.name + 'OAuthToken'];
const config = this._getOAuthConfig(); const config = this._getOAuthConfig();
this._xhr({ this._xhr({
@ -467,7 +470,6 @@ class StorageBase {
this.logger.error('Error exchanging refresh token, trying to authorize again'); this.logger.error('Error exchanging refresh token, trying to authorize again');
this._oauthAuthorize(callback); this._oauthAuthorize(callback);
} else { } else {
this.logger.error('Error exchanging refresh token', err);
callback?.('Error exchanging refresh token'); callback?.('Error exchanging refresh token');
} }
} }

View File

@ -13,6 +13,7 @@ function charCodeToHtml(char) {
if (char === 32 || char === 8193 || char === 8239) { if (char === 32 || char === 8193 || char === 8239) {
char = 160; char = 160;
} }
return Math.random() < 0.2 ? String.fromCharCode(char) : `&#x${char.toString(16)};`; return Math.random() < 0.2 ? String.fromCharCode(char) : `&#x${char.toString(16)};`;
} }

View File

@ -32,7 +32,7 @@ Logger.prototype.debug = function (...args) {
args[0] = this.getPrefix() + args[0]; args[0] = this.getPrefix() + args[0];
if (this.level >= Level.Debug) { if (this.level >= Level.Debug) {
Logger.saveLast('debug', args); Logger.saveLast('debug', args);
console.log(...args); // eslint-disable-line no-console console.log(...args);
} }
}; };
@ -40,7 +40,7 @@ Logger.prototype.info = function (...args) {
args[0] = this.getPrefix() + args[0]; args[0] = this.getPrefix() + args[0];
if (this.level >= Level.Info) { if (this.level >= Level.Info) {
Logger.saveLast('info', args); Logger.saveLast('info', args);
console.info(...args); // eslint-disable-line no-console console.info(...args);
} }
}; };
@ -48,7 +48,7 @@ Logger.prototype.warn = function (...args) {
args[0] = this.getPrefix() + args[0]; args[0] = this.getPrefix() + args[0];
if (this.level >= Level.Warn) { if (this.level >= Level.Warn) {
Logger.saveLast('warn', args); Logger.saveLast('warn', args);
console.warn(...args); // eslint-disable-line no-console console.warn(...args);
} }
}; };
@ -56,7 +56,7 @@ Logger.prototype.error = function (...args) {
args[0] = this.getPrefix() + args[0]; args[0] = this.getPrefix() + args[0];
if (this.level >= Level.Error) { if (this.level >= Level.Error) {
Logger.saveLast('error', args); Logger.saveLast('error', args);
console.error(...args); // eslint-disable-line no-console console.error(...args);
} }
}; };

View File

@ -3,7 +3,6 @@ const path = require('path');
module.exports = function loadScss(scssSource) { module.exports = function loadScss(scssSource) {
const callback = this.async(); const callback = this.async();
const iconFontScssPath = path.resolve('app/styles/base/_icon-font.scss'); const iconFontScssPath = path.resolve('app/styles/base/_icon-font.scss');
this.addDependency(iconFontScssPath); this.addDependency(iconFontScssPath);
@ -12,12 +11,20 @@ module.exports = function loadScss(scssSource) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
scssSource += scssSource +=
'\n' + '\n' +
[...iconFontScssSource.matchAll(/\n\$fa-var-([\w-]+):/g)] [...iconFontScssSource.matchAll(/\n\$fa-var-([\w-]+):/g)]
.map(([, name]) => name) .map(([, name]) => {
.map((icon) => `.fa-${icon}:before { content: $fa-var-${icon}; }`) // console.log(`name: ${name}`);
return name;
})
.map((icon) => {
// console.log(`$fa-var-${icon}`);
return `.fa-${icon}:before { content: $fa-var-${icon}; }`;
})
.join('\n'); .join('\n');
// console.log(scssSource);
callback(null, scssSource); callback(null, scssSource);
}); });
}; };

View File

@ -3,19 +3,21 @@ module.exports = function (grunt) {
const done = this.async(); const done = this.async();
const opt = this.options(); const opt = this.options();
const file = this.files[0].src[0]; const file = this.files[0].src[0];
const path = require('path'); const path = require('path');
const puppeteer = require('puppeteer'); const puppeteer = require('puppeteer');
(async function () { (async function () {
grunt.log.writeln('Running tests...'); grunt.log.writeln('Running tests...');
const fullPath = 'file://' + path.resolve(file); const fullPath = 'file://' + path.resolve(file);
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
headless: opt.headless, headless: opt.headless
executablePath: process.env.CHROME_BIN || null,
args: ['--disable-dev-shm-usage']
}); });
grunt.log.writeln('puppeteer launched...');
const page = await browser.newPage(); const page = await browser.newPage();
await page.goto(fullPath); await page.goto(fullPath);
async function check() { async function check() {
const result = await page.evaluate(() => { const result = await page.evaluate(() => {
const { output, done } = window; const { output, done } = window;