Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactorings #57

Merged
merged 54 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
0528a59
rename static to public
mb21 Dec 24, 2020
ad4d908
basic electron typescript setup
mb21 Dec 24, 2020
0962378
basic React GUI running
mb21 Dec 25, 2020
97abf7d
basic preview working
mb21 Dec 26, 2020
cc591f7
MetaEditor and ColorPicker
mb21 Dec 27, 2020
c1f98d8
fixes
mb21 Dec 27, 2020
a44e2cf
basic IPC
mb21 Dec 27, 2020
a89808c
electron-apprenderer
mb21 Dec 27, 2020
0ddf3d8
convert export to ts
mb21 Dec 27, 2020
12a79d5
basic IPC
mb21 Dec 27, 2020
ccce2fa
Merge branch 'ts' of github.com:mb21/panwriter into ts
mb21 Jan 1, 2021
418cad5
remove psc-package
mb21 Jan 1, 2021
bef5514
tsconfig
mb21 Jan 1, 2021
2f1aad5
export
mb21 Jan 1, 2021
28c7aae
import.ts
mb21 Jan 1, 2021
7fab7d1
started converting file to ts
mb21 Jan 3, 2021
a19935a
more
mb21 Jan 6, 2021
b52227c
react-changes
mb21 Jan 9, 2021
c4dce36
more-electron
mb21 Jan 10, 2021
410f60f
electron
mb21 Jan 10, 2021
9767474
react-ipc-part
mb21 Jan 10, 2021
0967af5
update codemirror
mb21 Jan 10, 2021
71c33ab
add print preview
mb21 Jan 10, 2021
e140783
fix some preview issues
mb21 Jan 15, 2021
447b67a
make previewDiv type non-optional
mb21 Jan 17, 2021
ce0b057
consolidate reducers
mb21 Jan 17, 2021
52c8473
ts fixes for scrolling.ts
mb21 Jan 31, 2021
4797dec
convert renderPreviewImpl to TypeScript
mb21 Jan 31, 2021
e37bf0a
fix prod build
mb21 Jan 31, 2021
50234ca
recentFiles.ts
mb21 Jan 31, 2021
abcdbd1
fix isDev
mb21 Jan 31, 2021
1c3509a
move icons to fix yarn build
mb21 Mar 6, 2021
e767aeb
fix prod build
mb21 Mar 6, 2021
85b3930
re-add fix-path
mb21 Mar 6, 2021
fcb5b00
quit app after popup
mb21 Mar 6, 2021
a2ba597
preview: correct comment in interceptClicks
mb21 Mar 7, 2021
dc0ff08
paged.js started
mb21 Mar 7, 2021
b7457e6
update and fix katex
mb21 Mar 27, 2021
d02c999
re-add injecting base tag
mb21 Mar 27, 2021
33b6a65
move renderPreview call into useEffect
mb21 Apr 2, 2021
0804e45
paged: only this works
mb21 Apr 3, 2021
3a1bbe4
fix paged math
mb21 Apr 3, 2021
e410410
add comment
mb21 Apr 3, 2021
ff5b6f8
remove base tag and rewrite image url instead
mb21 Apr 3, 2021
717e9ac
paginated scroll sync
mb21 Apr 3, 2021
2c07d6e
renderPreview: actually buffer instead of rendering old version
mb21 Apr 3, 2021
45a2d27
remove ability to read user-customizable css files
mb21 Apr 3, 2021
107f419
Merge branch 'master' into ts
mb21 Apr 3, 2021
ea3b9f4
electron 12
mb21 Apr 3, 2021
6a17384
export: add Out type
mb21 Apr 5, 2021
0b10e4d
re-add fileExportLikePrevious
mb21 Apr 5, 2021
b854d67
syntactic cleanups
mb21 Apr 5, 2021
c8be27f
fix print from preview
mb21 Apr 5, 2021
e9fd3c6
re-add -webkit-print-color-adjust
mb21 Apr 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
node_modules
output
.psci_modules
.psc-ide-port
.psc-package
dist
.DS_Store
.eslintcache
build
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Select `File -> 'Print / PDF'` and `PDF -> 'Save as PDF'` in the print dialog (e

This will export exactly what’s shown in the preview, and not use pandoc at all.

You can change the styling of the preview and immediately see the changes. (You can later save your CSS as a theme, see [Document types](#document-types--themes) below.)
You can change the styling of the preview and immediately see the changes.

![](screenshot-css.png)

Expand Down Expand Up @@ -83,13 +83,11 @@ If the directory does not exist, you can create it.

### Default CSS and YAML

PanWriter will look for a `default.css` file in the user data directory, to load CSS for the preview. If that file is not found, it will use sensible defaults.

If you put a `default.yaml` file in the data directory, PanWriter will merge this with the YAML in your input file (to determine the command-line arguments to call pandoc with) and add the `--metadata-file` option. The YAML should be in the same format as above.

### Document types / themes

You can e.g. put `type: letter` in the YAML of your input document. In that case, PanWriter will look for `letter.yaml` and `letter.css` instead of `default.yaml` and `default.css` in the user data directory.
You can e.g. put `type: letter` in the YAML of your input document. In that case, PanWriter will look for `letter.yaml` instead of `default.yaml` in the user data directory.

### Markdown syntax

Expand Down
82 changes: 82 additions & 0 deletions electron/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { BrowserWindow, dialog } from 'electron'
import { readFile, writeFile } from 'fs'
import { basename, extname } from 'path'
import { promisify } from 'util'
import * as ipc from './ipc'
import { Doc } from '../src/appState/AppState'
import { addToRecentFiles } from './recentFiles'


export const openFile = async (
win: BrowserWindow
, filePath: string
): Promise<Partial<Doc> | undefined> => {
const fileName = pathToName(filePath)

try {
const md = await promisify(readFile)(filePath, 'utf-8')
win.setTitle(fileName)
win.setRepresentedFilename(filePath)
addToRecentFiles(filePath)
return { md, fileName, filePath, fileDirty: false }
} catch (err) {
dialog.showMessageBox(win, {
type: 'error'
, message: 'Could not open file'
, detail: err.message
})
win.close()
}
}

export const saveFile = async (
win: BrowserWindow
, doc: Doc
, opts: {saveAsNewFile?: boolean} = {}
) => {
const filePath = await showDialog(win, doc, opts.saveAsNewFile)

if (!filePath) {
return
}

try {
await promisify(writeFile)(filePath, doc.md)

const fileName = pathToName(filePath)
win.setTitle(fileName)
win.setRepresentedFilename(filePath)

ipc.sendMessage(win, {
type: 'updateDoc'
, doc: { fileName, filePath, fileDirty: false }
})

addToRecentFiles(filePath)
} catch (err) {
dialog.showMessageBox(win, {
type: 'error'
, message: 'Could not save file'
, detail: err.message
})
}
}

const showDialog = async (win: BrowserWindow, doc: Doc, saveAsNewFile?: boolean) => {
// TODO: should we save the filePath on `win` in the main process
// instead of risk it being tampered with in the renderer process?
let { filePath } = doc
if (filePath === undefined || saveAsNewFile) {
const res = await dialog.showSaveDialog(win, {
defaultPath: 'Untitled.md'
, filters: [
{ name: 'Markdown', extensions: ['md', 'txt', 'markdown'] }
]
})
filePath = res.filePath
}
return filePath
}

const pathToName = (filePath: string) =>
basename(filePath, extname(filePath))
54 changes: 54 additions & 0 deletions electron/ipc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { BrowserWindow, ipcMain, shell } from 'electron'
import { Doc } from '../src/appState/AppState'
import { Message } from './preload'

// this file contains the IPC functionality of the main process.
// for the renderer process's part see electron/preload.ts

export const init = () => {
ipcMain.on('close', (event) => {
const win = BrowserWindow.fromWebContents(event.sender)
win?.close()
})

ipcMain.on('minimize', (event) => {
const win = BrowserWindow.fromWebContents(event.sender)
win?.minimize()
})

ipcMain.on('maximize', (event) => {
const win = BrowserWindow.fromWebContents(event.sender)
// win.isMaximized() ? win.unmaximize() : win.maximize()
win?.setFullScreen( !win.isFullScreen() )
})

ipcMain.on('openLink', (_event, link: string) => {
shell.openExternal(link)
})
}

export const getDoc = async (win: BrowserWindow): Promise<Doc> => {
const replyChannel = 'getDoc' + Math.random().toString()
win.webContents.send('getDoc', replyChannel)
return new Promise(resolve => {
ipcMain.once(replyChannel, (_event, doc) => {
resolve(doc)
})
})
}

export const sendMessage = (win: BrowserWindow, msg: Message) => {
win.webContents.send('dispatch', msg)
}

export const sendPlatform = (win: BrowserWindow) => {
win.webContents.send('sendPlatform', process.platform)
}

export type Command = 'printFile'
| 'find' | 'findNext' | 'findPrevious'
| 'addBold' | 'addItalic' | 'addStrikethrough'

export const sendCommand = (win: BrowserWindow, cmd: Command) => {
win.webContents.send(cmd)
}
Loading