Skip to content

Commit 1791cfc

Browse files
committed
why no prompting
1 parent 6d322b0 commit 1791cfc

File tree

1 file changed

+53
-38
lines changed

1 file changed

+53
-38
lines changed

main.ts

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,69 @@ const DEFAULT_SETTINGS: ObsidanSageSettings = {
2020

2121
export default class ObsidianSage extends Plugin {
2222
ws: any;
23+
ws_url: any;
24+
session_id: any;
2325
settings: ObsidanSageSettings;
2426
outputWriters: any;
2527

2628
async onload() {
27-
this.outputWriters = {};
2829
await this.loadSettings();
2930

3031
this.addSettingTab(new SettingTab(this.app, this));
3132

33+
new Notice("creating everything");
34+
this.createListeners()
35+
.then(() => {
36+
this.registerMarkdownCodeBlockProcessor("sage", (src, el, ctx) => {
37+
if (this.ws == null) {
38+
console.warn("tried to parse sage math before server connection established.");
39+
this.createListeners();
40+
return;
41+
}
42+
console.log('rendering eeeeeeeeeeeeeeeeeeeeeeeeee...', this.ws);
43+
new Notice("renderingggggg");
44+
45+
const req_id = nanoid();
46+
const payload = JSON.stringify({
47+
header: {
48+
msg_id: req_id,
49+
username: "",
50+
session: cell_session_id,
51+
msg_type: 'execute_request',
52+
},
53+
metadata: {},
54+
content: {
55+
code: src,
56+
silent: false,
57+
user_variables: [],
58+
user_expressions: {
59+
"_sagecell_files": "sys._sage_.new_files()",
60+
},
61+
allow_stdin: false
62+
},
63+
parent_header: {}
64+
}, null, 4);
65+
66+
el.addClass('sagecell-display-wrapper');
67+
const wrapper = el.createEl("div");
68+
const code_disp = wrapper.createEl("pre");
69+
code_disp.addClass('sagecell-display-code')
70+
code_disp.innerText = src;
71+
this.outputWriters[req_id] = new OutputWriter(wrapper, this.settings.displayByDefault);
72+
console.log('just_before_send', this.ws);
73+
this.ws.send(`${session_id}/channels,${payload}`);
74+
});
75+
})
76+
.catch(this.connectFailed);
77+
}
78+
async createListeners() {
3279
const cell_session_id = nanoid();
80+
this.outputWriters = {};
81+
this.ws = null;
82+
this.ws_url = null;
83+
this.session_id = null;
3384

34-
await fetch(this.settings.serverURL + `kernel?CellSessionID=${cell_session_id}&timeout=inf&accepted_tos=true`, { method: "POST" })
85+
return await fetch(this.settings.serverURL + `kernel?CellSessionID=${cell_session_id}&timeout=inf&accepted_tos=true`, { method: "POST" })
3586
.then(res => res.json())
3687
.then(({ ws_url, id }) => {
3788
this.ws = new SockJS(`${this.settings.serverURL}sockjs?CellSessionID=${cell_session_id}`);
@@ -71,42 +122,6 @@ export default class ObsidianSage extends Plugin {
71122

72123
return [ ws_url, id ];
73124
})
74-
.then(([ ws_url, session_id ]) => {
75-
76-
this.registerMarkdownCodeBlockProcessor("sage", (src, el, ctx) => {
77-
if (this.ws == null) { console.warn("tried to parse sage math before server connection established."); return; }
78-
79-
const req_id = nanoid();
80-
const payload = JSON.stringify({
81-
header: {
82-
msg_id: req_id,
83-
username: "",
84-
session: cell_session_id,
85-
msg_type: 'execute_request',
86-
},
87-
metadata: {},
88-
content: {
89-
code: src,
90-
silent: false,
91-
user_variables: [],
92-
user_expressions: {
93-
"_sagecell_files": "sys._sage_.new_files()",
94-
},
95-
allow_stdin: false
96-
},
97-
parent_header: {}
98-
}, null, 4);
99-
100-
el.addClass('sagecell-display-wrapper');
101-
const wrapper = el.createEl("div");
102-
const code_disp = wrapper.createEl("pre");
103-
code_disp.addClass('sagecell-display-code')
104-
code_disp.innerText = src;
105-
this.outputWriters[req_id] = new OutputWriter(wrapper, this.settings.displayByDefault);
106-
this.ws.send(`${session_id}/channels,${payload}`);
107-
});
108-
})
109-
.catch(this.connectFailed);
110125
}
111126
connectFailed(e: any) {
112127
console.error(e);

0 commit comments

Comments
 (0)