add more type, all defaults apps are now in typescript

This commit is contained in:
Xuan Sang LE
2020-06-04 17:49:48 +02:00
parent 6e95994892
commit fb462fe31b
50 changed files with 2612 additions and 1734 deletions

View File

@ -1,126 +0,0 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// 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/.
class AppearanceHandle extends SettingHandle {
constructor(scheme, parent) {
let v;
super(scheme, parent);
this.wplist = this.find("wplist");
this.wpreview = this.find("wp-preview");
this.wpsize = this.find("wpsize");
this.wprepeat = this.find("wprepeat");
this.themelist = this.find("theme-list");
this.syswp = undefined;
this.wplist.set("onlistselect", e => {
const data = e.data.item.get("data");
$(this.wpreview)
.css("background-image", `url(${data.path.asFileHandle().getlink()})` )
.css("background-size", "cover");
this.parent.systemsetting.appearance.wp.url = data.path;
return this.parent._gui.wallpaper();
});
this.wplist.set("buttons", [
{
text: "+", onbtclick: e => {
return this.parent.openDialog("FileDialog", {
title: __("Select image file"),
mimes: ["image/.*"]
}).then(d => {
this.parent.systemsetting.appearance.wps.push(d.file.path);
return this.wplist.set("data", this.getwplist());
});
}
}
]);
this.wpsize.set("onlistselect", e => {
this.parent.systemsetting.appearance.wp.size = e.data.item.get("data").text;
return this.parent._gui.wallpaper();
});
const sizes = [
{ text: "cover", selected: this.parent.systemsetting.appearance.wp.size === "cover" },
{ text: "auto", selected: this.parent.systemsetting.appearance.wp.size === "auto" },
{ text: "contain", selected: this.parent.systemsetting.appearance.wp.size === "contain" }
];
this.wpsize.set("data", sizes);
const repeats = [
{ text: "repeat", selected: this.parent.systemsetting.appearance.wp.repeat === "repeat" },
{ text: "repeat-x", selected: this.parent.systemsetting.appearance.wp.repeat === "repeat-x" },
{ text: "repeat-y", selected: this.parent.systemsetting.appearance.wp.repeat === "repeat-y" },
{ text: "no-repeat", selected: this.parent.systemsetting.appearance.wp.repeat === "no-repeat" }
];
this.wprepeat.set("onlistselect", e => {
this.parent.systemsetting.appearance.wp.repeat = e.data.item.get("data").text;
return this.parent._gui.wallpaper();
});
this.wprepeat.set("data", repeats);
const currtheme = this.parent.systemsetting.appearance.theme;
for (v of Array.from(this.parent.systemsetting.appearance.themes)) { v.selected = v.name === currtheme; }
this.themelist.set("data" , this.parent.systemsetting.appearance.themes);
this.themelist.set("onlistselect", e => {
let data;
if (e && e.data) { data = e.data.item.get("data"); }
if (!data) { return; }
if (data.name === this.parent.systemsetting.appearance.theme) { return; }
this.parent.systemsetting.appearance.theme = data.name;
return this.parent._gui.loadTheme(data.name, true);
});
if (!this.syswp) {
const path = "os://resources/themes/system/wp";
path.asFileHandle().read()
.then(d => {
if (d.error) { return this.parent.error(__("Cannot read wallpaper list from {0}", path)); }
for (v of Array.from(d.result)) {
v.text = v.filename;
v.iconclass = "fa fa-file-image-o";
}
this.syswp = d.result;
return this.wplist.set("data", this.getwplist());
}).catch(e => this.parent.error(__("Unable to read: {0}", path), e));
} else {
this.wplist.set("data", this.getwplist());
}
}
getwplist() {
let v;
let list = [];
for (v of Array.from(this.parent.systemsetting.appearance.wps)) {
const file = v.asFileHandle();
list.push({
text: file.basename,
path: file.path,
selected: file.path === this.parent.systemsetting.appearance.wp.url,
iconclass: "fa fa-file-image-o"
});
}
list = list.concat(this.syswp);
for (v of Array.from(list)) { v.selected = v.path === this.parent.systemsetting.appearance.wp.url; }
return list;
}
}

View File

