Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

Commit

Permalink
Improve default files
Browse files Browse the repository at this point in the history
  • Loading branch information
xnerhu committed Aug 16, 2018
1 parent 43c7824 commit 0953f12
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 27 deletions.
46 changes: 46 additions & 0 deletions key-bindings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"key": "ctrl+digit",
"command": "tabs.switch"
},
{
"key": "ctrl+n",
"command": "tabs.new"
},
{
"key": "ctrl+r",
"command": "tabs.reload"
},
{
"key": "ctrl+left",
"command": "tabs.back"
},
{
"key": "ctrl+right",
"command": "tabs.forward"
},
{
"key": "alt+home",
"command": "tabs.home"
},
{
"key": "ctrl+s",
"command": "workspaces.show"
},
{
"key": "ctrl+h",
"command": "history.show"
},
{
"key": "ctrl+e",
"command": "menu.show"
},
{
"key": "ctrl+b",
"command": "bookmarks.show"
},
{
"key": "esc",
"command": "wexond.hideAllMenu"
}
]
14 changes: 8 additions & 6 deletions src/defaults/paths.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { getPath } from '../utils/paths';
const defaultKeyBindings = require('../../static/defaults/key-bindings.json');

export const defaultPaths = {
plugins: getPath('plugins'),
extensions: getPath('extensions'),
keyBindings: getPath('key-bindings.json'),
export const defaultPaths: { [key: string]: string } = {
plugins: 'plugins',
extensions: 'extensions',
keyBindings: 'key-bindings.json',
};

export default defaultPaths;
export const filesContent: { [key: string]: string } = {
keyBindings: JSON.stringify(defaultKeyBindings, null, 2),
};
32 changes: 11 additions & 21 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { resolve, join } from 'path';
import { platform, homedir } from 'os';
import { mkdirSync, existsSync, writeFileSync } from 'fs';

import { getPath } from '../utils/paths';
import { getPath, isPathFile } from '../utils/paths';
import { runAutoUpdaterService } from './auto-updater';
import { runExtensionsService } from './extensions-service';
import { Global } from './interfaces';
import { createWindow } from './window';
import { registerProtocols } from './protocols';

const defaultKeyBindings = require('../../static/defaults/key-bindings.json');
import { defaultPaths, filesContent } from '../defaults/paths';

app.setPath('userData', resolve(homedir(), '.wexond'));

Expand All @@ -21,10 +20,6 @@ let mainWindow: Electron.BrowserWindow;
global.extensions = {};
global.backgroundPages = {};

const pluginsPath = getPath('plugins');
const extensionsPath = getPath('extensions');
const keyBindingsPath = getPath('key-bindings.json');

app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
Expand All @@ -34,20 +29,15 @@ app.on('activate', () => {
});

app.on('ready', () => {
if (!existsSync(pluginsPath)) {
mkdirSync(pluginsPath);
}

if (!existsSync(extensionsPath)) {
mkdirSync(extensionsPath);
}

if (!existsSync(keyBindingsPath)) {
writeFileSync(
keyBindingsPath,
JSON.stringify(defaultKeyBindings, null, 2),
'utf8',
);
for (const key in defaultPaths) {
const filePath = getPath(defaultPaths[key]);
if (existsSync(filePath)) continue;

if (!isPathFile(filePath)) {
mkdirSync(filePath);
} else {
writeFileSync(filePath, filesContent[key], 'utf8');
}
}

mainWindow = createWindow();
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './key-bindings';
export * from './workspaces';
export * from './tabs';
export * from './pages';
export * from './paths';
4 changes: 4 additions & 0 deletions src/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export const getPath = (...relativePaths: string[]) => {
.resolve(app.getPath('userData'), ...relativePaths)
.replace(/\\/g, '/');
};

export const isPathFile = (file: string) => {
return path.extname(file) !== '';
};

0 comments on commit 0953f12

Please sign in to comment.