-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscorder.vala
126 lines (86 loc) · 3.06 KB
/
Discorder.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* MIT License
#
# Copyright (c) 2020 Ferhat Geçdoğan All Rights Reserved.
# Distributed under the terms of the MIT License.
#
# */
/* Use Gtk and Webkit namespaces */
using Gtk;
using WebKit;
public class Discorder : Window {
/* Set Window title */
private const string TITLE = "Discorder";
/* Default URL */
private const string DEFAULT_URL = "https://discord.com/app/";
/* Default protocol */
private const string DEFAULT_PROTOCOL = "http";
private Regex protocol_regex;
private WebView web_view;
private ToolButton _discorder_button; /* As a home button */
private HeaderBar headerBar;
private WebContext webContext;
private CookieManager cookieManager;
private string cookie_data = GLib.Environment.get_home_dir() + "/.config/discorder/cookies.discorder";
public Discorder() {
headerBar = new HeaderBar();
webContext = new WebContext();
headerBar.set_title (Discorder.TITLE);
headerBar.set_subtitle ("\'Discording\' for everyone, everytime.");
headerBar.set_show_close_button (true);
this.set_default_size(800, 600);
try {
this.protocol_regex = new Regex(".*://.*");
} catch (RegexError e) {
critical("%s", e.message);
}
create_widgets();
connect_signals();
}
private void create_widgets() {
Gtk.Image img = new Gtk.Image.from_file("/usr/share/pixmaps/discorder/discorder_32.png");
this._discorder_button = new Gtk.ToolButton(img, null);
headerBar.pack_start(this._discorder_button);
this.set_titlebar(headerBar);
cookieManager = webContext.get_cookie_manager();
cookieManager.set_persistent_storage(this.cookie_data, CookiePersistentStorage.TEXT);
web_view = new WebView.with_context(webContext);
print("Data: " + this.cookie_data);
var scrolled_window = new ScrolledWindow(null, null);
scrolled_window.set_policy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
scrolled_window.add(this.web_view);
var box = new Box(Gtk.Orientation.VERTICAL, 0);
box.pack_start(scrolled_window, true, true, 0);
add(box);
}
private void connect_signals() {
this.destroy.connect(Gtk.main_quit);
this._discorder_button.clicked.connect(discorder_button);
}
private void discorder_button() {
this.web_view.load_uri(DEFAULT_URL);
}
public bool IsExist(string _directory) {
if (GLib.FileUtils.test(_directory, GLib.FileTest.EXISTS)) {
return true;
}
return false;
}
public void AddText(string _directory, string data) {
try {
FileUtils.set_contents(_directory, data);
} catch(Error e) {
stderr.printf ("Error: %s\n", e.message);
}
}
public void start() {
show_all();
this.web_view.load_uri(DEFAULT_URL);
}
public static int main(string[] args) {
Gtk.init(ref args);
var browser = new Discorder();
browser.start();
Gtk.main();
return 0;
}
}