Quellcode durchsuchen

Merge branch 'master' of https://github.com/heapsio/hide

clandrin vor 4 Jahren
Ursprung
Commit
697946870d
2 geänderte Dateien mit 20 neuen und 3 gelöschten Zeilen
  1. 1 2
      hide/Ide.hx
  2. 19 1
      hide/tools/FileWatcher.hx

+ 1 - 2
hide/Ide.hx

@@ -824,8 +824,7 @@ class Ide {
 	}
 
 	public function getUnCachedUrl( path : String ) {
-		var timestamp = Std.int(Date.now().getTime() / 1000);
-		return "file://" + getPath(path) + "?t=" + timestamp;
+		return "file://" + getPath(path) + "?t=" + fileWatcher.getVersion(path);
 	}
 
 	public static var IMG_EXTS = ["jpg", "jpeg", "gif", "png", "raw", "dds", "hdr", "tga"];

+ 19 - 1
hide/tools/FileWatcher.hx

@@ -5,7 +5,14 @@ typedef FileWatchEvent = {path:String,fun:Void->Void,checkDel:Bool,element:js.ht
 class FileWatcher {
 
 	var ide : hide.Ide;
-	var watches : Map<String,{ events : Array<FileWatchEvent>, w : js.node.fs.FSWatcher, wasChanged : Bool, changed : Bool, isDir : Bool }> = new Map();
+	var watches : Map<String, {
+		events : Array<FileWatchEvent>,
+		w : js.node.fs.FSWatcher,
+		wasChanged : Bool,
+		changed : Bool,
+		isDir : Bool,
+		version : Int
+	}> = new Map();
 	var timer : haxe.Timer;
 
 	public function new() {
@@ -32,6 +39,7 @@ class FileWatcher {
 	}
 
 	public function register( path : String, updateFun, ?checkDelete : Bool, ?element : Element ) : FileWatchEvent {
+		path = ide.getPath(path);
 		var w = getWatches(path);
 		var f : FileWatchEvent = { path : path, fun : updateFun, checkDel : checkDelete, element : element == null ? null : element[0] };
 		w.events.push(f);
@@ -43,6 +51,7 @@ class FileWatcher {
 	}
 
 	public function unregister( path : String, updateFun : Void -> Void ) {
+		path = ide.getPath(path);
 		var w = getWatches(path);
 		for( e in w.events )
 			if( Reflect.compareMethods(e.fun, updateFun) ) {
@@ -67,6 +76,13 @@ class FileWatcher {
 		}
 	}
 
+	public function getVersion( path : String ) : Int {
+		var w = watches.get(ide.getPath(path));
+		if( w == null )
+			return 0;
+		return w.version;
+	}
+
 	function cleanEvents() {
 		for( w in watches )
 			for( e in w.events.copy() )
@@ -94,12 +110,14 @@ class FileWatcher {
 				changed : false,
 				isDir : try sys.FileSystem.isDirectory(fullPath) catch( e : Dynamic ) false,
 				wasChanged : false,
+				version : 0,
 			};
 			w.w = try js.node.Fs.watch(fullPath, function(k:String, file:String) {
 				if( w.isDir && k == "change" ) return;
 				if( k == "change" ) w.wasChanged = true;
 				if( w.changed ) return;
 				w.changed = true;
+				w.version++;
 				haxe.Timer.delay(function() {
 					if( !w.changed ) return;
 					w.changed = false;