@ -0,0 +1,206 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// 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 {
const App = OS.application.Setting;
/**
*
*
* @class AppearanceHandle
* @extends {App.SettingHandle}
*/
class AppearanceHandle extends App.SettingHandle {
private wplist: GUI.tag.ListViewTag;
private wpreview: HTMLDivElement;
private wprepeat: GUI.tag.ListViewTag;
private themelist: GUI.tag.ListViewTag;
private wpsize: GUI.tag.ListViewTag;
private syswp: string;
/**
*Creates an instance of AppearanceHandle.
* @param {HTMLElement} scheme
* @param {OS.application.Setting} parent
* @memberof AppearanceHandle
*/
constructor(scheme: HTMLElement, parent: OS.application.Setting) {
let v: GenericObject<any>;
super(scheme, parent);
this.wplist = this.find("wplist") as GUI.tag.ListViewTag;
this.wpreview = this.find("wp-preview") as HTMLDivElement;
this.wpsize = this.find("wpsize") as GUI.tag.ListViewTag;
this.wprepeat = this.find("wprepeat") as GUI.tag.ListViewTag;
this.themelist = this.find("theme-list") as GUI.tag.ListViewTag;
this.syswp = undefined;
this.wplist.onlistselect = (e) => {
const data = e.data.item.data;
$(this.wpreview)
.css(
"background-image",
`url(${data.path.asFileHandle().getlink()})`
)
.css("background-size", "cover");
OS.setting.appearance.wp.url = data.path;
GUI.wallpaper();
};
this.wplist.buttons = [
{
text: "+",
onbtclick: (e) => {
return this.parent
.openDialog("FileDialog", {
title: __("Select image file"),
mimes: ["image/.*"],
})
.then((d) => {
OS.setting.appearance.wps.push(d.file.path);
this.wplist.data = this.getwplist();
});
},
},
];
this.wpsize.onlistselect = (e) => {
setting.appearance.wp.size = e.data.item.data.text;
return GUI.wallpaper();
};
const sizes = [
{
text: "cover",
selected: setting.appearance.wp.size === "cover",
},
{
text: "auto",
selected: setting.appearance.wp.size === "auto",
},
{
text: "contain",
selected: setting.appearance.wp.size === "contain",
},
];
this.wpsize.data = sizes;
const repeats = [
{
text: "repeat",
selected: setting.appearance.wp.repeat === "repeat",
},
{
text: "repeat-x",
selected: setting.appearance.wp.repeat === "repeat-x",
},
{
text: "repeat-y",
selected: setting.appearance.wp.repeat === "repeat-y",
},
{
text: "no-repeat",
selected: setting.appearance.wp.repeat === "no-repeat",
},
];
this.wprepeat.onlistselect = (e) => {
setting.appearance.wp.repeat = e.data.item.data.text;
GUI.wallpaper();
};
this.wprepeat.data = repeats;
const currtheme = setting.appearance.theme;
for (v of setting.appearance.themes) {
v.selected = v.name === currtheme;
}
this.themelist.data = setting.appearance.themes;
this.themelist.onlistselect = (e) => {
let data;
if (e && e.data) {
data = e.data.item.data;
}
if (!data) {
return;
}
if (data.name === setting.appearance.theme) {
return;
}
setting.appearance.theme = data.name;
GUI.loadTheme(data.name, true);
};
if (!this.syswp) {
const path = "os://resources/themes/system/wp";
path.asFileHandle()
.read()
.then((d) => {
if (d.error) {
return this.parent.error(
__(
"Cannot read wallpaper list from {0}",
path
)
);
}
for (v of Array.from(d.result)) {
v.text = v.filename;
v.iconclass = "fa fa-file-image-o";
}
this.syswp = d.result;
return (this.wplist.data = this.getwplist());
})
.catch((e) =>
this.parent.error(
__("Unable to read: {0}", path),
e
)
);
} else {
this.wplist.data = this.getwplist();
}
}
/**
*
*
* @private
* @returns {GenericObject<any>[]}
* @memberof AppearanceHandle
*/
private getwplist(): GenericObject<any>[] {
let v;
let list = [];
for (v of setting.appearance.wps) {
const file = v.asFileHandle();
list.push({
text: file.basename,
path: file.path,
selected: file.path === setting.appearance.wp.url,
iconclass: "fa fa-file-image-o",
});
}
list = list.concat(this.syswp);
for (v of list) {
v.selected = v.path === setting.appearance.wp.url;
}
return list;
}
}
App.AppearanceHandle = AppearanceHandle;
}

