'From Pharo6.0 of 13 May 2016 [Latest update: #60497] on 6 June 2017 at 2:59:55.736131 pm'! StringMorph subclass: #MyFileWatcher instanceVariableNames: 'file mutex firstLine process' classVariableNames: '' poolDictionaries: '' category: '_UnpackagedPackage'! !MyFileWatcher commentStamp: 'SvenVanCaekenberghe 6/6/2017 14:59' prior: 0! MyFileWatcher open Shows the contents of the first line of the temp file 'watched-file.txt'. Updates using a background process every 3 seconds.! !MyFileWatcher methodsFor: 'accessing' stamp: 'SvenVanCaekenberghe 6/6/2017 14:01'! firstLine ^ mutex critical: [ firstLine ifNil: [ 'file is empty' ] ]! ! !MyFileWatcher methodsFor: 'accessing' stamp: 'SvenVanCaekenberghe 6/6/2017 14:50'! firstLine: string mutex critical: [ firstLine := string ]! ! !MyFileWatcher methodsFor: 'initialize' stamp: 'SvenVanCaekenberghe 6/6/2017 14:47'! initialize super initialize. file := FileLocator temp / 'watched-file.txt'. file ensureCreateFile. mutex := Semaphore forMutualExclusion. self announcer when: MorphDeleted do: [ self stop ]. self updateFirstLineDisplay. self start! ! !MyFileWatcher methodsFor: 'running' stamp: 'SvenVanCaekenberghe 6/6/2017 14:33'! run [ self updateFirstLine. 3 seconds wait ] repeat! ! !MyFileWatcher methodsFor: 'running' stamp: 'SvenVanCaekenberghe 6/6/2017 14:53'! start self stop. process := [ self run ] forkAt: Processor userBackgroundPriority named: 'MyFileWatcher updater'! ! !MyFileWatcher methodsFor: 'running' stamp: 'SvenVanCaekenberghe 6/6/2017 14:06'! stop process ifNil: [ ^ self ]. process terminate. process := nil! ! !MyFileWatcher methodsFor: 'private' stamp: 'SvenVanCaekenberghe 6/6/2017 14:16'! updateFirstLineDisplay self contents: file pathString , ':1=' , self firstLine! ! !MyFileWatcher methodsFor: 'private' stamp: 'SvenVanCaekenberghe 6/6/2017 14:54'! updateFirstLine file exists ifFalse: [ ^ self firstLine: nil ]. file contents lines ifEmpty: [ self firstLine: nil ] ifNotEmpty: [ :lines | self firstLine: lines first ]! ! !MyFileWatcher methodsFor: 'stepping and presenter' stamp: 'SvenVanCaekenberghe 6/6/2017 14:04'! step self updateFirstLineDisplay! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! MyFileWatcher class instanceVariableNames: ''! !MyFileWatcher class methodsFor: 'system startup' stamp: 'SvenVanCaekenberghe 6/6/2017 14:00'! shutDown self allInstancesDo: #stop! ! !MyFileWatcher class methodsFor: 'system startup' stamp: 'SvenVanCaekenberghe 6/6/2017 14:00'! startUp self allInstancesDo: #start! ! !MyFileWatcher class methodsFor: 'class initialization' stamp: 'SvenVanCaekenberghe 6/6/2017 14:00'! initialize SessionManager default registerUserClassNamed: self name! ! !MyFileWatcher class methodsFor: 'instance creation' stamp: 'SvenVanCaekenberghe 6/6/2017 13:50'! open "self open" ^ self new openInWindow setLabel: 'MyFileWatcher'. ! ! MyFileWatcher initialize!