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 {
if (!windowInfo.url) {
// 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);
windowInfo.url = urlMatches && urlMatches.length > 0 ? urlMatches[0] : null;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -13,6 +13,7 @@ function charCodeToHtml(char) {
if (char === 32 || char === 8193 || char === 8239) {
char = 160;
}
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];
if (this.level >= Level.Debug) {
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];
if (this.level >= Level.Info) {
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];
if (this.level >= Level.Warn) {
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];
if (this.level >= Level.Error) {
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) {
const callback = this.async();
const iconFontScssPath = path.resolve('app/styles/base/_icon-font.scss');
this.addDependency(iconFontScssPath);
@ -12,12 +11,20 @@ module.exports = function loadScss(scssSource) {
if (err) {
return callback(err);
}
scssSource +=
'\n' +
[...iconFontScssSource.matchAll(/\n\$fa-var-([\w-]+):/g)]
.map(([, name]) => name)
.map((icon) => `.fa-${icon}:before { content: $fa-var-${icon}; }`)
.map(([, name]) => {
// console.log(`name: ${name}`);
return name;
})
.map((icon) => {
// console.log(`$fa-var-${icon}`);
return `.fa-${icon}:before { content: $fa-var-${icon}; }`;
})
.join('\n');
// console.log(scssSource);
callback(null, scssSource);
});
};

View File

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