1
0
mirror of https://github.com/rhysd/Mstdn.git synced 2025-01-20 19:52:10 +01:00

first preload script

This commit is contained in:
rhysd 2017-04-16 02:27:06 +09:00
parent 463dab1537
commit b3da0be465
8 changed files with 53 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import {Config, Account} from './config'
const IS_DEBUG = process.env.NODE_ENV === 'development';
const IS_DARWIN = process.platform === 'darwin';
const APP_ICON = path.join(__dirname, '..', 'resources', 'icon.png');
const PRELOAD_JS = path.join(__dirname, '..', 'renderer', 'preload.js');
const DEFAULT_WIDTH = 340;
const DEFAULT_HEIGHT = 400;
@ -57,6 +58,7 @@ function startNormalWindow(config: Config): Promise<Electron.BrowserWindow> {
webPreferences: {
nodeIntegration: false,
sandbox: true,
preload: PRELOAD_JS,
},
});
win.once('ready-to-show', () => {
@ -135,6 +137,7 @@ function startMenuBar(config: Config): Promise<Electron.BrowserWindow> {
webPreferences: {
nodeIntegration: false,
sandbox: true,
preload: PRELOAD_JS,
},
});
mb.once('ready', () => mb.showWindow());

View File

@ -8,13 +8,17 @@
"open-mstdn-app": "./bin/cli.js"
},
"scripts": {
"build": "tsc --pretty -p .",
"build:ts": "tsc --pretty -p .",
"build:bundle": "NODE_ENV=development browserify renderer/index.js -o renderer/preload.js",
"build": "npm run build:ts && npm run build:bundle",
"build:bundle:release": "NODE_ENV=production browserify renderer/index.js -o renderer/preload.js",
"build:release": "npm run build:ts && npm run build:bundle:release",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "tslint --project tsconfig.json --type-check $(git ls-files | grep -E \"\\.ts$\")",
"watch": "guard --watchdir main renderer typings",
"debug": "NODE_ENV=development electron .",
"start": "NODE_ENV=production electron .",
"release": "npm run lint && ./scripts/make-release.sh"
"release": "npm run lint && npm run build:release && ./scripts/make-release.sh"
},
"repository": {
"type": "git",
@ -38,6 +42,7 @@
"@types/loglevel": "^1.4.29",
"@types/mousetrap": "^1.5.33",
"@types/node": "^7.0.12",
"browserify": "^14.3.0",
"electron-packager": "^8.6.0",
"npm-run-all": "^4.0.2",
"tslint": "^5.1.0",

10
renderer/index.ts Normal file
View File

@ -0,0 +1,10 @@
// import * as Mousetrap from 'mousetrap';
import {Config} from '../main/config';
import * as Ipc from './ipc';
import log from './log';
Ipc.on('mstdn:config', (config: Config) => {
log.info('FOOOOOO', config);
});

11
renderer/ipc.ts Normal file
View File

@ -0,0 +1,11 @@
import log from './log';
import r from './require';
const electron = r('electron');
const ipc = electron.ipcRenderer;
export function on(channel: IpcChannel, callback: Function) {
ipc.on(channel, (...args: any[]) => {
log.info('IPC: Received from:', channel, args);
callback(...args);
});
}

9
renderer/log.ts Normal file
View File

@ -0,0 +1,9 @@
import * as log from 'loglevel';
if (process.env.NODE_ENV === 'development') {
log.setLevel('debug');
} else {
log.setLevel('info');
}
export default log;

4
renderer/require.ts Normal file
View File

@ -0,0 +1,4 @@
// In preload script, global.require does not exist.
// So we need to wrap require() to avoid to be bundled.
export default require;

6
typings/browserify_workaround.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
declare namespace NodeJS {
interface Global {
require: NodeRequireFunction;
}
}

3
typings/ipc.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
type IpcChannel
= 'mstdn:config'
;