Skip to content

Commit b93891d

Browse files
author
arch
committed
update ofs extension to new background process func
1 parent d4119cf commit b93891d

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

contrib/Installer/assets/main.lua

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
-- Version 0.0.1
2-
configFile = ofs.ExtensionDir() .. "/config"
3-
pythonFunscriptGenerator = ofs.ExtensionDir() .. "/funscript-editor/funscript-editor.exe"
1+
-- Version 0.0.2
2+
processHandle = nil
3+
scriptIdx = 0
44

5-
function funscript_generator()
5+
function start_funscript_generator()
6+
scriptIdx = ofs.ActiveIdx()
67
local tmpFile = ofs.ExtensionDir() .. "/funscript_actions.csv"
78
local video = player.CurrentVideo()
8-
local scriptIdx = ofs.ActiveIdx()
99
local script = ofs.Script(scriptIdx)
1010
local currentTimeMs = player.CurrentTime() * 1000
11+
local cmd = ofs.ExtensionDir() .. "/funscript-editor/funscript-editor.exe"
1112

12-
print("funscriptGenerator", pythonFunscriptGenerator)
13+
print("cmd: ", cmd)
1314
print("tmpFile: ", tmpFile)
1415
print("video: ", video)
1516
print("currentScriptIdx: ", scriptIdx)
@@ -20,26 +21,29 @@ function funscript_generator()
2021
next_action = ofs.ClosestActionAfter(script, script.actions[next_action].at / 1000)
2122
end
2223

23-
if next_action then
24-
print("nextAction: ", script.actions[next_action].at)
24+
print("nextAction: ", next_action and tostring(script.actions[next_action].at) or "nil")
25+
26+
if next_action then
27+
processHandle = ofs.CreateProcess(
28+
cmd, "--generator",
29+
"-s", tostring(currentTimeMs),
30+
"-e", tostring(script.actions[next_action].at),
31+
"-i", video,
32+
"-o", tmpFile
33+
)
2534
else
26-
print("nextAction: nil")
35+
processHandle = ofs.CreateProcess(
36+
cmd, "--generator",
37+
"-s", tostring(currentTimeMs),
38+
"-i", video,
39+
"-o", tmpFile
40+
)
2741
end
42+
end
2843

29-
local command = '"'
30-
..pythonFunscriptGenerator
31-
..'" --generator -s '
32-
..( next_action == nil and tostring(currentTimeMs) or tostring(currentTimeMs)..' -e '..tostring(script.actions[next_action].at) )
33-
..' -i "'
34-
..video
35-
..'" -o "'
36-
..tmpFile
37-
..'"'
38-
39-
40-
print("cmd: ", command)
41-
ofs.SilentCmd(command, false)
4244

45+
function import_funscript_generator_result()
46+
local tmpFile = ofs.ExtensionDir() .. "/funscript_actions.csv"
4347
local f = io.open(tmpFile)
4448
if not f then
4549
print('Funscript Generator output file not found')
@@ -66,12 +70,16 @@ end
6670

6771

6872
function init()
69-
ofs.Bind("funscript_generator", "execute the funcript generator")
73+
ofs.Bind("start_funscript_generator", "execute the funcript generator")
7074
end
7175

7276

7377
function update(delta)
74-
78+
if processHandle and not ofs.IsProcessAlive(processHandle) then
79+
print('funscript generator completed, try import result')
80+
processHandle = nil
81+
import_funscript_generator_result()
82+
end
7583
end
7684

7785

funscript_editor/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def show_editor() -> None:
1515
""" Show the Funscript Editor Main Window """
1616
setup_logging()
1717
logging.info("Python Funscript Editor %s", VERSION)
18+
logging.info("Startup Path: %s", str(os.getcwd()))
1819
app = QtWidgets.QApplication(sys.argv)
1920
widget = FunscriptEditorWindow()
2021
widget.show()

0 commit comments

Comments
 (0)