Utils: Add type
json serialization workaround
Signed-off-by: Vasiliy Doylov <nekocwd@mainlining.org>
This commit is contained in:
parent
de0ee500d6
commit
87d22b312b
3 changed files with 53 additions and 0 deletions
5
src/logic/meson.build
Normal file
5
src/logic/meson.build
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
singularity_sources += [
|
||||||
|
'logic/utils.vala',
|
||||||
|
]
|
||||||
|
|
||||||
|
singularity_deps += dependency('json-glib-1.0')
|
46
src/logic/utils.vala
Normal file
46
src/logic/utils.vala
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/* utils.vala
|
||||||
|
*
|
||||||
|
* Copyright 2025 Vasiliy Doylov (NekoCWD) <nekocwd@mainlining.org>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Collection of ugly workarounds and hacks
|
||||||
|
*/
|
||||||
|
namespace Singularity.Utils {
|
||||||
|
/*
|
||||||
|
* In vala we can't use `type` as field name, but we need to use it
|
||||||
|
* to make out saves compatible with SingBox configuration.
|
||||||
|
*/
|
||||||
|
public void fix_type(ref Json.Node node) {
|
||||||
|
const string TYPE_NAME_SRC = "type-name";
|
||||||
|
const string TYPE_NAME_DST = "type";
|
||||||
|
|
||||||
|
var obj = node.get_object();
|
||||||
|
if (obj.has_member(TYPE_NAME_SRC)) {
|
||||||
|
var type_name = obj.get_member(TYPE_NAME_SRC);
|
||||||
|
obj.set_member(TYPE_NAME_DST, type_name);
|
||||||
|
obj.remove_member(TYPE_NAME_SRC);
|
||||||
|
} else if (obj.has_member(TYPE_NAME_DST)) {
|
||||||
|
var type_name = obj.get_member(TYPE_NAME_DST);
|
||||||
|
obj.set_member(TYPE_NAME_SRC, type_name);
|
||||||
|
obj.remove_member(TYPE_NAME_DST);
|
||||||
|
} else {
|
||||||
|
warning("Object has no type to fix it");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,8 @@ singularity_deps = [
|
||||||
dependency('libadwaita-1', version: '>= 1.4'),
|
dependency('libadwaita-1', version: '>= 1.4'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
subdir('logic')
|
||||||
|
|
||||||
blueprints = custom_target(
|
blueprints = custom_target(
|
||||||
'blueprints',
|
'blueprints',
|
||||||
input: files(
|
input: files(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue