feat(changelog): changelog inside application

This commit is contained in:
Alexey Kasyanchuk
2018-02-06 00:41:23 +03:00
parent 74def9f763
commit 9bac53f559
6 changed files with 324 additions and 12 deletions

26
src/app/changelog-page.js Normal file
View File

@ -0,0 +1,26 @@
import React from 'react';
import Page from './page';
import ReactMarkdown from 'react-markdown'
import fs from 'fs'
export default class ChangeLog extends Page {
constructor(props) {
super(props)
this.setTitle('Changelog');
let changelogPath = 'CHANGELOG.md'
if(!fs.existsSync(changelogPath))
changelogPath = 'resources/CHANGELOG.md'
this.changelog = fs.readFileSync(changelogPath)
if(!this.changelog)
throw new Error('no changelog file')
}
render() {
return (
<div className='pad0-75'>
<ReactMarkdown skipHtml={true} source={this.changelog} />
</div>
);
}
}

View File

@ -6,6 +6,7 @@ import TorrentPage from './torrent-page.js'
import DMCAPage from './dmca-page.js'
import AdminPage from './admin-page.js'
import TopPage from './top-page.js'
import ChangelogPage from './changelog-page.js'
let routers = {}
const router = (page, callback) => {
@ -81,4 +82,11 @@ router('/top', () => {
//singleton
let pie = new PagesPie;
pie.open(TopPage, {replace: 'all'});
});
router('/changelog', () => {
//singleton
let pie = new PagesPie;
console.log('changelog')
pie.open(ChangelogPage, {replace: 'all'});
});

View File

@ -6,10 +6,12 @@
import path from "path";
import url from "url";
import { app, Menu, ipcMain, Tray } from "electron";
import createWindow from "./helpers/window";
import { devMenuTemplate } from "./menu/dev_menu_template";
import { editMenuTemplate } from "./menu/edit_menu_template";
import { settingsMenuTemplate } from "./menu/config_menu_template";
import createWindow from "./helpers/window";
import { aboutMenuTemplate } from "./menu/about_menu_template";
// Special module holding environment variables which you declared
// in config/env_xxx.json file.
@ -19,7 +21,7 @@ const { spawn, exec } = require('child_process')
const fs = require('fs')
const setApplicationMenu = () => {
const menus = [editMenuTemplate, settingsMenuTemplate];
const menus = [editMenuTemplate, settingsMenuTemplate, aboutMenuTemplate];
if (env.name !== "production") {
menus.push(devMenuTemplate);
}

View File

@ -0,0 +1,38 @@
import { app, BrowserWindow, shell } from "electron";
import path from "path";
import url from "url";
export const aboutMenuTemplate = {
label: "About",
submenu: [
{
label: "Changelog",
accelerator: "CmdOrCtrl+]",
click: () => {
const win = new BrowserWindow({
parent: BrowserWindow.getFocusedWindow(),
modal: true
})
win.setMenu(null)
win.loadURL(url.format({
pathname: path.join(__dirname, "app.html"),
protocol: "file:",
slashes: true
}))
win.webContents.on('did-finish-load', () => {
win.send('url', '/changelog')
});
const handleRedirect = (e, url) => {
if(url != win.webContents.getURL()) {
e.preventDefault()
shell.openExternal(url)
}
}
win.webContents.on('will-navigate', handleRedirect)
win.webContents.on('new-window', handleRedirect)
}
}
]
};