Skip to content

Commit a43e991

Browse files
committed
Cleanup and refactor, completed switch to vanilla codemirror and showdown, render markdown and sync checkbox with source markdown, added hotkey (ctrl+shift+a) to toggle, move and focus window. added a tray icon, window now closes to tray by default.
1 parent 3310b82 commit a43e991

File tree

13 files changed

+293
-236
lines changed

13 files changed

+293
-236
lines changed

public/style.css

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,81 @@ body {
66
#app {
77
background: #f1ea99;
88
width: 100vw;
9-
height: 98vh;
10-
margin-top:5px;
9+
height: 100vh;
1110
border-radius: 5px;
1211
}
1312

1413
.cm-s-default{
1514
background:transparent !important;
1615
}
17-
/* .editor .tuieditor .CodeMirror .tui-editor-defaultUI */
18-
#app #home{
16+
17+
#home {
1918
font-family: 'Avenir', Helvetica, Arial, sans-serif;
2019
-webkit-font-smoothing: antialiased;
2120
-moz-osx-font-smoothing: grayscale;
2221
color: #2c3e50;
2322
width: 100vw;
24-
height: 88vh;
25-
background:transparent !important;
26-
background-color:transparent !important;
23+
height: 100vh;
2724
}
2825

29-
.te-editor, .te-ww-container, .editor{
30-
width: 100% !important;
26+
27+
#renderContainer, .cm-s-default{
28+
top:0px;
29+
margin-top:0px;
30+
padding:0px;
31+
height: 100%;
32+
width:100%;
3133
position: absolute;
32-
background:transparent !important;
33-
background-color:transparent !important;
3434
}
3535

36+
#renderContainer * {
37+
margin:3pt;
38+
}
3639

37-
.te-toolbar-section, .te-preview, .te-md-splitter{
38-
display: none !important;
39-
}
40+
#renderContainer li{
41+
margin:0;
42+
}
4043

41-
.CodeMirror .tui-editor-defaultUI{
42-
height: 100%;
44+
#renderContainer ul ul{
45+
padding-left:10pt;
46+
}
47+
48+
#renderContainer{
49+
font-size: 10pt;
50+
}
51+
52+
.CodeMirror{
53+
height: 94vh !important;
54+
}
55+
56+
.editor{
57+
position: absolute;
58+
top:6vh;
59+
height: 94vh;
60+
width: 100vw;
4361
}
4462

4563
#NavBar {
46-
height: 20px;
4764
background: #2c3e50;
4865
border-radius: 5px 5px 0px 0px;
49-
padding: 10px 10px 10px 5px;
66+
padding: 0.75vh 2vw 0.5vh 2vw;
67+
/* 10px 10px 10px 5px; */
68+
height:4vh;
5069
-webkit-app-region: drag;
70+
font-size: 8pt;
5171
}
72+
5273
#NavBar a{
5374
font-weight: bold;
5475
color: #fff;
55-
padding-left: 10px;
5676
text-decoration: none;
5777
-webkit-app-region: none;
5878
}
5979

80+
#NavBar span a{
81+
padding-left: 7px;
82+
}
83+
6084
#NavBar #controls a {
6185
float: right;
6286
}
@@ -71,22 +95,24 @@ body {
7195
border-bottom: 3px dashed lightblue;
7296
background: none;
7397
color: white;
74-
width:20%;
98+
width:25%;
99+
margin-right: 7px;
75100
text-overflow: ellipsis;
76101
white-space: nowrap;
77102
overflow: hidden;
103+
font-size: inherit;
78104
}
79105

80106
#NavBar select {
81107
border:none;
82108
background: #2c3e50;
83109
color: white;
110+
width:25%;
84111
border-bottom: 3px solid lightblue;
85-
width:20%;
86112
text-overflow: ellipsis;
87113
white-space: nowrap;
88114
overflow: hidden;
89-
left: 0;
115+
font-size: inherit;
90116
}
91117

92118
#NavBar option{
@@ -117,4 +143,5 @@ body {
117143

118144
#settings form{
119145
padding:10px;
120-
}
146+
}
147+

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<div id="app">
33
<router-view/>
44
</div>
5-
</template>
5+
</template>

src/background.ts

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
'use strict'
2-
3-
import { app, protocol, BrowserWindow, Config, screen, shell } from 'electron'
4-
import {
5-
createProtocol,
6-
installVueDevtools
7-
} from 'vue-cli-plugin-electron-builder/lib'
8-
const isDevelopment = process.env.NODE_ENV !== 'production'
9-
// Keep a global reference of the window object, if you don't, the window will
1+
'use strict';
2+
import { app, protocol, BrowserWindow, Config, screen, shell, globalShortcut, ipcMain, Tray, Menu } from 'electron';
3+
import {createProtocol, installVueDevtools} from 'vue-cli-plugin-electron-builder/lib';
4+
const isDevelopment = process.env.NODE_ENV !== 'production';
5+
// Keep a global reference of the window and tray objects else they will
106
// be closed automatically when the JavaScript object is garbage collected.
11-
let win;
7+
let win: BrowserWindow;
8+
let tray: Tray;
129

