antos-frontend/src/core/settings.ts

620 lines
17 KiB
TypeScript
Raw Normal View History

// Copyright 2017-2018 Xuan Sang LE <xsang.le AT gmail DOT com>
// AnTOS Web desktop is is licensed under the GNU General Public
// License v3.0, see the LICENCE file for more information
// 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/.
namespace OS {
2020-06-18 17:09:00 +02:00
/**
* This namespace is dedicated to everything related to the
* global system settings
*/
export namespace setting {
/**
2020-06-18 17:09:00 +02:00
* User setting type definition
*
* @export
* @interface UserSettingType
*/
export interface UserSettingType {
2020-06-18 17:09:00 +02:00
/**
* User full name
*
* @type {string}
* @memberof UserSettingType
*/
name: string;
2020-06-18 17:09:00 +02:00
/**
* User name
*
* @type {string}
* @memberof UserSettingType
*/
username: string;
2020-06-18 17:09:00 +02:00
/**
* User id
*
* @type {number}
* @memberof UserSettingType
*/
id: number;
2020-06-18 17:09:00 +02:00
/**
* User groups
*
* @type {{ [index: number]: string }}
* @memberof UserSettingType
*/
group?: { [index: number]: string };
[propName: string]: any;
}
/**
2020-06-18 17:09:00 +02:00
* Virtual desktop setting data type
*
* @export
* @interface DesktopSettingType
*/
export interface DesktopSettingType {
2020-06-18 17:09:00 +02:00
/**
* Desktop VFS path
*
* @type {string}
* @memberof DesktopSettingType
*/
path: string;
2020-06-18 17:09:00 +02:00
/**
* Desktop menu, can be added automatically by applications
*
* @type {GUI.BasicItemType[]}
* @memberof DesktopSettingType
*/
menu: GUI.BasicItemType[];
/**
* Show desktop hidden files
*
* @type {boolean}
* @memberof DesktopSettingType
*/
showhidden: boolean;
[propName: string]: any;
}
/**
2020-06-18 17:09:00 +02:00
* Wallpaper setting data type
*
* @export
* @interface WPSettingType
*/
export interface WPSettingType {
2020-06-18 17:09:00 +02:00
/**
* Repeat wallpaper:
* - `repeat`
* - `repeat-x`
* - `repeat-y`
* - `no-repeat`
*
* @type {string}
* @memberof WPSettingType
*/
repeat: string;
2020-06-18 17:09:00 +02:00
/**
* Wallpaper size
* - `contain`
* - `cover`
* - `auto`
*
* @type {string}
* @memberof WPSettingType
*/
size: string;
2020-06-18 17:09:00 +02:00
/**
* VFS path to the wallpaper image
*
* @type {string}
* @memberof WPSettingType
*/
url: string;
}
/**
2020-06-18 17:09:00 +02:00
* Theme setting data type
*
* @export
* @interface ThemeSettingType
*/
export interface ThemeSettingType {
2020-06-18 17:09:00 +02:00
/**
* Theme name, this value is used for looking
* theme file in system asset
*
* @type {string}
* @memberof ThemeSettingType
*/
name: string;
2020-06-18 17:09:00 +02:00
/**
* Theme user-friendly text
*
* @type {string}
* @memberof ThemeSettingType
*/
text: string;
}
/**
2020-06-18 17:09:00 +02:00
* Appearance setting data type
*
* @export
* @interface AppearanceSettingType
*/
export interface AppearanceSettingType {
2020-06-18 17:09:00 +02:00
/**
* Current theme name
*
* @type {string}
* @memberof AppearanceSettingType
*/
theme: string;
2020-06-18 17:09:00 +02:00
/**
* All themes available in the system
*
* @type {ThemeSettingType[]}
* @memberof AppearanceSettingType
*/
themes: ThemeSettingType[];
2020-06-18 17:09:00 +02:00
/**
* Current wallpaper setting
*
* @type {WPSettingType}
* @memberof AppearanceSettingType
*/
wp: WPSettingType;
2020-06-18 17:09:00 +02:00
/**
* All wallpapers available in the system
*
* @type {string[]}
* @memberof AppearanceSettingType
*/
wps: string[];
}
/**
2020-06-18 17:09:00 +02:00
* VFS Mount points setting data type
*
* @export
* @interface VFSMountPointSettingType
*/
export interface VFSMountPointSettingType {
2020-06-18 17:09:00 +02:00
/**
* Path to the mount point
*
* @type {string}
* @memberof VFSMountPointSettingType
*/
path: string;
2020-06-18 17:09:00 +02:00
/**
* User friendly mount point name
*
* @type {string}
* @memberof VFSMountPointSettingType
*/
text: string;
[propName: string]: any;
}
/**
2020-06-18 17:09:00 +02:00
* VFS setting data type
*
* @export
* @interface VFSSettingType
*/
export interface VFSSettingType {
2020-06-18 17:09:00 +02:00
/**
* mount points setting
*
* @type {VFSMountPointSettingType[]}
* @memberof VFSSettingType
*/
mountpoints: VFSMountPointSettingType[];
[propName: string]: any;
}
/**
2020-06-18 17:09:00 +02:00
* Global system setting data type
*
* @export
* @interface SystemSettingType
*/
export interface SystemSettingType {
2020-06-18 17:09:00 +02:00
/**
* System error report URL
*
* @type {string}
* @memberof SystemSettingType
*/
error_report: string;
2020-06-18 17:09:00 +02:00
/**
* Current system locale e.g. `en_GB`
*
* @type {string}
* @memberof SystemSettingType
*/
locale: string;
2020-06-18 17:09:00 +02:00
/**
* System menus
*
* @type {API.PackageMetaType[]}
* @memberof API.PackageMetaType
*/
menu: API.PackageMetaType[];
/**
* Packages meta-data
*
* @type {{ [index: string]: API.PackageMetaType }}
* @memberof SystemSettingType
*/
packages: { [index: string]: API.PackageMetaType };
2020-06-18 17:09:00 +02:00
/**
* Path to the installed packages
*
* @type {{
* user: string;
* system: string;
* }}
* @memberof SystemSettingType
*/
pkgpaths: {
2020-06-18 17:09:00 +02:00
/**
* User specific packages install location
*
* @type {string}
*/
user: string;
2020-06-18 17:09:00 +02:00
/**
* System packages install location
*
* @type {string}
*/
system: string;
};
2020-06-18 17:09:00 +02:00
/**
* Package repositories setting.
* This configuration is used by [[MarketPlace]]
* for package management
*
* @type {{
* text: string;
* url: string;
* }[]}
* @memberof SystemSettingType
*/
repositories: {
2020-06-18 17:09:00 +02:00
/**
* Repository name
*
* @type {string}
*/
text: string;
2020-06-18 17:09:00 +02:00
/**
* Repository uri
*
* @type {string}
*/
url: string;
}[];
2020-06-18 17:09:00 +02:00
/**
* Startup applications and services
*
* @type {{
* apps: string[];
* services: string[];
* }}
* @memberof SystemSettingType
*/
startup: {
2020-06-18 17:09:00 +02:00
/**
* List of application names
*
* @type {string[]}
*/
apps: string[];
2020-06-18 17:09:00 +02:00
/**
* List of service names
*
* @type {string[]}
*/
services: string[];
/**
* List of pinned applications
*
* @type {string[]}
*/
pinned: string[];
};
}
2020-06-18 17:09:00 +02:00
/**
* User settings
*/
export var user: UserSettingType;
2020-06-18 17:09:00 +02:00
/**
* Application settings
*/
export var applications: GenericObject<any> = {};
2020-06-18 17:09:00 +02:00
/**
* Desktop settings
*/
export var desktop: DesktopSettingType;
2020-06-18 17:09:00 +02:00
/**
* Appearance settings
*/
export var appearance: AppearanceSettingType;
2020-06-18 17:09:00 +02:00
/**
* VFS settings
*/
export var VFS: VFSSettingType;
2020-06-18 17:09:00 +02:00
/**
* System settings
*/
export var system: SystemSettingType;
}
/**
2020-06-18 17:09:00 +02:00
* Reset the system settings to default values
*
* @export
*/
export function resetSetting(): void {
setting.desktop = {
path: "home://.desktop",
menu: [],
2020-06-18 17:09:00 +02:00
showhidden: false,
};
setting.user = {
name: undefined,
username: undefined,
id: 0,
};
setting.appearance = {
theme: "antos_dark",
themes: [
{
text: "AntOS light",
name: "antos_light",
},
{
text: "AntOS dark",
name: "antos_dark",
},
],
wp: {
url: "os://resources/themes/system/wp/wp3.jpg",
size: "cover",
repeat: "repeat",
},
wps: [],
};
setting.VFS = {
mountpoints: [
//TODO: multi app try to write to this object, it need to be cloned
{
text: "__(Applications)",
path: "app://",
iconclass: "fa fa-adn",
type: "app",
},
{
text: "__(Home)",
path: "home://",
iconclass: "fa fa-home",
type: "fs",
},
{
text: "__(Desktop)",
path: setting.desktop.path,
iconclass: "fa fa-desktop",
type: "fs",
},
{
text: "__(OS)",
path: "os://",
iconclass: "fa fa-inbox",
type: "fs",
},
{
text: "__(Google Drive)",
path: "gdv://",
iconclass: "fa fa-inbox",
type: "fs",
},
{
text: "__(Shared)",
path: "shared://",
iconclass: "fa fa-share-square",
type: "fs",
},
],
};
OS.setting.system = {
error_report: "https://os.iohub.dev/report",
locale: "en_GB",
menu: [],
packages: {},
pkgpaths: {
user: "home://.packages",
system: "os://packages",
},
repositories: [],
startup: {
apps: [],
2020-06-18 17:09:00 +02:00
services: ["Syslog/PushNotification", "Syslog/Calendar"],
pinned: [],
},
};
}
/**
2020-06-18 17:09:00 +02:00
* Apply the input parameter object to system settings.
* This object could be an object loaded from
* setting JSON file saved on the server.
*
* @export
* @param {*} conf
*/
export function systemSetting(conf: any) {
resetSetting();
if (conf.desktop) {
setting.desktop = conf.desktop;
}
if (conf.applications) {
setting.applications = conf.applications;
}
if (conf.appearance) {
setting.appearance = conf.appearance;
}
if (conf.user) {
setting.user = conf.user;
}
if (conf.VFS) {
setting.VFS = conf.VFS;
}
if (conf.system) {
setting.system = conf.system;
}
if (!setting.VFS.gdrive) {
setting.VFS.gdrive = {
CLIENT_ID: "",
API_KEY: "",
apilink: "https://apis.google.com/js/api.js",
DISCOVERY_DOCS: [
"https://www.googleapis.com/discovery/v1/apis/drive/v3/rest",
],
SCOPES: "https://www.googleapis.com/auth/drive",
};
}
if(!setting.applications.categories)
{
setting.applications.categories = [
{
2021-03-31 23:37:45 +02:00
text: "__(Media)",
iconclass: "bi bi-disc"
},
{
2021-03-31 23:37:45 +02:00
text: "__(Development)",
iconclass: "bi bi-hammer"
},
{
2021-03-31 23:37:45 +02:00
text: "__(Education)",
iconclass: "fa fa-graduation-cap"
},
{
2021-03-31 23:37:45 +02:00
text: "__(Game)",
iconclass: "fa fa-gamepad"
},
{
2021-03-31 23:37:45 +02:00
text: "__(Graphics)",
iconclass: "bi bi-palette-fill"
},
{
2021-03-31 23:37:45 +02:00
text: "__(Internet)",
iconclass: "fa fa-globe"
},
{
2021-03-31 23:37:45 +02:00
text: "__(Office)",
iconclass: "bi bi-building"
},
{
2021-03-31 23:37:45 +02:00
text: "__(System)",
iconclass: "fa bi-gear-wide-connected"
},
{
2021-03-31 23:37:45 +02:00
text: "__(Utility)",
iconclass: "bi bi-tools"
},
]
}
}
2020-06-18 17:09:00 +02:00
// Register handle for application search
API.onsearch("__(Applications)", function (t) {
const ar = [];
const term = new RegExp(t, "i");
for (let k in setting.system.packages) {
const v = setting.system.packages[k];
if (v.app) {
var e: any, k1: string, v1: { [x: string]: any; detail?: any; path?: any; complex?: any; };
if (
v.name.match(term) ||
(v.description && v.description.match(term))
) {
v1 = {};
for (k1 in v) {
e = v[k1];
if (k1 !== "selected") {
v1[k1] = e;
}
}
v1.detail = [{ text: v1.path }];
v1.complex = true;
ar.push(v1);
} else if (v.mimes) {
for (let m of v.mimes) {
if (t.match(new RegExp(m, "g"))) {
v1 = {};
for (k1 in v) {
e = v[k1];
if (k1 !== "selected") {
v1[k1] = v[k1];
}
}
v1.detail = [{ text: v1.path }];
v1.complex = true;
ar.push(v1);
break;
}
}
}
}
}
return ar;
});
}