View File

@ -1,49 +0,0 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// 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/.
class LocaleHandle extends SettingHandle {
constructor(scheme, parent) {
super(scheme, parent);
this.lglist = this.find("lglist");
this.localelist = undefined;
this.lglist.set("onlistselect", e => {
return this.parent._api.setLocale(e.data.item.get("data").text);
});
if (!this.localelist) {
const path = "os://resources/languages";
path.asFileHandle().read()
.then(d => {
if (d.derror) { return this.parent.error(__("Cannot fetch system locales: {0}", d.error)); }
for (let v of Array.from(d.result)) {
v.text = v.filename.replace(/\.json$/g, "");
v.selected = v.text === this.parent.systemsetting.system.locale;
}
this.localelist = d.result;
return this.lglist.set("data", this.localelist);
}).catch(e => this.parent.error(__("Unable to read: {0}", path), e));
} else {
this.lglist.set("data", this.localelist);
}
}
}

View File

@ -0,0 +1,77 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// 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 {
const App = OS.application.Setting;
/**
*
*
* @class LocaleHandle
* @extends {App.SettingHandle}
*/
class LocaleHandle extends App.SettingHandle {
private lglist: GUI.tag.ListViewTag;
private localelist: GenericObject<any>[];
/**
*Creates an instance of LocaleHandle.
* @param {HTMLElement} scheme
* @param {OS.application.Setting} parent
* @memberof LocaleHandle
*/
constructor(scheme: HTMLElement, parent: OS.application.Setting) {
super(scheme, parent);
this.lglist = this.find("lglist") as GUI.tag.ListViewTag;
this.localelist = undefined;
this.lglist.onlistselect = (e) => {
return API.setLocale(e.data.item.data.text);
};
if (!this.localelist) {
const path = "os://resources/languages";
path.asFileHandle()
.read()
.then((d) => {
if (d.derror) {
return this.parent.error(
__("Cannot fetch system locales: {0}", d.error)
);
}
for (let v of d.result) {
v.text = v.filename.replace(/\.json$/g, "");
v.selected = v.text === setting.system.locale;
}
this.localelist = d.result;
return (this.lglist.data = this.localelist);
})
.catch((e) =>
this.parent.error(__("Unable to read: {0}", path), e)
);
} else {
this.lglist.data = this.localelist;
}
}
}
App.LocaleHandle = LocaleHandle;
}

View File

@ -1,110 +0,0 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS205: Consider reworking code to avoid use of IIFEs
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// 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/.
class StartupHandle extends SettingHandle {
constructor(scheme, parent) {
super(scheme, parent);
this.srvlist = this.find("srvlist");
this.applist = this.find("applist");
this.srvlist.set("buttons", [
{
text: "+", onbtclick: e => {
let services = [];
for (var k in this.parent.systemsetting.system.packages) {
const v = this.parent.systemsetting.system.packages[k];
if (v.services) {
const srvs = (Array.from(v.services).map((x) => ({ text: `${k}/${x}`, iconclass: "fa fa-tasks" })));
services = services.concat(srvs);
}
}
return this.parent.openDialog("SelectionDialog", {
title: "__(Add service)",
data: services
}).then(d => {
this.parent.systemsetting.system.startup.services.push(d.text);
return this.refresh();
});
}
},
{
text: "-", onbtclick: e => {
const item = this.srvlist.get("selectedItem");
if (!item) { return; }
const selidx = $(item).index();
this.parent.systemsetting.system.startup.services.splice(selidx, 1);
return this.refresh();
}
}
]);
this.applist.set("buttons", [
{
text: "+", onbtclick: e => {
const apps = ((() => {
const result = [];
for (let k in this.parent.systemsetting.system.packages) {
const v = this.parent.systemsetting.system.packages[k];
result.push({ text: k, iconclass: v.iconclass });
}
return result;
})());
return this.parent.openDialog("SelectionDialog", {
title: "__(Add application)",
data: apps
}).then(d => {
this.parent.systemsetting.system.startup.apps.push(d.text);
return this.refresh();
});
}
},
{
text: "-", onbtclick: e => {
const item = this.applist.get("selectedItem");
if (!item) { return; }
const selidx = $(item).index();
this.parent.systemsetting.system.startup.apps.splice(selidx, 1);
return this.refresh();
}
}
]);
this.refresh();
}
refresh() {
let v;
this.srvlist.set("data", ((() => {
const result = [];
for (v of Array.from(this.parent.systemsetting.system.startup.services)) { result.push({ text:v });
}
return result;
})()));
return this.applist.set("data", ((() => {
const result1 = [];
for (v of Array.from(this.parent.systemsetting.system.startup.apps)) { result1.push({ text:v });
}
return result1;
})()));
}
}

