Skip to content

Commit c1e29c3

Browse files
Release 1.1.2 cleanup
Release 1.1.2 cleanup
2 parents 03d1f3b + c96fdba commit c1e29c3

File tree

9 files changed

+62
-71
lines changed

9 files changed

+62
-71
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "ical-obsidian-sync",
33
"name": "iCalSync",
4-
"version": "1.1.1",
4+
"version": "1.1.2",
55
"minAppVersion": "0.15.0",
66
"description": "Synchronize iCalendar with your notes",
77
"author": "Vaccarini Lorenzo",

package-lock.json

Lines changed: 0 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-sample-plugin",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
55
"main": "main.js",
66
"scripts": {
@@ -11,19 +11,14 @@
1111
"author": "",
1212
"license": "MIT",
1313
"dependencies": {
14-
"@types/cors": "^2.8.13",
1514
"@types/node": "^16.11.6",
1615
"@types/node-fetch": "^2.6.2",
17-
"@types/punycode": "^2.1.0",
1816
"@typescript-eslint/eslint-plugin": "^5.43.0",
1917
"@typescript-eslint/parser": "5.29.0",
2018
"builtin-modules": "3.3.0",
2119
"chrono-node": "^2.6.4",
2220
"codemirror": "^6.0.1",
23-
"crypto": "^1.0.1",
24-
"dotenv": "^16.3.1",
2521
"electron": "^25.3.2",
26-
"electron-clipboard-watcher": "^1.0.1",
2722
"esbuild": "0.18.17",
2823
"moment-timezone": "^0.5.43",
2924
"node-fetch": "^2.6.7",

src/controllers/eventController.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import iCloudMisc from "../iCloudJs/iCloudMisc";
33
import {iCloudCalendarEvent} from "../iCloudJs/calendar";
44
import {Sentence} from "../model/sentence";
55
import iCloudController from "./iCloudController";
6-
import {Notice} from "obsidian";
6+
import {Notice, requestUrl, RequestUrlParam} from "obsidian";
77
import {appendFileSync, readFileSync, writeFileSync} from "fs";
88
import {DateRange} from "../model/dateRange";
99

@@ -133,6 +133,7 @@ class EventController{
133133
if (status) new Notice("📅 The event has been synchronized!")
134134
else new Notice("🤷 There has been an error synchronizing the event...")
135135
}));
136+
this.updateCounter();
136137
}
137138

138139
private generateNewUUID(): string {
@@ -160,7 +161,19 @@ class EventController{
160161
}
161162
}
162163

163-
164+
// This method sends a body-less post request to an internal server to notify the synchronisation request
165+
// The purpose is to publish on the README page a badge with the number of synced requests
166+
private updateCounter() {
167+
const requestUrlParam = {
168+
url: "https://icalsynccounter.onrender.com/numSync",
169+
method: "POST"
170+
}
171+
try {
172+
requestUrl(requestUrlParam as RequestUrlParam);
173+
} catch (e) {
174+
console.warn("Error interacting with the counter server", e);
175+
}
176+
}
164177
}
165178

166179
const eventController = new EventController();

