11import fs from 'node:fs' ;
22import path from 'node:path' ;
33import type { Metas } from './types.js' ;
4- import { Script } from './models/Script.js' ;
4+ import { Script , type ScriptArguments } from './models/Script.js' ;
55import { defaultScriptPath , metaEndTerm , metaStartTerm } from './const.js' ;
66import { matchesMetas , stringRange } from './utils/utils.js' ;
77import { ScriptExecution } from './models/ScriptExecution.js' ;
8+ import { Clipboard } from './utils/clipboard.js' ;
9+ import { FlowLauncher } from './utils/flowLauncher.js' ;
810
911export class ScriptManager {
1012 scripts : Script [ ] ;
@@ -15,6 +17,7 @@ export class ScriptManager {
1517
1618 init ( ) {
1719 this . loadDefaultScripts ( ) ;
20+ //TODO: Manage users scripts
1821 }
1922
2023 loadDefaultScripts ( ) {
@@ -71,9 +74,33 @@ export class ScriptManager {
7174 return results . sort ( metaNameSort ) ;
7275 }
7376
77+ runScriptM ( scriptArguments : ScriptArguments ) {
78+ // Get clipboard content
79+ const clip = Clipboard . get ( ) ;
80+
81+ const script = new Script ( scriptArguments ) ;
82+
83+ const result = this . runScript ( script , clip ) ;
84+
85+ this . replaceText ( result , clip ) ;
86+ }
87+
7488 runScript ( script : Script , text : string ) {
7589 let scriptExecution = new ScriptExecution ( { text : text } ) ;
90+
7691 script . run ( scriptExecution ) ;
77- return scriptExecution . text ;
92+
93+ return scriptExecution . text ?? '' ;
94+ }
95+
96+ replaceText ( newText : string , originText : string ) {
97+ if ( newText !== originText ) {
98+ // Update clipboard with new value
99+ Clipboard . copy ( newText ) ;
100+
101+ //TODO: Possibly change location in futur
102+ // Notify User from change
103+ FlowLauncher . showMessage ( 'test' ) ;
104+ }
78105 }
79106}
0 commit comments