View File

@ -0,0 +1,155 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS205: Consider reworking code to avoid use of IIFEs
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// 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 {
const App = OS.application.Setting;
/**
*
*
* @class StartupHandle
* @extends {App.SettingHandle}
*/
class StartupHandle extends App.SettingHandle {
private srvlist: GUI.tag.ListViewTag;
private applist: GUI.tag.ListViewTag;
/**
*Creates an instance of StartupHandle.
* @param {HTMLElement} scheme
* @param {OS.application.Setting} parent
* @memberof StartupHandle
*/
constructor(scheme: HTMLElement, parent: OS.application.Setting) {
super(scheme, parent);
this.srvlist = this.find("srvlist") as GUI.tag.ListViewTag;
this.applist = this.find("applist") as GUI.tag.ListViewTag;
this.srvlist.buttons = [
{
text: "+",
onbtclick: () => {
let services = [];
for (var k in setting.system.packages) {
const v = setting.system.packages[k];
if (v.services) {
const srvs = v.services.map((x) => ({
text: `${k}/${x}`,
iconclass: "fa fa-tasks",
}));
services = services.concat(srvs);
}
}
this.parent
.openDialog("SelectionDialog", {
title: "__(Add service)",
data: services,
})
.then((d) => {
setting.system.startup.services.push(d.text);
return this.refresh();
});
},
},
{
text: "-",
onbtclick: () => {
const item = this.srvlist.selectedItem;
if (!item) {
return;
}
const selidx = $(item).index();
setting.system.startup.services.splice(selidx, 1);
return this.refresh();
},
},
];
this.applist.buttons = [
{
text: "+",
onbtclick: () => {
const apps = (() => {
const result = [];
for (let k in setting.system.packages) {
const v = setting.system.packages[k];
result.push({
text: k,
iconclass: v.iconclass,
});
}
return result;
})();
this.parent
.openDialog("SelectionDialog", {
title: "__(Add application)",
data: apps,
})
.then((d) => {
setting.system.startup.apps.push(d.text);
return this.refresh();
});
},
},
{
text: "-",
onbtclick: () => {
const item = this.applist.selectedItem;
if (!item) {
return;
}
const selidx = $(item).index();
setting.system.startup.apps.splice(selidx, 1);
return this.refresh();
},
},
];
this.refresh();
}
/**
*
*
* @private
* @memberof StartupHandle
*/
private refresh(): void {
let v;
this.srvlist.data = (() => {
const result = [];
for (v of setting.system.startup.services) {
result.push({ text: v });
}
return result;
})();
this.applist.data = (() => {
const result1 = [];
for (v of Array.from(setting.system.startup.apps)) {
result1.push({ text: v });
}
return result1;
})();
}
}
App.StartupHandle = StartupHandle;
}

View File