src/controllers/iCloudController.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ class ICloudController {
1313
private _tagHash: Map<number, Event>;
1414
private _dataLoadingComplete: boolean;
1515
private appSettings: SettingInterface;
16+
private maxReconnectAttempt: number;
17+
private reconnectAttempt: number;
1618

1719
constructor() {
1820
this._tagHash = new Map<number, Event>();
1921
this._pendingTagsBuffer = [];
2022
this._calendars = [];
2123
this._dataLoadingComplete = false;
24+
this.maxReconnectAttempt = 5;
25+
this.reconnectAttempt = 0;
2226
}
2327

2428
injectPath(pluginPath: string){
@@ -76,13 +80,32 @@ class ICloudController {
7680
return await this._calendarService.postEvent(event.value, calendar.ctag);
7781
}
7882

83+
async awaitReady(){
84+
await this._iCloud.awaitReady;
85+
}
86+
7987
isLoggedIn(){
8088
return this._iCloud != undefined && (this._iCloud.status == iCloudServiceStatus.Ready || this._iCloud.status == iCloudServiceStatus.Trusted)
8189
}
8290

8391
async getICloudEvents(missedDateRange: DateRange): Promise<iCloudCalendarEvent[]> {
8492
return await this._calendarService.events(missedDateRange.start, missedDateRange.end);
8593
}
94+
95+
refreshRequestCookies(requestUrlParams: { url, method, headers, body }){
96+
const oldHeader = requestUrlParams.headers;
97+
oldHeader.Cookie = this._iCloud.authStore.getHeaders().Cookie;
98+
return;
99+
}
100+
101+
checkMaxReconnectAttempt(): boolean{
102+
this.reconnectAttempt += 1;
103+
return this.reconnectAttempt < this.maxReconnectAttempt;
104+
}
105+
106+
resetReconnectAttempt() {
107+
this.reconnectAttempt = 0;
108+
}
86109
}
87110

88111
const iCloudController = new ICloudController();

src/controllers/nlpController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class NlpController {
2424
this._mainNLP = wink( model );
2525
this._secondaryNLP = wink (model);
2626
this._customPatterns = [];
27-
this._secondaryCustomPatterns = []
27+
this._secondaryCustomPatterns = [];
2828
}
2929

3030
injectPath(pluginPath: string){
@@ -56,7 +56,7 @@ class NlpController {
5656
{name: "ordinalDateReverse", patterns: [" [|DATE] [DATE|may|march] [|DET] [ORDINAL]"]},
5757
);
5858
this._customPatterns.push(
59-
{name: "timeRange", patterns: ["from [TIME|CARDINAL|NUM] [|NOUN] to [TIME|CARDINAL|NUM] [|NOUN]", "ADP SYM PART SYM"]},
59+
{name: "timeRange", patterns: ["from [TIME|CARDINAL|NUM] [|am|pm] to [TIME|CARDINAL|NUM] [|am|pm]", "[TIME|CARDINAL] [-|/] [TIME|CARDINAL]"]},
6060
{name: "exactTime", patterns: ["[at|for] [CARDINAL|TIME]"]}
6161
)
6262
this._customPatterns.push({name: "intentionalVerb", patterns: ["[|AUX] [VERB] [|ADP] [|DET] [NOUN]"]});

src/iCloudJs/account.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,4 @@ export class iCloudAccountDetailsService {
6868
this.service = service;
6969
this.serviceUri = serviceUri;
7070
}
71-
72-
private _devices;
73-
async getDevices(refresh = false): Promise<iCloudDevices> {
74-
if (!refresh && this._devices) return this._devices;
75-
const response = await iCloudMisc.wrapRequest(this.serviceUri + "/setup/web/device/getDevices", { headers: this.service.authStore.getHeaders() });
76-
const json = await response.json();
77-
this._devices = json;
78-
return this._devices;
79-
}
80-
81-
private _family;
82-
async getFamily(refresh = false): Promise<iCloudFamilyInfo> {
83-
if (!refresh && this._family) return this._family;
84-
const response = await iCloudMisc.wrapRequest(this.serviceUri + "/setup/web/family/getFamilyDetails", { headers: this.service.authStore.getHeaders() });
85-
const json = await response.json();
86-
this._family = json;
87-
return this._family;
88-
}
8971
}

src/iCloudJs/iCloudMisc.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {RequestInfo, RequestInit, Response} from "node-fetch";
22
import {requestUrl, RequestUrlParam} from "obsidian";
3+
import iCloudController from "../controllers/iCloudController";
34

45
class ICloudMisc {
56
private stringifyDateNumber(dateNumber: number): string {
@@ -50,7 +51,25 @@ class ICloudMisc {
5051
try{
5152
requestUrlResponse = await requestUrl(requestUrlParam as RequestUrlParam);
5253
} catch (e){
53-
console.warn("Error requestingUrl");
54+
console.warn("Error requestingUrl:", e);
55+
console.warn(e.code);
56+
console.warn(e.toString());
57+
if (e.toString() == "Error: Request failed, status 421"){
58+
const canTryReconnect = iCloudController.checkMaxReconnectAttempt();
59+
if(!canTryReconnect){
60+
console.warn("Can't reconnect - max attempts reached");
61+
return;
62+
}
63+
console.warn("Refreshing token...");
64+
await iCloudController.tryAuthentication("", "")
65+
await iCloudController.awaitReady();
66+
iCloudController.resetReconnectAttempt();
67+
iCloudController.refreshRequestCookies(requestUrlParam);
68+
requestUrlResponse = await requestUrl(requestUrlParam as RequestUrlParam);
69+
}
70+
else if(e.toString() == "Error: net::ERR_NAME_NOT_RESOLVED"){
71+
console.warn("Internet connection error");
72+
}
5473
}
5574

5675
const setCookieField = requestUrlResponse.headers["set-cookie"] as any;

src/plugin/nlpExtension.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Event from "../model/event";
99
import { Misc } from "../misc/misc";
1010
import iCloudController from "../controllers/iCloudController";
1111
import { Notice } from "obsidian";
12-
import nlpController from "../controllers/nlpController";
1312

1413
class NLPPlugin implements PluginValue {
1514
decorations: DecorationSet;

0 commit comments

Comments
 (0)