@@ -8,11 +8,33 @@ import GLib from "gi://GLib"
8
8
import { programArgs , programInvocationName } from "system"
9
9
import { build } from "troll"
10
10
import "troll/globals.js"
11
- import Interface from "./window.blp" with { type : "uri" }
12
- import meta from "../share/metainfo/surf.tangent.Tangent.metainfo.xml" with { type : "uri" }
13
-
11
+ import Interface from "./window.blp" assert { type : "uri " }
12
+ //import meta from "../share/metainfo/surf.tangent.Tangent.metainfo.xml" assert { type: "uri" }
13
+ // import Preferences from "./settings.js"
14
+ // imports.package.init({
15
+ // name: "@app_id@",
16
+ // version: "@version@",
17
+ // prefix: "@prefix@",
18
+ // libdir: "@libdir@",
19
+ // datadir: "@datadir@",
20
+ // })
14
21
GLib . set_application_name ( "Tangent" )
15
22
23
+ /**
24
+ * @param {string } fail_url
25
+ * @param {string } msg
26
+ */
27
+ function error_page ( fail_url , msg ) {
28
+ const error = `
29
+ <meta name="color-scheme" content="dark light">
30
+ <div style="text-align:center; margin:24px;">
31
+ <h2>An error occurred while loading ${ fail_url } </h2>
32
+ <p>${ msg } </p>
33
+ </div>
34
+ `
35
+ return error
36
+ }
37
+
16
38
const Tangent = GObject . registerClass (
17
39
{ } ,
18
40
class Tangent extends Adw . Application {
@@ -26,19 +48,27 @@ const Tangent = GObject.registerClass(
26
48
vfunc_startup ( ) {
27
49
super . vfunc_startup ( )
28
50
29
- const about_action = new Gio . SimpleAction ( {
51
+ const about = new Gio . SimpleAction ( {
30
52
name : "about" ,
31
- parameterType : null
53
+ parameterType : null ,
32
54
} )
33
- about_action . connect ( "activate" , ( ) => {
55
+ about . connect ( "activate" , ( ) => {
34
56
const about = Adw . AboutWindow . new_from_appdata (
35
- meta . replace ( "resource://" , "" ) ,
36
- ""
57
+ meta . replace ( "resource://" , "" ) ,
58
+ ""
37
59
)
38
- about . set_transient_for ( this . get_active_window ( ) )
60
+ about . set_transient_for ( this . get_active_window ( ) )
39
61
about . present ( )
40
62
} )
41
- this . add_action ( about_action )
63
+ this . add_action ( about )
64
+ const preferences = new Gio . SimpleAction ( {
65
+ name : "preferences" ,
66
+ parameterType : null ,
67
+ } )
68
+ preferences . connect ( "activate" , ( ) =>
69
+ Preferences ( this . get_active_window ( ) )
70
+ )
71
+ this . add_action ( preferences )
42
72
}
43
73
44
74
vfunc_activate ( ) {
@@ -51,34 +81,59 @@ const Tangent = GObject.registerClass(
51
81
window . present ( )
52
82
window . connect ( "close-request" , win => win . run_dispose ( ) )
53
83
const webview = new WebKit2 . WebView ( {
54
- settings :
55
- new WebKit2 . Settings ( {
56
- enableDeveloperExtras : true
57
- } )
58
-
84
+ settings : new WebKit2 . Settings ( {
85
+ enableDeveloperExtras : true ,
86
+ // enableCaretBrowsing : true,
87
+ enableHyperlinkAuditing : false ,
88
+ } ) ,
59
89
} )
60
90
61
-
62
91
content . append ( webview )
63
92
webview . vexpand = true
64
93
webview . hexpand = true
65
- webview . load_uri ( "https://tangent.surf " )
94
+ webview . load_uri ( "https://duckduckgo.com/lite " )
66
95
webview . bind_property (
67
- "uri" ,
68
- urlbar . buffer ,
69
- "text" ,
70
- GObject . BindingFlags . DEFAULT ,
71
- ) ;
72
- webview . connect ( "notify::estimated-load-progress" , ( ) => {
73
- urlbar . progressFraction = webview . estimatedLoadProgress ;
74
- if ( urlbar . progressFraction === 1 ) {
75
- setTimeout ( ( ) => {
76
- urlbar . progressFraction = 0 ;
77
- } , 500 ) ;
78
- }
79
- } ) ;
96
+ "uri" ,
97
+ urlbar . buffer ,
98
+ "text" ,
99
+ GObject . BindingFlags . DEFAULT
100
+ )
101
+ webview . connect ( "notify::estimated-load-progress" , ( ) => {
102
+ urlbar . progressFraction = webview . estimatedLoadProgress
103
+ if ( urlbar . progressFraction === 1 ) {
104
+ setTimeout ( ( ) => {
105
+ urlbar . progressFraction = 0
106
+ } , 500 )
107
+ }
108
+ } )
109
+ webview . connect ( "load-failed" , ( _self , _load_event , fail_url , error ) => {
110
+ // Loading failed as a result of calling stop_loading
111
+ if (
112
+ error . matches ( WebKit2 . NetworkError , WebKit2 . NetworkError . CANCELLED )
113
+ ) {
114
+ return
115
+ }
116
+ webview . load_alternate_html (
117
+ error_page ( fail_url , error . message ) ,
118
+ fail_url ,
119
+ null
120
+ )
121
+ } )
122
+ urlbar . connect ( "activate" , ( ) => {
123
+ let url = urlbar . buffer . text
124
+ const scheme = GLib . Uri . peek_scheme ( url )
125
+ if ( ! scheme ) {
126
+ url = `https://${ url } `
127
+ }
128
+ webview . load_uri ( url )
129
+ } )
80
130
}
81
131
}
82
132
)
83
133
84
- new Tangent ( ) . run ( [ programInvocationName ] . concat ( programArgs ) )
134
+
135
+ export function main ( argv = [ ] ) {
136
+ const application = new Tangent ( )
137
+ return application . runAsync ( argv )
138
+ }
139
+ // new Tangent().run([programInvocationName].concat(programArgs))
0 commit comments