@@ -21,33 +21,71 @@ function createWindow() {
21
21
contextIsolation : false ,
22
22
} ,
23
23
} ) ;
24
- electronDL ( ) ;
25
24
26
- // Rest of your code...
27
-
28
- function downloadBatchFile ( ) {
29
- const downloadURL =
30
- "https://raw.githubusercontent.com/Parcoil/Sparkle/main/update.bat" ;
25
+ function downloadAndExtractSparkle ( ) {
26
+ const downloadURL = `https://github.com/Parcoil/Sparkle/releases/latest/download/win-unpacked.zip` ;
31
27
const downloadDir = app . getPath ( "userData" ) ;
32
- const downloadPath = path . join ( downloadDir , "update.bat" ) ;
33
-
34
- electronDL
35
- . download ( BrowserWindow . getFocusedWindow ( ) , downloadURL , {
36
- directory : downloadDir ,
37
- filename : "update.bat" , // Set the desired filename
38
- overwrite : true , // Overwrite the file if it already exists
39
- } )
40
- . then ( ( dl ) => {
41
- console . log ( `Downloaded to ${ dl . getSavePath ( ) } ` ) ;
42
-
43
- // Run the downloaded batch file as administrator
44
- runBatFile ( dl . getSavePath ( ) ) ;
45
- } )
46
- . catch ( ( error ) => {
47
- console . error ( `Error downloading the file: ${ error } ` ) ;
28
+ const downloadPath = path . join ( downloadDir , "win-unpacked.zip" ) ;
29
+ const extractionPath = `C:\\Users\\${ process . env . USERNAME } \\AppData\\Local\\Programs\\sparkle` ;
30
+
31
+ // Kill the Sparkle.exe process twice before downloading
32
+ killSparkleProcess ( ( ) => {
33
+ killSparkleProcess ( ( ) => {
34
+ electronDL
35
+ . download ( BrowserWindow . getFocusedWindow ( ) , downloadURL , {
36
+ directory : downloadDir ,
37
+ filename : "win-unpacked.zip" ,
38
+ overwrite : true ,
39
+ } )
40
+ . then ( ( dl ) => {
41
+ console . log ( `Downloaded to ${ dl . getSavePath ( ) } ` ) ;
42
+
43
+ // Extract the downloaded zip file to the specified path
44
+ extractZip ( dl . getSavePath ( ) , extractionPath ) ;
45
+
46
+ // You can add further actions here after extraction if needed
47
+ } )
48
+ . catch ( ( error ) => {
49
+ console . error ( `Error downloading the file: ${ error } ` ) ;
50
+ } ) ;
48
51
} ) ;
52
+ } ) ;
53
+ }
54
+
55
+ function extractZip ( zipFilePath , extractionPath ) {
56
+ exec (
57
+ `powershell Expand-Archive -Path "${ zipFilePath } " -DestinationPath "${ extractionPath } " -Force` ,
58
+ ( error , stdout , stderr ) => {
59
+ if ( error ) {
60
+ console . error ( `Error extracting zip: ${ error . message } ` ) ;
61
+ return ;
62
+ }
63
+ if ( stderr ) {
64
+ console . error ( `Zip extraction stderr: ${ stderr } ` ) ;
65
+ return ;
66
+ }
67
+ console . log ( `Zip extracted to ${ extractionPath } ` ) ;
68
+ }
69
+ ) ;
49
70
}
50
71
72
+ function killSparkleProcess ( callback ) {
73
+ // Kill Sparkle.exe process
74
+ exec ( "taskkill /f /im Sparkle.exe" , ( error , stdout , stderr ) => {
75
+ if ( error ) {
76
+ console . error ( `Error killing Sparkle.exe process: ${ error . message } ` ) ;
77
+ }
78
+ if ( stderr ) {
79
+ console . error ( `Sparkle.exe process termination stderr: ${ stderr } ` ) ;
80
+ }
81
+ console . log ( "Sparkle.exe process terminated." ) ;
82
+ callback ( ) ;
83
+ } ) ;
84
+ }
85
+
86
+ // Call the function to initiate the download and extraction process
87
+ downloadAndExtractSparkle ( ) ;
88
+
51
89
// Trigger the batch file download when the app is ready
52
90
53
91
client . on ( "ready" , ( ) => {
@@ -93,7 +131,7 @@ function createWindow() {
93
131
} ) ;
94
132
95
133
ipcMain . on ( "run-update-batch" , ( ) => {
96
- downloadBatchFile ( ) ;
134
+ downloadAndExtractSparkle ( ) ;
97
135
} ) ;
98
136
99
137
const batFilePath =
0 commit comments