Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Shvets committed Feb 11, 2018
1 parent 0995f95 commit a50650c
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 35 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
<h2 align="center">
<a href="//github.com/alexander-shvets/writebar/releases">Downloads</a>
/
<a href="dist/WriteBar.dmg">v0.2.0-beta.dmg</a>
<a href="dist/WriteBar.dmg">v0.2.1-beta.dmg</a>
</h2>
<p align="center"><img width="600" src="assets/screenshot.jpg" alt="screenshot"/></p>

### Discuss

- [Intro Video post @ Facebook UX Club](//facebook.com/groups/uxclubs/permalink/973396292808999/)
- [Development direction voting @ Twitter](https://twitter.com/YodaKiev/status/961870873530544128)
- [Feature Requests and Issues @ GitHub](//github.com/alexander-shvets/writebar/issues)

## Development
Expand Down Expand Up @@ -55,7 +54,7 @@ yarn start

Build app and Installer:
```shell
yarn build
yarn packdist
```
Release files generated in [`dist`][] directory.

Expand Down
Binary file modified dist/WriteBar.dmg
Binary file not shown.
5 changes: 2 additions & 3 deletions src/main.js → main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let mainWindow
function createWindow () {
mainWindow = new BrowserWindow({
title: 'WriteBar',
icon: path.join(__dirname, '..', 'assets', 'logo.ico'),
icon: path.join(__dirname, 'assets', 'logo.icns'),

width: 580, height: 500,
minWidth: 260, minHeight: 200,
Expand All @@ -28,11 +28,10 @@ function createWindow () {
defaultFontSize: 18,
},
})
//let worker = new Worker('script.js')

// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'editor.html'),
pathname: path.join(__dirname, 'src', 'editor.html'),
protocol: 'file:',
slashes: true
}))
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"name": "writebar",
"productName": "WriteBar",
"version": "0.2.0",
"version": "0.2.1",
"description": "Distraction-free text editor, based on the Macbook pro TouchBar",
"author": "Alexander Shvets (https://github.com/alexander-shvets)",
"private": true,
"main": "src/main.js",
"main": "main.js",
"scripts": {
"start": "electron .",
"build": "yarn run build-package && yarn run build-installer",
"build-package": "electron-packager . --out=./dist/ --icon=./assets/logo.icns --overwrite=true --electronVersion=1.7.12 --packageManager=yarn --appCategoryType=public.app-category.productivity --osxSign && cp -R ./node_modules/* ./dist/*-darwin-*/*.app/Contents/Resources/app/node_modules/",
"build-installer": "cd ./dist && electron-installer-dmg ./*-darwin-*/*.app WriteBar --icon=../assets/logo.icns --overwrite"
"packdist": "yarn run pack && yarn run dist",
"pack": "electron-packager . --out=./dist/ --icon=./assets/logo.icns --overwrite=true --electronVersion=1.7.12 --packageManager=yarn --appCategoryType=public.app-category.productivity && cp -R ./node_modules/* ./dist/*-darwin-*/*.app/Contents/Resources/app/node_modules/",
"dist": "cd ./dist && electron-installer-dmg ./*-darwin-*/*.app WriteBar --icon=../assets/logo.icns --overwrite"
},
"dependencies": {
"@slite/quill-delta-markdown": "alexjohnporter/quill-delta-markdown",
"quill": "^1.3.5",
"quill-focus": "amka/quill-focus",
"quill-markdown-shortcuts": "patleeman/quill-markdown-shortcuts"
Expand Down
3 changes: 3 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const quill = new Quill('#editor', {
})
quill.focus()
//window.onfocus =()=> quill.focus()

window.quill = quill
window.documentNotSaved = true

Menu.setApplicationMenu(Menu.buildFromTemplate( menu ))

Expand All @@ -37,6 +39,7 @@ quill.on('editor-change', (eventName, ...args) => {

if (eventName === 'text-change') {

window.documentNotSaved = true
getCurrentWindow().setDocumentEdited( true )

// args[0] will be delta
Expand Down
59 changes: 40 additions & 19 deletions src/file-menu.js → src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
// webContents: {getFocusedWebContents},
// } = require('electron')
const fs = require('fs')
const {remote} = require('electron')
const { app, getCurrentWindow,
webContents: {getFocusedWebContents},
dialog: {showOpenDialog, showSaveDialog},
} = require('electron').remote
webContents:{ getFocusedWebContents },
dialog:{ showOpenDialog, showSaveDialog },
} = remote

const { fromDelta } = remote.require('@slite/quill-delta-markdown')
const { toDelta } = remote.require('@slite/quill-delta-markdown')

module.exports.fileMenu = {
label: 'File',
submenu: [
{label: 'New', accelerator: 'CmdOrCtrl+N', click: newFile},
{label: 'Open...', accelerator: 'CmdOrCtrl+O', click: openFile},
{role: 'recentDocuments'},
{role: 'clearRecentDocuments'},
// {role: 'recentDocuments'},
// {role: 'clearRecentDocuments'},
{type: 'separator'},
{label: 'Save', accelerator: 'CmdOrCtrl+S', click: saveFile},
{label: 'Save As...', accelerator: 'CmdOrCtrl+Shift+S', click: saveFileAs},
Expand All @@ -32,17 +36,19 @@ module.exports.fileMenu = {
let loadedFile

const options = {
filters: [
{ name: 'txt', extensions: ['txt'] },
{ name: 'html', extensions: ['html'] },
]
// filters: [
// { name: 'txt', extensions: ['txt'] },
// { name: 'html', extensions: ['html'] },
// ]
}
const markdown = /(\/readme|\.(md|markdown))$/i
const html = /\.html?$/i

function newFile(){
if( isSaved() ){
//if( isSaved() ){
loadedFile = null
getFocusedWebContents().reload()
}
//}
}

function saveFileAs() {
Expand All @@ -60,7 +66,8 @@ function saveFile() {
}

function openFile(menu, focusedWindow) {
if( isSaved() ) showOpenDialog(options, ([filename] = []) => {
//if( isSaved() )
showOpenDialog(options, ([filename] = []) => {
if( filename ){
readFromFS( filename )
}
Expand All @@ -78,19 +85,35 @@ function revertFile(menu, focusedWindow){
}

function writeToFS( filename ) {
var html = window.quill.container.firstChild.innerHTML
fs.writeFile(filename, html, console.log)
let raw
if( filename.match(markdown) ){
raw = fromDelta( window.quill.getContents() )
} else if( filename.match(html) ) {
raw = window.quill.container.firstChild.innerHTML
} else {
raw = window.quill.getText()
}
fs.writeFile(filename, raw, () =>
window.documentNotSaved = false)
}

function readFromFS( filename ) {
fs.readFile(filename, "utf-8", (err, data) => {
if( err ){
console.log(err)
} else {
//window.quill.setText(data)
window.quill.container.firstChild.innerHTML = data
if( filename.match(markdown) ){
window.quill.setContents( toDelta(data) )
} else if( filename.match(html) ) {
//window.quill.setText(data)
window.quill.container.firstChild.innerHTML = data
} else {
window.quill.setText( data )
}

if( loadedFile != filename ){
loadedFile = filename
window.documentNotSaved = false
app.addRecentDocument( loadedFile )
getCurrentWindow().setRepresentedFilename( loadedFile )
}
Expand All @@ -99,7 +122,5 @@ function readFromFS( filename ) {
}

function isSaved(){
//const win = getCurrentWindow()
return !!//win && win.getDocumentEdited() &&
confirm("Document isn't saved. Do you want discard changes?")
return documentNotSaved && confirm("Document isn't saved. Do you want discard changes?")
}
19 changes: 15 additions & 4 deletions src/menu.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
const {shell:{ openExternal }} = require('electron')
const {shell:{ openExternal },remote:{ app }} = require('electron')

const {fileMenu} = require('./file-menu')
const {spellcheckMenu} = require('./spellcheck-menu')
const {fileMenu} = require('./file')
const {spellcheckMenu} = require('./spellcheck')

module.exports.menu = [

{label: 'WriteBar',//app.getName(),
{label: app.getName(),
submenu: [
{role: 'about'},

{type: 'separator'},
{role: 'services'},
{type: 'separator'},

{role: 'hideothers'},
{role: 'hide'},
{role: 'unhide'},

{type: 'separator'},

{role: 'quit'},
]
},
Expand Down
File renamed without changes.
39 changes: 38 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,35 @@
# yarn lockfile v1


"@slite/quill-delta-markdown@alexjohnporter/quill-delta-markdown":
version "0.0.8"
resolved "https://codeload.github.com/alexjohnporter/quill-delta-markdown/tar.gz/796acf9e6b9397cc3c4ab020841101ae06ae3c14"
dependencies:
commonmark "^0.26.0"
lodash "^4.16.4"
quill-delta "^3.4.0"

clone@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.1.tgz#d217d1e961118e3ac9a4b8bba3285553bf647cdb"

commonmark@^0.26.0:
version "0.26.0"
resolved "https://registry.yarnpkg.com/commonmark/-/commonmark-0.26.0.tgz#216e8f2f2bc7306c002a73aaa4edb64609e26457"
dependencies:
entities "~ 1.1.1"
mdurl "~ 1.0.1"
minimist "~ 1.2.0"
string.prototype.repeat "^0.2.0"

deep-equal@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5"

"entities@~ 1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0"

eventemitter3@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-2.0.3.tgz#b5e1079b59fb5e1ba2771c0a993be060a58c99ba"
Expand All @@ -22,11 +43,23 @@ [email protected]:
version "1.1.2"
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.1.2.tgz#4b62c42b8e03de3f848460b639079920695d0154"

lodash@^4.16.4:
version "4.17.5"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"

"mdurl@~ 1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"

"minimist@~ 1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

parchment@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/parchment/-/parchment-1.1.3.tgz#c0fd5c2765eb73b30bfe171d6567cb1ae748e9af"

quill-delta@^3.6.2:
quill-delta@^3.4.0, quill-delta@^3.6.2:
version "3.6.2"
resolved "https://registry.yarnpkg.com/quill-delta/-/quill-delta-3.6.2.tgz#76eed0163b8b09a076fba6ade29307c42b40b8d8"
dependencies:
Expand All @@ -52,3 +85,7 @@ quill@^1.3.5:
extend "^3.0.1"
parchment "^1.1.3"
quill-delta "^3.6.2"

string.prototype.repeat@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/string.prototype.repeat/-/string.prototype.repeat-0.2.0.tgz#aba36de08dcee6a5a337d49b2ea1da1b28fc0ecf"

0 comments on commit a50650c

Please sign in to comment.