mirror of
https://github.com/anatolykopyl/stardew-sync.git
synced 2026-03-26 12:55:40 +00:00
Added a refresh feature
This commit is contained in:
65
start.lua
65
start.lua
@@ -6,14 +6,14 @@ lfs = require('lfs')
|
|||||||
function to_pc(button)
|
function to_pc(button)
|
||||||
print(button:label())
|
print(button:label())
|
||||||
if selected_device ~= '' then
|
if selected_device ~= '' then
|
||||||
os.execute('cp -r '..selected_path..'/. '..local_dir)
|
os.execute('cp -rv '..selected_path..'/. '..local_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function to_phone(button)
|
function to_phone(button)
|
||||||
print(button:label())
|
print(button:label())
|
||||||
if selected_device ~= '' then
|
if selected_device ~= '' then
|
||||||
os.execute('cp -r '..local_dir..'/. '..selected_path)
|
os.execute('cp -rv '..local_dir..'/. '..selected_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -26,36 +26,59 @@ function input_choice_cb(_, ic)
|
|||||||
to_phone_btn:activate()
|
to_phone_btn:activate()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function refresh_devices()
|
||||||
|
handle = io.popen('ls '..mount_point)
|
||||||
|
phone_dir_output = handle:read('*a')
|
||||||
|
handle:close()
|
||||||
|
|
||||||
|
phone_dir = {}
|
||||||
|
for i in string.gmatch(phone_dir_output, '%S+') do
|
||||||
|
phone_dir[#phone_dir + 1] = i
|
||||||
|
end
|
||||||
|
|
||||||
|
if win then
|
||||||
|
if #phone_dir == 0 then
|
||||||
|
device_choice:clear()
|
||||||
|
device_choice:deactivate()
|
||||||
|
to_pc_btn:deactivate()
|
||||||
|
to_phone_btn:deactivate()
|
||||||
|
else
|
||||||
|
device_choice:activate()
|
||||||
|
to_pc_btn:activate()
|
||||||
|
to_phone_btn:activate()
|
||||||
|
for i = 1, #phone_dir do
|
||||||
|
device_choice:add(phone_dir[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
selected_device = ''
|
selected_device = ''
|
||||||
selected_path = ''
|
selected_path = ''
|
||||||
my_dir = lfs.currentdir()
|
my_dir = lfs.currentdir()
|
||||||
local_dir = '/home/victoria/.config/StardewValley/Saves'
|
local_dir = '/home/victoria/.config/StardewValley/Saves'
|
||||||
mount_point = '/run/user/1000/gvfs'
|
mount_point = '/run/user/1000/gvfs'
|
||||||
handle = io.popen('ls '..mount_point)
|
|
||||||
--handle = io.popen('ls ~')
|
|
||||||
phone_dir_output = handle:read('*a')
|
|
||||||
handle:close()
|
|
||||||
|
|
||||||
phone_dir = {}
|
|
||||||
for i in string.gmatch(phone_dir_output, '%S+') do
|
|
||||||
phone_dir[#phone_dir + 1] = i
|
|
||||||
end
|
|
||||||
|
|
||||||
W, H = 320, 360
|
W, H = 320, 360
|
||||||
|
|
||||||
fl.visual('rgb')
|
fl.visual('rgb')
|
||||||
win = fl.double_window(W, H, 'Синхронизатор')
|
win = fl.double_window(W, H, 'Синхронизатор')
|
||||||
win:color(fl.WHITE)
|
win:color(fl.WHITE)
|
||||||
--fl.background(255, 255, 255)
|
icon_img = fl.png_image(my_dir..'/img/icon.png')
|
||||||
--fl.set_font(1, ' Roboto')
|
win:icon(icon_img)
|
||||||
--fl.font(1, 12)
|
fl.background(240, 240, 240)
|
||||||
|
|
||||||
bg_img = fl.png_image(my_dir..'/img/bg.png')
|
bg_img = fl.png_image(my_dir..'/img/bg.png')
|
||||||
bg_box = fl.box(1, 1, W, H)
|
bg_box = fl.box(1, 1, W, H)
|
||||||
bg_box:image(bg_img)
|
bg_box:image(bg_img)
|
||||||
|
|
||||||
title = fl.box(0, 10, W, 30, 'Выберите устройство:')
|
title = fl.box(0, 10, W, 30, 'Выберите устройство:')
|
||||||
ic = fl.input_choice(10, 50, W-20, 30)
|
refresh_img = fl.png_image(my_dir..'/img/refresh.png')
|
||||||
ic:callback(input_choice_cb, ic)
|
refresh_btn = fl.button(10, 50, 30, 30)
|
||||||
|
refresh_btn:callback(refresh_devices)
|
||||||
|
refresh_btn:image(refresh_img)
|
||||||
|
device_choice = fl.input_choice(50, 50, W-60, 30)
|
||||||
|
device_choice:callback(input_choice_cb, device_choice)
|
||||||
|
|
||||||
to_pc_btn = fl.button(50, H/2, W-100, 30, 'На ПК')
|
to_pc_btn = fl.button(50, H/2, W-100, 30, 'На ПК')
|
||||||
to_pc_btn:callback(to_pc)
|
to_pc_btn:callback(to_pc)
|
||||||
@@ -64,15 +87,7 @@ to_phone_btn = fl.button(50, H/2+40, W-100, 30, 'На телефон')
|
|||||||
to_phone_btn:callback(to_phone)
|
to_phone_btn:callback(to_phone)
|
||||||
to_phone_btn:deactivate()
|
to_phone_btn:deactivate()
|
||||||
|
|
||||||
if #phone_dir == 0 then
|
refresh_devices()
|
||||||
ic:deactivate()
|
|
||||||
to_pc_btn:deactivate()
|
|
||||||
to_phone_btn:deactivate()
|
|
||||||
else
|
|
||||||
for i = 1, #phone_dir do
|
|
||||||
ic:add(phone_dir[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
win:done()
|
win:done()
|
||||||
win:show(arg[0], arg)
|
win:show(arg[0], arg)
|
||||||
|
|||||||
Reference in New Issue
Block a user