UNPKG

nyaovim

Version:

Web-enhanced Extensible Neovim Frontend

86 lines 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = require("path"); const fs_1 = require("fs"); const electron_1 = require("electron"); const extend = require("deep-extend"); const windowStateKeeper = require("electron-window-state"); class BrowserConfig { constructor() { this.loaded_config = null; this.window_state = null; } loadFrom(config_dir) { return new Promise(resolve => { try { const config_file = path_1.join(config_dir, 'browser-config.json'); const content = fs_1.readFileSync(config_file, 'utf8'); this.loaded_config = JSON.parse(content); } catch (e) { } resolve(); }); } applyToOptions(opt) { if (typeof this.loaded_config !== 'object' || this.loaded_config === null) { return opt; } if (typeof this.loaded_config.window_options === 'object') { extend(opt, this.loaded_config.window_options); } if (this.loaded_config.remember_window_state) { const s = windowStateKeeper({ defaultWidth: 1000, defaultHeight: 800, path: global.config_dir_path, }); if (typeof s.x === 'number') { opt.x = s.x; } if (typeof s.y === 'number') { opt.y = s.y; } opt.width = s.width; opt.height = s.height; if (typeof s.isFullScreen === 'boolean') { opt.fullscreen = s.isFullScreen; } this.window_state = s; } return opt; } setupWindowState(win) { if (this.window_state === null) { return null; } win.on('resize', () => { this.window_state.saveState(win); }); if (this.window_state.isMaximized) { win.maximize(); } return this.window_state; } configSingletonWindow(win) { if (this.loaded_config === null || !this.loaded_config.single_instance) { return false; } return electron_1.app.makeSingleInstance((argv, cwd) => { if (win.isMinimized()) { win.restore(); } win.focus(); const args = argv.slice(2); if (args.length !== 0) { win.webContents.send('nyaovim:exec-commands', [ 'cd ' + cwd, 'args ' + args.join(' '), ]); } return true; }); } } exports.default = BrowserConfig; //# sourceMappingURL=browser-config.js.map