1
1
'use strict'
2
2
3
- import { app , protocol , BrowserWindow } from 'electron'
3
+ import { app , protocol , BrowserWindow , Config } from 'electron'
4
4
import {
5
5
createProtocol ,
6
6
installVueDevtools
7
7
} from 'vue-cli-plugin-electron-builder/lib'
8
+ import Configuration from './utility/Configuration' ;
8
9
const isDevelopment = process . env . NODE_ENV !== 'production'
9
- const nativeImage = require ( 'electron' ) . nativeImage ;
10
- // var image = nativeImage.createFromPath(__dirname + '/assets/icon.png');
11
- // image.setTemplateImage(true);
12
- // console.log(__dirname + '/assets/icon.png')
13
10
// Keep a global reference of the window object, if you don't, the window will
14
11
// be closed automatically when the JavaScript object is garbage collected.
15
12
let win ;
16
13
17
14
// Standard scheme must be registered before the app is ready
18
15
protocol . registerStandardSchemes ( [ 'app' ] , { secure : true } )
19
- function createWindow ( ) {
16
+ function createWindow ( ) {
20
17
// Create the browser window.
21
- win = new BrowserWindow ( {
22
- minWidth :230 ,
23
- width :400 ,
24
- height :400 ,
25
- minHeight :400 ,
26
- autoHideMenuBar : true ,
27
- transparent : true ,
18
+ win = new BrowserWindow ( {
19
+ minWidth : 230 ,
20
+ width : 400 ,
21
+ height : 400 ,
22
+ minHeight : 400 ,
23
+ autoHideMenuBar : true ,
24
+ transparent : true ,
28
25
frame : false ,
29
- resizable :true
30
- } )
26
+ resizable : true
27
+ } ) ;
31
28
32
29
if ( process . env . WEBPACK_DEV_SERVER_URL ) {
33
30
// Load the url of the dev server if in development mode
@@ -43,7 +40,42 @@ function createWindow () {
43
40
win = null
44
41
} )
45
42
}
43
+ import * as fs from 'fs' ;
44
+ import * as path from 'path' ;
45
+ function ensureExists ( callback ) {
46
+ Configuration . getConfig ( ) . then ( c => {
47
+ fs . exists ( c . notePath , folderExists => {
48
+ if ( ! folderExists ) {
49
+ createDirectory ( c , _ => {
50
+ createDefault ( c , _ => callback ( ) ) ;
51
+ } )
52
+ } else {
53
+ fs . exists ( path . join ( c . notePath , c . defaultNote ) , fileExists => {
54
+ if ( ! fileExists ) createDefault ( c , _ => callback ( ) )
55
+ else callback ( ) ;
56
+ } )
57
+ } ;
58
+ } )
59
+ } ) ;
60
+ }
61
+
62
+ function createDirectory ( config : Configuration , callback ) {
63
+ fs . mkdir ( config . notePath , e => {
64
+ if ( e ) {
65
+ console . log ( e ) ;
66
+ alert ( e ) ;
67
+ process . exit ( ) ;
68
+ } else {
69
+ callback ( e ) ;
70
+ }
71
+ } ) ;
72
+ }
46
73
74
+ function createDefault ( config : Configuration , callback ) {
75
+ fs . writeFile ( path . join ( config . notePath , config . defaultNote ) , "# Welcome to your new note!\nLet's write something awesome." , e => {
76
+ callback ( e )
77
+ } )
78
+ }
47
79
48
80
// Quit when all windows are closed.
49
81
app . on ( 'window-all-closed' , ( ) => {
@@ -70,7 +102,10 @@ app.on('ready', async () => {
70
102
// Install Vue Devtools
71
103
await installVueDevtools ( )
72
104
}
73
- createWindow ( )
105
+
106
+ ensureExists ( function ( ) {
107
+ createWindow ( )
108
+ } )
74
109
} )
75
110
76
111
// Exit cleanly on request from parent process in development mode.
0 commit comments