Added the support for a the client updater
This commit is contained in:
		
							parent
							
								
									3611718bc7
								
							
						
					
					
						commit
						ea6e37e4f1
					
				
							
								
								
									
										2
									
								
								github
									
									
									
									
									
								
							
							
								
								
								
								
								
								
									
									
								
							
						
						
									
										2
									
								
								github
									
									
									
									
									
								
							| @ -1 +1 @@ | ||||
| Subproject commit 16aeb7e7c75fb3af0b5238a093074497d02ec7c4 | ||||
| Subproject commit 27579459d13317200cb9d49f2908b92c22031b11 | ||||
							
								
								
									
										140
									
								
								modules/renderer/ClientUpdater.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								modules/renderer/ClientUpdater.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,140 @@ | ||||
| import * as electron from "electron"; | ||||
| import * as path from "path"; | ||||
| import * as fs from "fs-extra"; | ||||
| import {Updater} from "tc-shared/update/Updater"; | ||||
| import {ChangeLog, ChangeSetEntry} from "tc-shared/update/ChangeLog"; | ||||
| 
 | ||||
| function getChangeLogFile() { | ||||
|     const app_path = electron.remote.app.getAppPath(); | ||||
|     if(app_path.endsWith(".asar")) | ||||
|         return path.join(path.dirname(app_path), "..", "ChangeLog.txt"); | ||||
|     else | ||||
|         return path.join(app_path, "github", "ChangeLog.txt"); /* We've the source master :D */ | ||||
| } | ||||
| 
 | ||||
