3
3
//
4
4
5
5
const electron = require ( 'electron' ) ;
6
- const app = electron . app ;
6
+ const { app} = require ( ' electron' ) ;
7
7
const Menu = electron . Menu ;
8
8
const BrowserWindow = electron . BrowserWindow ;
9
+ const GhReleases = require ( 'electron-gh-releases' ) ;
9
10
const ipc = electron . ipcMain ;
11
+ let splashScreen
10
12
let mainWindow
11
- function createWindow ( ) {
12
- mainWindow = new BrowserWindow ( {
13
- width : 1024 ,
14
- height : 600 ,
15
- minWidth : 1024 ,
16
- icon : __dirname + '/web/img/tgf/icon_circle.png'
17
- } ) ;
18
- mainWindow . loadURL ( `file://${ __dirname } /web/index.html` ) ;
13
+ //retreive package.json properties
14
+ var pjson = require ( './package.json' ) ;
19
15
20
- mainWindow . on ( 'closed' , function ( ) {
21
- // Dereference the window object, usually you would store windows
22
- // in an array if your app supports multi windows, this is the time
23
- // when you should delete the corresponding element.
24
- mainWindow = null
25
- } ) ;
26
- }
27
- app . on ( 'ready' , createWindow ) ;
16
+ console . log ( "Tagifier V." + pjson . version ) ;
17
+
18
+ app . on ( 'ready' , function ( ) {
19
+ createSplashScreen ( ) ;
20
+ } ) ;
28
21
app . on ( 'window-all-closed' , function ( ) {
29
22
if ( process . platform !== 'darwin' ) {
30
23
app . quit ( )
31
24
}
32
- } )
25
+ } ) ;
26
+
27
+ app . on ( 'ready' , ( ) => {
28
+ const { protocol} = require ( 'electron' ) ;
29
+ protocol . registerFileProtocol ( 'tagifier' , ( request , callback ) => {
30
+ console . log ( request ) ;
31
+ const url = request . url . substr ( 7 ) ;
32
+ callback ( { path : path . normalize ( __dirname + '/' + url ) } ) ;
33
+ } , ( error ) => {
34
+ if ( error )
35
+ console . error ( 'Failed to register protocol' ) ;
36
+ } ) ;
37
+ } ) ;
33
38
34
39
app . on ( 'activate' , function ( ) {
35
40
// On OS X it's common to re-create a window in the app when the
36
41
// dock icon is clicked and there are no other windows open.
37
- if ( mainWindow === null ) {
42
+ if ( splashScreen === null ) {
38
43
createWindow ( ) ;
39
44
}
40
45
} ) ;
41
46
47
+
48
+ //
49
+ // Create the splashscreen
50
+ //
51
+ // Also check for update -> Pre-render the app -> show the app
52
+
53
+ function createSplashScreen ( ) {
54
+ splashScreen = new BrowserWindow ( {
55
+ width : 300 ,
56
+ height : 300 ,
57
+ show :false ,
58
+ frame :false ,
59
+ icon : __dirname + '/web/img/tgf/icon_circle.png'
60
+ } ) ;
61
+
62
+ splashScreen . loadURL ( `file://${ __dirname } /web/splash.html` ) ;
63
+
64
+ splashScreen . once ( 'ready-to-show' , ( ) => {
65
+ splashScreen . show ( ) ;
66
+ splashScreen . webContents . send ( "tgf_version" , { version :pjson . version } ) ;
67
+ splashScreen . webContents . send ( "splash_message" , { message :"Checking for update..." } ) ;
68
+
69
+ //check for updates
70
+ let options = {
71
+ repo : 'Cyriaqu3/tagifier' ,
72
+ currentVersion : pjson . version
73
+ }
74
+
75
+ const updater = new GhReleases ( options )
76
+
77
+ // Check for updates
78
+ // `status` returns true if there is a new update available
79
+ updater . check ( ( err , status ) => {
80
+ if ( ! err && status ) {
81
+ ipc . emit ( "splach_message" , { message :"Downloading update..." } ) ;
82
+ // Download the update
83
+ updater . download ( ) ;
84
+
85
+ //no update available, prepare the mainWindow
86
+ } else {
87
+ splashScreen . webContents . send ( "splash_message" , { message :"Loading..." } ) ;
88
+ mainWindow = new BrowserWindow ( {
89
+ show :false ,
90
+ width : 1024 ,
91
+ height : 600 ,
92
+ minWidth : 1024 ,
93
+ icon : __dirname + '/web/img/tgf/icon_circle.png'
94
+ } ) ;
95
+ mainWindow . loadURL ( `file://${ __dirname } /web/index.html` ) ;
96
+ //display the main app and close the
97
+ mainWindow . once ( 'ready-to-show' , ( ) => {
98
+ splashScreen . close ( ) ;
99
+ mainWindow . show ( ) ;
100
+ mainWindow . focus ( ) ;
101
+ } ) ;
102
+ }
103
+ } ) ;
104
+
105
+ // When an update has been downloaded
106
+ updater . on ( 'update-downloaded' , ( info ) => {
107
+ // Restart the app and install the update
108
+ updater . install ( )
109
+ } )
110
+
111
+ // Access electrons autoUpdater
112
+ updater . autoUpdater
113
+
114
+ } ) ;
115
+
116
+ splashScreen . on ( 'closed' , function ( ) {
117
+ splashScreen = null
118
+ } ) ;
119
+ }
120
+
42
121
var fs = require ( 'fs-sync' ) ;
43
122
var ofs = require ( 'fs' ) ; // old fs
44
123
var util = require ( 'util' ) ;
@@ -56,7 +135,7 @@ var sanitize = require("sanitize-filename");
56
135
var ffmpeg = require ( 'fluent-ffmpeg' ) ;
57
136
58
137
//File class
59
- var File = require ( ". /file.js") ;
138
+ var File = require ( __dirname + " /file.js") ;
60
139
//
61
140
62
141
var fidOpt = {
@@ -66,13 +145,13 @@ var fidOpt = {
66
145
67
146
//set the ffmpeg binary location (path)
68
147
if ( os . platform ( ) === 'win32' ) {
69
- var ffmpegPath = '. /bin/ffmpeg/ffmpeg.exe'
148
+ var ffmpegPath = __dirname + ' /bin/ffmpeg/ffmpeg.exe'
70
149
} else {
71
- var ffmpegPath = '. /bin/ffmpeg/ffmpeg'
150
+ var ffmpegPath = __dirname + ' /bin/ffmpeg/ffmpeg'
72
151
}
73
152
ffmpeg . setFfmpegPath ( ffmpegPath ) ;
74
153
// create the "exports" folder
75
- var p = ". /exports";
154
+ var p = __dirname + " /exports";
76
155
if ( ! ofs . existsSync ( p ) ) {
77
156
ofs . mkdirSync ( p ) ;
78
157
}
@@ -141,7 +220,7 @@ ipc.on('processRequest', function (data) {
141
220
session . files . push ( file ) ;
142
221
}
143
222
144
- session . tempPath = ". /exports/"+ session . id ;
223
+ session . tempPath = __dirname + " /exports/"+ session . id ;
145
224
146
225
//create the temp session path
147
226
if ( ! ofs . existsSync ( session . tempPath ) ) {
@@ -277,6 +356,6 @@ var rmDir = function(dirPath, removeSelf) {
277
356
278
357
279
358
280
- rmDir ( '. /web/img/temps', false ) ;
281
- rmDir ( '. /exports', false ) ;
359
+ rmDir ( __dirname + ' /web/img/temps', false ) ;
360
+ rmDir ( __dirname + ' /exports', false ) ;
282
361
console . log ( "Temp files cleaned" ) ;
0 commit comments