[MIRROR] Fixes issues with closing apps on tablets [MDB IGNORE] (#20969)

* Fixes issues with closing apps on tablets (#75117)

## About The Pull Request

- Fixes background apps not reloading the UI
- Standardizes opening/closing/backgrounding apps
- Simplifies the way apps are closed instead of having 2 procs, one on
the PC and one on the program, being named the same thing (wtf)
- Removes program states. They existed so computers can know to update
their UI every process tick, but since we now do this event based, this
is no longer needed, which is good.
- Replaces the 'forced' arg from kill_program as it was completely
unused, with ``reload_ui``, which is now used to open the UI on close,
and not to when we don't want it to.
- Closing background apps no longer reloads the entire UI
- Responding to an NT Message will no longer open the UI on your face.

## Why It's Good For The Game

Closes https://github.com/tgstation/tgstation/issues/75046
Closes https://github.com/tgstation/tgstation/issues/75108

Makes tablet UIs more responsive and lag less, not checking if a program
is closed every process to close it, and makes responding to messages
not a hassle every time.
Also makes the code easier to understand/read,

## Changelog

🆑
fix: Tablets' minimize apps feature works again.
/🆑

* Fixes issues with closing apps on tablets

* Update tablet.dm

---------

Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
Co-authored-by: Gandalf <9026500+Gandalf2k15@users.noreply.github.com>
This commit is contained in:
SkyratBot
2023-05-08 23:02:51 +01:00
committed by GitHub
parent f1b1e8b109
commit c50e7c03b6
21 changed files with 88 additions and 99 deletions
@@ -148,9 +148,7 @@ GLOBAL_LIST_EMPTY(TabletMessengers) // a list of all active messengers, similar
/obj/item/modular_computer/Destroy()
STOP_PROCESSING(SSobj, src)
wipe_program(forced = TRUE)
for(var/datum/computer_file/program/idle as anything in idle_threads)
idle.kill_program(TRUE)
close_all_programs()
//Some components will actually try and interact with this, so let's do it later
QDEL_NULL(soundloop)
QDEL_LIST(stored_files)
@@ -476,20 +474,14 @@ GLOBAL_LIST_EMPTY(TabletMessengers) // a list of all active messengers, similar
active_program.event_networkfailure(FALSE) // Active program requires NTNet to run but we've just lost connection. Crash.
for(var/datum/computer_file/program/idle_programs as anything in idle_threads)
if(idle_programs.program_state == PROGRAM_STATE_KILLED)
idle_threads.Remove(idle_programs)
continue
idle_programs.process_tick(seconds_per_tick)
idle_programs.ntnet_status = get_ntnet_status()
if(idle_programs.requires_ntnet && !idle_programs.ntnet_status)
idle_programs.event_networkfailure(TRUE)
if(active_program)
if(active_program.program_state == PROGRAM_STATE_KILLED)
active_program = null
else
active_program.process_tick(seconds_per_tick)
active_program.ntnet_status = get_ntnet_status()
active_program.process_tick(seconds_per_tick)
active_program.ntnet_status = get_ntnet_status()
handle_power(seconds_per_tick) // Handles all computer power interaction
@@ -571,20 +563,7 @@ GLOBAL_LIST_EMPTY(TabletMessengers) // a list of all active messengers, similar
data["PC_showexitprogram"] = !!active_program // Hides "Exit Program" button on mainscreen
return data
///Wipes the computer's current program. Doesn't handle any of the niceties around doing this
/obj/item/modular_computer/proc/wipe_program(forced)
if(!active_program)
return
active_program.kill_program(forced)
active_program = null
// Relays kill program request to currently active program. Use this to quit current program.
/obj/item/modular_computer/proc/kill_program(forced = FALSE)
wipe_program(forced)
update_appearance()
update_tablet_open_uis(usr)
/obj/item/modular_computer/proc/open_program(mob/user, datum/computer_file/program/program)
/obj/item/modular_computer/proc/open_program(mob/user, datum/computer_file/program/program, open_ui = TRUE)
if(program.computer != src)
CRASH("tried to open program that does not belong to this computer")
@@ -594,11 +573,12 @@ GLOBAL_LIST_EMPTY(TabletMessengers) // a list of all active messengers, similar
// The program is already running. Resume it.
if(program in idle_threads)
program.program_state = PROGRAM_STATE_ACTIVE
active_program = program
program.alert_pending = FALSE
idle_threads.Remove(program)
update_appearance()
if(open_ui)
update_tablet_open_uis(user)
update_appearance(UPDATE_ICON)
return TRUE
if(!program.is_supported_by_hardware(hardware_flag, 1, user))
@@ -617,8 +597,9 @@ GLOBAL_LIST_EMPTY(TabletMessengers) // a list of all active messengers, similar
active_program = program
program.alert_pending = FALSE
update_appearance()
update_tablet_open_uis(user)
if(open_ui)
update_tablet_open_uis(user)
update_appearance(UPDATE_ICON)
return TRUE
// Returns 0 for No Signal, 1 for Low Signal and 2 for Good Signal. 3 is for wired connection (always-on)
@@ -650,10 +631,13 @@ GLOBAL_LIST_EMPTY(TabletMessengers) // a list of all active messengers, similar
return SSmodular_computers.add_log("[src]: [text]")
/obj/item/modular_computer/proc/shutdown_computer(loud = 1)
kill_program(forced = TRUE)
for(var/datum/computer_file/program/idle_program in idle_threads)
idle_program.kill_program(forced = TRUE)
/obj/item/modular_computer/proc/close_all_programs()
active_program = null
for(var/datum/computer_file/program/idle as anything in idle_threads)
idle_threads.Remove(idle)
/obj/item/modular_computer/proc/shutdown_computer(loud = TRUE)
close_all_programs()
if(looping_sound)
soundloop.stop()
if(physical && loud)
@@ -35,10 +35,10 @@
return FALSE
if(istype(file_removing, /datum/computer_file/program))
var/datum/computer_file/program/program_file = file_removing
if(program_file.program_state != PROGRAM_STATE_KILLED)
program_file.kill_program(TRUE)
if(program_file.program_state == PROGRAM_STATE_ACTIVE)
active_program = null
if(program_file == active_program)
active_program.kill_program()
for(var/datum/computer_file/program/programs as anything in idle_threads)
programs.kill_program()
SEND_SIGNAL(file_removing, COMSIG_MODULAR_COMPUTER_FILE_DELETING)
stored_files.Remove(file_removing)
@@ -23,12 +23,13 @@
// Used in following function to reduce copypaste
/obj/item/modular_computer/proc/power_failure()
if(enabled) // Shut down the computer
if(active_program)
active_program.event_powerfailure(background = FALSE)
for(var/datum/computer_file/program/programs as anything in idle_threads)
programs.event_powerfailure(background = TRUE)
shutdown_computer(0)
if(!enabled) // Shut down the computer
return
if(active_program)
active_program.event_powerfailure()
for(var/datum/computer_file/program/programs as anything in idle_threads)
programs.event_powerfailure()
shutdown_computer(loud = FALSE)
// Handles power-related things, such as battery interaction, recharging, shutdown when it's discharged
/obj/item/modular_computer/proc/handle_power(seconds_per_tick)
@@ -126,7 +126,7 @@
switch(action)
if("PC_exit")
kill_program()
active_program.kill_program()
return TRUE
if("PC_shutdown")
shutdown_computer()
@@ -134,26 +134,17 @@
if("PC_minimize")
if(!active_program)
return
//header programs can't be minimized.
if(active_program.header_program)
kill_program()
return TRUE
idle_threads.Add(active_program)
active_program.program_state = PROGRAM_STATE_BACKGROUND // Should close any existing UIs
active_program = null
update_appearance()
active_program.background_program()
return TRUE
if("PC_killprogram")
var/prog = params["name"]
var/datum/computer_file/program/killed_program = find_file_by_name(prog)
if(!istype(killed_program) || killed_program.program_state == PROGRAM_STATE_KILLED)
if(!istype(killed_program))
return
killed_program.kill_program(forced = TRUE)
killed_program.kill_program()
to_chat(usr, span_notice("Program [killed_program.filename].[killed_program.filetype] with PID [rand(100,999)] has been killed."))
return TRUE
@@ -96,7 +96,6 @@
. = ..()
var/datum/computer_file/program/chatclient/chatprogram = cpu.find_file_by_name("ntnrc_client")
chatprogram.username = "[lowertext(console_department)]_department"
chatprogram.program_state = PROGRAM_STATE_ACTIVE
cpu.active_program = chatprogram
/obj/machinery/modular_computer/console/preset/cargochat/service