| const EntryRegex = /^([0-9]+)\.([0-9]+)\.([0-9]+)(-b[0-9]+)?:$/m; | ||||
| function parseChangeLogEntry(lines: string[], index: number) : { entries: ChangeSetEntry[], index: number } { | ||||
|     const entryDepth = lines[index].indexOf("-"); | ||||
|     if(entryDepth === -1) { | ||||
|         throw "missing entry depth for line " + index; | ||||
|     } | ||||
| 
 | ||||
|     let entries = [] as ChangeSetEntry[]; | ||||
|     let currentEntry; | ||||
|     while(index < lines.length && !lines[index].match(EntryRegex)) { | ||||
|         let trimmed = lines[index].trim(); | ||||
|         if(trimmed.length === 0) { | ||||
|             index++; | ||||
|             continue; | ||||
|         } | ||||
| 
 | ||||
|         if(trimmed[0] === '-') { | ||||
|             const depth = lines[index].indexOf('-'); | ||||
|             if(depth > entryDepth) { | ||||
|                 if(typeof currentEntry === "undefined") | ||||
|                     throw "missing change child entries parent at line " + index; | ||||
| 
 | ||||
|                 const result = parseChangeLogEntry(lines, index); | ||||
|                 entries.push({ | ||||
|                     changes: result.entries, | ||||
|                     title: currentEntry | ||||
|                 }); | ||||
|                 index = result.index; | ||||
|             } else if(depth < entryDepth) { | ||||
|                 /* we're done with our block */ | ||||
|                 break; | ||||
|             } else { | ||||
|                 /* new entry */ | ||||
|                 if(typeof currentEntry === "string") | ||||
|                     entries.push(currentEntry); | ||||
| 
 | ||||
|                 currentEntry = trimmed.substr(1).trim(); | ||||
|             } | ||||
|         } else { | ||||
|             currentEntry += "\n" + trimmed; | ||||
|         } | ||||
| 
 | ||||
|         index++; | ||||
|     } | ||||
| 
 | ||||
|     if(typeof currentEntry === "string") | ||||
|         entries.push(currentEntry); | ||||
| 
 | ||||
|     return { | ||||
|         index: index, | ||||
|         entries: entries | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| async function parseClientChangeLog() : Promise<ChangeLog> { | ||||
|     let result: ChangeLog = { | ||||
|         currentVersion: "unknown", | ||||
|         changes: [] | ||||
|     } | ||||
| 
 | ||||
|     const lines = (await fs.readFile(getChangeLogFile())).toString("UTF-8").split("\n"); | ||||
|     let index = 0; | ||||
| 
 | ||||
|     while(index < lines.length && !lines[index].match(EntryRegex)) | ||||
|         index++; | ||||
| 
 | ||||
|     while(index < lines.length) { | ||||
|         const [ _, major, minor, patch, build ] = lines[index].match(EntryRegex); | ||||
| 
 | ||||
|         const entry = parseChangeLogEntry(lines, index + 1); | ||||
|         result.changes.push({ | ||||
|             timestamp: major + "." + minor + "." + patch + (build || ""), | ||||
|             changes: entry.entries | ||||
|         }); | ||||
| 
 | ||||
|         index = entry.index; | ||||
|     } | ||||
| 
 | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
| const kLastUsedVersionKey = "updater-used-version-native"; | ||||
| export class ClientUpdater implements Updater { | ||||
|     private changeLog: ChangeLog; | ||||
|     private currentVersion: string; | ||||
| 
 | ||||
|     constructor() { | ||||
|     } | ||||
| 
 | ||||
|     async initialize() { | ||||
|         this.currentVersion = electron.remote.getGlobal("app_version_client"); | ||||
|         this.changeLog = await parseClientChangeLog(); | ||||
|     } | ||||
| 
 | ||||
|     getChangeList(oldVersion: string): ChangeLog { | ||||
|         let changes = { | ||||
|             changes: [], | ||||
|             currentVersion: this.currentVersion | ||||
|         } as ChangeLog; | ||||
| 
 | ||||
|         for(const change of this.getChangeLog().changes) { | ||||
|             if(change.timestamp === oldVersion) | ||||
|                 break; | ||||
| 
 | ||||
|             changes.changes.push(change); | ||||
|         } | ||||
| 
 | ||||
|         return changes; | ||||
|     } | ||||
| 
 | ||||
|     getChangeLog(): ChangeLog { | ||||
|         return this.changeLog; | ||||
|     } | ||||
| 
 | ||||
|     getCurrentVersion(): string { | ||||
|         return this.currentVersion; | ||||
|     } | ||||
| 
 | ||||
|     getLastUsedVersion(): string { | ||||
|         return localStorage.getItem(kLastUsedVersionKey) || "1.4.9"; | ||||
|     } | ||||
| 
 | ||||
|     updateUsedVersion() { | ||||
|         localStorage.setItem(kLastUsedVersionKey, this.getCurrentVersion()); | ||||
|     } | ||||
| } | ||||
| @ -1,4 +0,0 @@ | ||||
| import * as handler from "../connection/ServerConnection"; | ||||
| 
 | ||||
| export const spawn_server_connection = handler.spawn_server_connection; | ||||
| export const destroy_server_connection = handler.destroy_server_connection; | ||||
							
								
								
									
										14
									
								
								modules/renderer/hooks/ChangeLogClient.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								modules/renderer/hooks/ChangeLogClient.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | ||||
| import * as loader from "tc-loader"; | ||||
| import {Stage} from "tc-loader"; | ||||
| import {setNativeUpdater} from "tc-shared/update"; | ||||
| import {ClientUpdater} from "../ClientUpdater"; | ||||
| 
 | ||||
| loader.register_task(Stage.JAVASCRIPT_INITIALIZING, { | ||||
|     name: "web updater init", | ||||
|     function: async () => { | ||||
|         const updater = new ClientUpdater(); | ||||
|         await updater.initialize(); | ||||
|         setNativeUpdater(updater); | ||||
|     }, | ||||
|     priority: 50 | ||||
| }); | ||||
| @ -162,6 +162,7 @@ loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, { | ||||
|             await import("./hooks/AudioInput"); | ||||
|             await import("./hooks/ExternalModal"); | ||||
|             await import("./hooks/ServerConnection"); | ||||
|             await import("./hooks/ChangeLogClient"); | ||||
| 
 | ||||
|             await import("./UnloadHandler"); | ||||
|         } catch (error) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user