13-
// Standard scheme must be registered before the app is ready
1410
protocol.registerStandardSchemes(['app'], { secure: true })
11+
1512
function createWindow() {
16-
// Create the browser window.
13+
1714
win = new BrowserWindow({
18-
minWidth: 230,
15+
minWidth: 265,
1916
width: 400,
2017
height: 400,
2118
minHeight: 400,
@@ -26,93 +23,104 @@ function createWindow() {
2623
});
2724

2825
if (process.env.WEBPACK_DEV_SERVER_URL) {
29-
// Load the url of the dev server if in development mode
30-
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL as string)
31-
if (!process.env.IS_TEST) win.webContents.openDevTools()
32-
} else {
33-
createProtocol('app')
34-
// Load the index.html when not in development
35-
win.loadURL('app://./index.html')
26+
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL as string);
27+
if (!process.env.IS_TEST) win.webContents.openDevTools();
28+
}
29+
else {
30+
createProtocol('app');
31+
win.loadURL('app://./index.html');
3632
}
3733

38-
win.on('closed', () => {
39-
win = null
34+
win.on('close', (e) => {
35+
e.preventDefault();
36+
console.log("test")
37+
win.hide();
4038
})
4139

42-
win.webContents.on('new-window', function(e, url){
40+
win.on('closed', (e) => {
41+
(<any>win) = null;
42+
})
43+
44+
win.webContents.on('new-window', function (e, url) {
4345
e.preventDefault();
4446
shell.openExternal(url);
45-
});
46-
47+
});
4748
}
4849

49-
50-
// Quit when all windows are closed.
5150
app.on('window-all-closed', () => {
52-
// On macOS it is common for applications and their menu bar
53-
// to stay active until the user quits explicitly with Cmd + Q
5451
if (process.platform !== 'darwin') {
55-
app.quit()
52+
app.quit();
5653
}
5754
})
5855

5956
app.on('activate', () => {
60-
// On macOS it's common to re-create a window in the app when the
61-
// dock icon is clicked and there are no other windows open.
6257
if (win === null) {
63-
createWindow()
58+
createWindow();
6459
}
6560
})
6661

67-
// This method will be called when Electron has finished
68-
// initialization and is ready to create browser windows.
69-
// Some APIs can only be used after this event occurs.
7062
app.on('ready', async () => {
7163
if (isDevelopment && !process.env.IS_TEST) {
72-
// Install Vue Devtools
73-
await installVueDevtools()
64+
await installVueDevtools();
7465
}
66+
globalShortcut.register('CommandOrControl+Shift+A', () => {
67+
if (win.isFocused() && !win.isAlwaysOnTop()) {
68+
win.minimize();
69+
} else {
70+
win.restore();
71+
win.focus();
72+
ipcMain.emit("FocusEditor");
73+
moveWindow();
74+
}
75+
})
76+
createTray()
7577
createWindow();
7678
moveWindow();
7779
})
7880

81+
function createTray() {
82+
tray = new Tray(require('path').join(__dirname, '/assets/icon.ico'));
83+
const contextMenu = Menu.buildFromTemplate([
84+
{ label: 'Restore', click: _ => win.show() },
85+
{ label: 'Quit', click: _ => { win.destroy(); app.quit() } }
86+
])
87+
tray.setContextMenu(contextMenu);
88+
}
89+
7990
var locked = app.requestSingleInstanceLock();
8091
if (!locked) {
81-
app.quit()
92+
app.quit();
8293
} else {
83-
app.on('second-instance', (event, commandLine, workingDirectory) => {
84-
// Someone tried to run a second instance, we should focus our window.
94+
app.on('second-instance', _ => {
8595
if (win) {
86-
if (win.isMinimized()) win.restore()
96+
if (win.isMinimized()) win.restore();
8797
moveWindow();
88-
win.focus()
98+
win.focus();
8999
}
90100
})
91101
}
92102

93-
function moveWindow(){
94-
103+
function moveWindow() {
104+
if (!win.isVisible) win.show();
95105
let mousePos = screen.getCursorScreenPoint();
96106
let bounds = screen.getDisplayNearestPoint(mousePos).bounds;
97107
let winBounds = win.getBounds();
98-
let horizontalBleed = (bounds.x+bounds.width)-winBounds.width
99-
let verticalBleed = (bounds.y+bounds.height)-winBounds.height
100-
win.setPosition(mousePos.x > horizontalBleed ? horizontalBleed : mousePos.x,mousePos.y > verticalBleed ? verticalBleed : mousePos.y)
108+
let horizontalBleed = (bounds.x + bounds.width) - winBounds.width;
109+
let verticalBleed = (bounds.y + bounds.height) - winBounds.height;
110+
win.setPosition(mousePos.x > horizontalBleed ? horizontalBleed : mousePos.x, mousePos.y > verticalBleed ? verticalBleed : mousePos.y);
101111
}
102112

103-
104-
105113
// Exit cleanly on request from parent process in development mode.
106114
if (isDevelopment) {
107115
if (process.platform === 'win32') {
108116
process.on('message', data => {
109117
if (data === 'graceful-exit') {
110-
app.quit()
118+
app.quit();
111119
}
112-
})
120+
});
113121
} else {
114122
process.on('SIGTERM', () => {
115-
app.quit()
116-
})
123+
app.quit();
124+
});
117125
}
118126
}

0 commit comments

Comments
 (0)