@ -1,173 +0,0 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// 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/.
class VFSSettingDialog extends this.OS.GUI.BasicDialog {
constructor() {
super("VFSSettingDialog", VFSSettingDialog.scheme);
}
main() {
super.main();
$(this.find("txtPath")).click(e => {
return this.openDialog("FileDialog", {
title: "__(Select a directory)",
mimes: ["dir"],
hidden: true
})
.then(d => {
return (this.find("txtPath")).value = d.file.path;
});
});
this.find("btnOk").set("onbtclick", e => {
const data = {
path: (this.find("txtPath")).value,
name: (this.find("txtName")).value
};
if (!data.name || (data.name === "")) { return this.error(__("Please enter mount point name")); }
if (!data.path || (data.path === "")) { return this.error(__("Please select a directory")); }
if (this.handle) { this.handle(data); }
return this.quit();
});
(this.find("btnCancel")).set("onbtclick", e => {
return this.quit();
});
if (!this.data) { return; }
if (this.data.text) { (this.find("txtName")).value = this.data.text; }
if (this.data.path) { return (this.find("txtPath")).value = this.data.path; }
}
}
VFSSettingDialog.scheme = `\
<afx-app-window width='250' height='180' apptitle = "__(Mount Points)">
<afx-vbox>
<afx-hbox>
<div data-width = "10" />
<afx-vbox>
<div data-height="10" />
<afx-label data-height="30" text = "__(Name)" />
<input type = "text" data-id= "txtName" />
<div data-height="3" />
<afx-label data-height="30" text = "__(Path)" />
<input type = "text" data-id= "txtPath" />
<div data-height="10" />
<afx-hbox data-height="30">
<div />
<afx-button data-id = "btnOk" text = "__(Ok)" data-width = "40" />
<afx-button data-id = "btnCancel" text = "__(Cancel)" data-width = "50" />
</afx-hbox>
</afx-vbox>
<div data-width = "10" />
</afx-hbox>
</afx-vbox>
</afx-app-window>\
`;
class VFSHandle extends SettingHandle {
constructor(scheme, parent) {
super(scheme, parent);
this.mplist = this.find("mplist");
this.dpath = this.find("dpath");
this.ppath = this.find("ppath");
this.mplist.set("buttons", [
{
text: "+",
onbtclick: e => {
return this.parent.openDialog(new VFSSettingDialog(), {
title: "__(Add mount point)"
})
.then(d => {
this.parent.systemsetting.VFS.mountpoints.push({
text: d.name, path: d.path, iconclass: "fa fa-folder", type: "fs"
});
return this.refresh();
});
}
},
{
text: "-",
onbtclick: e => {
const item = this.mplist.get("selectedItem");
if (!item) { return; }
const selidx = $(item).index();
return this.parent.openDialog("YesNoDialog", {
title: "__(Remove)",
text: __("Remove: {0}?", item.get("data").text)
}).then(d => {
if (!d) { return; }
this.parent.systemsetting.VFS.mountpoints.splice(selidx, 1);
return this.refresh();
});
}
},
{
text: "",
iconclass: "fa fa-pencil",
onbtclick: e => {
const sel = this.mplist.get("selectedItem");
if (!sel) { return; }
return this.parent.openDialog(new VFSSettingDialog(), {
title: "__(Edit mount point)",
text: sel.get("data").text,
path: sel.get("data").path
}).then(d => {
sel.get("data").text = d.name;
sel.get("data").path = d.path;
return this.refresh();
});
}
}
]);
(this.find("btndpath")).set('onbtclick', e => {
return this.parent.openDialog("FileDialog", {
title: "__(Select a directory)",
mimes: ["dir"],
hidden: true
}).then(d => {
this.parent.systemsetting.desktop.path = d.file.path;
this.parent._gui.refreshDesktop();
return this.refresh();
});
});
(this.find("btnppath")).set('onbtclick', e => {
return this.parent.openDialog("FileDialog", {
title: "__(Select a directory)",
mimes: ["dir"],
hidden: true
}).then(d => {
this.parent.systemsetting.system.pkgpaths.user = d.file.path;
return this.refresh();
});
});
this.refresh();
}
refresh() {
this.mplist.set("data", this.parent.systemsetting.VFS.mountpoints);
this.dpath.set("text", this.parent.systemsetting.desktop.path);
return this.ppath.set("text", this.parent.systemsetting.system.pkgpaths.user);
}
}

View File

