/
githubmirror
/
atom
Обзор
Документация
Войти
/
githubmirror
/
atom
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v1.56.0
src/main-process/atom-protocol-handler.js
54 строки
2 KB
Rafael Oleza
Reformat all JS files using prettier
31 май 2019, 19:33
31 май 2019, 19:33
7f3f040
Код
Авторство
О чём код?
const { protocol } = require('electron'); const fs = require('fs-plus'); const path = require('path'); // Handles requests with 'atom' protocol. // // It's created by {AtomApplication} upon instantiation and is used to create a // custom resource loader for 'atom://' URLs. // // The following directories are searched in order: // * ~/.atom/assets // * ~/.atom/dev/packages (unless in safe mode) // * ~/.atom/packages // * RESOURCE_PATH/node_modules // module.exports = class AtomProtocolHandler { constructor(resourcePath, safeMode) { this.loadPaths = []; if (!safeMode) { this.loadPaths.push(path.join(process.env.ATOM_HOME, 'dev', 'packages')); this.loadPaths.push(path.join(resourcePath, 'packages')); } this.loadPaths.push(path.join(process.env.ATOM_HOME, 'packages')); this.loadPaths.push(path.join(resourcePath, 'node_modules')); this.registerAtomProtocol(); } // Creates the 'atom' custom protocol handler. registerAtomProtocol() { protocol.registerFileProtocol('atom', (request, callback) => { const relativePath = path.normalize(request.url.substr(7)); let filePath; if (relativePath.indexOf('assets/') === 0) { const assetsPath = path.join(process.env.ATOM_HOME, relativePath); const stat = fs.statSyncNoException(assetsPath); if (stat && stat.isFile()) filePath = assetsPath; } if (!filePath) { for (let loadPath of this.loadPaths) { filePath = path.join(loadPath, relativePath); const stat = fs.statSyncNoException(filePath); if (stat && stat.isFile()) break; } } callback(filePath); }); } };