1
+ const { surrounding_box } = require ( "../fun/dev-console-ui-utils" ) ;
2
+ const BaseService = require ( "./BaseService" ) ;
3
+
4
+ const SOURCE_CODE_TIPS = `
5
+ Most services are registered in CoreModule.js
6
+ Boot sequence events are different from service events
7
+ ExpectationService exists to ensure Puter doesn't miss a step
8
+ Services are composable; StrategyService is a good example
9
+ API endpoints should be on a separate origin in production
10
+ There is some limited query-building in packages/backend/src/om
11
+ ` ;
12
+
13
+ const tips = (
14
+ // CLI tips
15
+ `
16
+ Type \`help\` to see a list of commands
17
+ \`logs:show\` toggles log output; useful when typing long commands
18
+ \`logs:indent \` toggles indentation for some logs
19
+ \`lock:locks \` will list any active mutex locks
20
+ ` ,
21
+ // Source code tips
22
+ `
23
+ Most services are registered in CoreModule.js
24
+ Boot sequence events are different from service events
25
+ ExpectationService exists to ensure Puter doesn't miss a step
26
+ Services are composable; StrategyService is a good example
27
+ API endpoints should be on a separate origin in production
28
+ These messages come from DevTODService.js
29
+ `
30
+ ) . split ( '\n' ) . map ( ( line ) => line . trim ( ) )
31
+ . filter ( ( line ) => line . length )
32
+ . map ( tip => {
33
+ const lines = [ ] ;
34
+ const WRAP = process . stdout . columns || 50 ;
35
+ while ( tip . length ) {
36
+ lines . push ( tip . substring ( 0 , WRAP ) ) ;
37
+ tip = tip . substring ( WRAP ) ;
38
+ }
39
+ return lines ;
40
+ } )
41
+
42
+ class DevTODService extends BaseService {
43
+ async _init ( ) {
44
+ const svc_commands = this . services . get ( 'commands' ) ;
45
+ this . _register_commands ( svc_commands ) ;
46
+ }
47
+ async [ '__on_boot.consolidation' ] ( ) {
48
+ const random_tip = tips [ Math . floor ( Math . random ( ) * tips . length ) ] ;
49
+ this . tod_widget = ( ) => {
50
+ const lines = [
51
+ "" ,
52
+ "\x1B[1mTip of the Day\x1B[0m" ,
53
+ ...random_tip ,
54
+ "Type tod:dismiss to un-stick this message" ,
55
+ "" ,
56
+ ] ;
57
+ surrounding_box ( '33;1' , lines ) ;
58
+ return lines ;
59
+ }
60
+
61
+ this . tod_widget . unimportant = true ;
62
+
63
+ const svc_devConsole = this . services . get ( 'dev-console' , { optional : true } ) ;
64
+ if ( ! svc_devConsole ) return ;
65
+ svc_devConsole . add_widget ( this . tod_widget ) ;
66
+ }
67
+
68
+ _register_commands ( commands ) {
69
+ commands . registerCommands ( 'tod' , [
70
+ {
71
+ id : 'dismiss' ,
72
+ description : 'Dismiss the startup message' ,
73
+ handler : async ( _ , log ) => {
74
+ const svc_devConsole = this . services . get ( 'dev-console' , { optional : true } ) ;
75
+ if ( ! svc_devConsole ) return ;
76
+ svc_devConsole . remove_widget ( this . tod_widget ) ;
77
+ const lines = this . tod_widget ( ) ;
78
+ for ( const line of lines ) log . log ( line ) ;
79
+ this . tod_widget = null ;
80
+ }
81
+ }
82
+ ] ) ;
83
+ }
84
+ }
85
+
86
+ module . exports = { DevTODService } ;
0 commit comments