@ -0,0 +1,246 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// 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 {
const App = OS.application.Setting;
/**
*
*
* @class VFSSettingDialog
* @extends {GUI.BasicDialog}
*/
class VFSSettingDialog extends GUI.BasicDialog {
/**
*Creates an instance of VFSSettingDialog.
* @memberof VFSSettingDialog
*/
constructor() {
super("VFSSettingDialog", VFSSettingDialog.scheme);
}
/**
*
*
* @returns
* @memberof VFSSettingDialog
*/
main() {
super.main();
$(this.find("txtPath")).click((e) => {
return this.openDialog("FileDialog", {
title: "__(Select a directory)",
mimes: ["dir"],
hidden: true,
}).then((d) => {
return ((this.find("txtPath") as HTMLInputElement).value =
d.file.path);
});
});
(this.find("btnOk") as GUI.tag.ButtonTag).onbtclick = (e) => {
const data = {
path: (this.find("txtPath") as HTMLInputElement).value,
name: (this.find("txtName") as HTMLInputElement).value,
};
if (!data.name || data.name === "") {
return this.error(__("Please enter mount point name"));
}
if (!data.path || data.path === "") {
return this.error(__("Please select a directory"));
}
if (this.handle) {
this.handle(data);
}
return this.quit();
};
(this.find("btnCancel") as GUI.tag.ButtonTag).onbtclick = (e) => {
return this.quit();
};
if (!this.data) {
return;
}
if (this.data.text) {
(this.find(
"txtName"
) as HTMLInputElement).value = this.data.text;
}
if (this.data.path) {
return ((this.find(
"txtPath"
) as HTMLInputElement).value = this.data.path);
}
}
}
VFSSettingDialog.scheme = `\
<afx-app-window width='250' height='180' apptitle = "__(Mount Points)">
<afx-vbox>
<afx-hbox>
<div data-width = "10" />
<afx-vbox>
<div data-height="10" />
<afx-label data-height="30" text = "__(Name)" />
<input type = "text" data-id= "txtName" />
<div data-height="3" />
<afx-label data-height="30" text = "__(Path)" />
<input type = "text" data-id= "txtPath" />
<div data-height="10" />
<afx-hbox data-height="30">
<div />
<afx-button data-id = "btnOk" text = "__(Ok)" data-width = "40" />
<afx-button data-id = "btnCancel" text = "__(Cancel)" data-width = "50" />
</afx-hbox>
</afx-vbox>
<div data-width = "10" />
</afx-hbox>
</afx-vbox>
</afx-app-window>\
`;
/**
*
*
* @class VFSHandle
* @extends {App.SettingHandle}
*/
class VFSHandle extends App.SettingHandle {
private mplist: GUI.tag.ListViewTag;
private dpath: GUI.tag.LabelTag;
private ppath: GUI.tag.LabelTag;
/**
*Creates an instance of VFSHandle.
* @param {HTMLElement} scheme
* @param {OS.application.Setting} parent
* @memberof VFSHandle
*/
constructor(scheme: HTMLElement, parent: OS.application.Setting) {
super(scheme, parent);
this.mplist = this.find("mplist") as GUI.tag.ListViewTag;
this.dpath = this.find("dpath") as GUI.tag.LabelTag;
this.ppath = this.find("ppath") as GUI.tag.LabelTag;
this.mplist.buttons = [
{
text: "+",
onbtclick: async () => {
const d = await this.parent.openDialog(
new VFSSettingDialog(),
{
title: "__(Add mount point)",
}
);
setting.VFS.mountpoints.push({
text: d.name,
path: d.path,
iconclass: "fa fa-folder",
type: "fs",
});
return this.refresh();
},
},
{
text: "-",
onbtclick: async () => {
const item = this.mplist.selectedItem;
if (!item) {
return;
}
const selidx = $(item).index();
const d = await this.parent.openDialog("YesNoDialog", {
title: "__(Remove)",
text: __("Remove: {0}?", item.data.text),
});
if (!d) {
return;
}
setting.VFS.mountpoints.splice(selidx, 1);
return this.refresh();
},
},
{
text: "",
iconclass: "fa fa-pencil",
onbtclick: async () => {
const sel = this.mplist.selectedItem;
if (!sel) {
return;
}
const d = await this.parent.openDialog(
new VFSSettingDialog(),
{
title: "__(Edit mount point)",
text: sel.data.text,
path: sel.data.path,
}
);
sel.data.text = d.name;
sel.data.path = d.path;
return this.refresh();
},
},
];
(this.find(
"btndpath"
) as GUI.tag.ButtonTag).onbtclick = async () => {
const d = await this.parent.openDialog("FileDialog", {
title: "__(Select a directory)",
mimes: ["dir"],
hidden: true,
});
setting.desktop.path = d.file.path;
GUI.refreshDesktop();
return this.refresh();
};
(this.find(
"btnppath"
) as GUI.tag.ButtonTag).onbtclick = async () => {
const d = await this.parent.openDialog("FileDialog", {
title: "__(Select a directory)",
mimes: ["dir"],
hidden: true,
});
setting.system.pkgpaths.user = d.file.path;
return this.refresh();
};
this.refresh();
}
/**
*
*
* @private
* @memberof VFSHandle
*/
private refresh(): void {
this.mplist.data = setting.VFS.mountpoints;
this.dpath.text = setting.desktop.path;
this.ppath.text = setting.system.pkgpaths.user;
}
}
App.VFSHandle = VFSHandle;
}

View File

@ -1,61 +0,0 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS208: Avoid top-level this
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// 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/.
class SettingHandle {
constructor(scheme, parent) {
this.scheme = scheme;
this.parent = parent;
}
find(id) { if (this.scheme) { return ($(`[data-id='${id}']`, this.scheme))[0]; } }
render() {}
}
class Setting extends this.OS.GUI.BaseApplication {
constructor(args) {
super("Setting", args);
}
main() {
this.container = this.find("container");
new AppearanceHandle(this.find("appearance"), this);
new VFSHandle(this.find("vfs"), this);
new LocaleHandle(this.find("locale"), this);
new StartupHandle(this.find("startup"), this);
return (this.find("btnsave")).set("onbtclick", e => {
return this._api.setting()
.then(d => {
if (d.error) { return this.error(__("Cannot save system setting: {0}", d.error)); }
return this.notify(__("System setting saved"));
}).catch(e => {
return this.error(__("Cannot save system setting: {0}", e.toString()), e);
});
});
}
}
Setting.singleton = true;
this.OS.register("Setting", Setting);

View File

@ -0,0 +1,136 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS208: Avoid top-level this
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// 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 {
export namespace application {
/**
*
*
* @class SettingHandle
*/
class SettingHandle {
protected scheme: HTMLElement;
protected parent: Setting;
/**
*Creates an instance of SettingHandle.
* @param {HTMLElement} scheme
* @param {Setting} parent
* @memberof SettingHandle
*/
constructor(scheme: HTMLElement, parent: Setting) {
this.scheme = scheme;
this.parent = parent;
}
/**
*
*
* @protected
* @param {string} id
* @returns
* @memberof SettingHandle
*/
protected find(id: string) {
if (this.scheme) {
return $(`[data-id='${id}']`, this.scheme)[0];
}
}
/**
*
*
* @protected
* @memberof SettingHandle
*/
protected render() : void {};
}
/**
*
*
* @export
* @class Setting
* @extends {BaseApplication}
*/
export class Setting extends BaseApplication {
//private containter: GUI.tag.TabContainerTag;
static AppearanceHandle: typeof SettingHandle;
static VFSHandle: typeof SettingHandle;
static LocaleHandle: typeof SettingHandle;
static StartupHandle: typeof SettingHandle;
static SettingHandle: typeof SettingHandle;
/**
*Creates an instance of Setting.
* @param {AppArgumentsType[]} args
* @memberof Setting
*/
constructor(args: AppArgumentsType[]) {
super("Setting", args);
}
/**
*
*
* @memberof Setting
*/
main(): void{
//this.containter = this.find("container") as GUI.tag.TabContainerTag;
new Setting.AppearanceHandle(this.find("appearance"), this);
new Setting.VFSHandle(this.find("vfs"), this);
new Setting.LocaleHandle(this.find("locale"), this);
new Setting.StartupHandle(this.find("startup"), this);
(this.find("btnsave") as GUI.tag.ButtonTag ).onbtclick = (e) => {
this._api
.setting()
.then((d) => {
if (d.error) {
return this.error(
__(
"Cannot save system setting: {0}",
d.error
)
);
}
return this.notify(__("System setting saved"));
})
.catch((e) => {
return this.error(
__(
"Cannot save system setting: {0}",
e.toString()
),
e
);
});
};
}
}
Setting.singleton = true;
Setting.SettingHandle = SettingHandle;
}
}