Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@hypr/codemirror": "workspace:^",
"@hypr/db": "workspace:*",
"@hypr/plugin-analytics": "workspace:*",
"@hypr/plugin-apple-calendar": "workspace:*",
"@hypr/plugin-cli2": "workspace:*",
"@hypr/plugin-db2": "workspace:*",
"@hypr/plugin-detect": "workspace:*",
Expand Down Expand Up @@ -64,6 +65,7 @@
"@tauri-apps/plugin-fs": "^2.4.4",
"@tauri-apps/plugin-http": "^2.5.4",
"@tauri-apps/plugin-opener": "^2.5.2",
"@tauri-apps/plugin-os": "^2.3.2",
"@tauri-apps/plugin-process": "^2.3.1",
"@tauri-apps/plugin-shell": "^2.3.3",
"@tauri-apps/plugin-store": "^2.4.1",
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@ tracing = { workspace = true }
aspasia = "0.2.1"
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }

[target.'cfg(target_os = "macos")'.dependencies]
tauri-plugin-apple-calendar = { workspace = true }

[features]
devtools = ["tauri/devtools"]
5 changes: 5 additions & 0 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ pub async fn main() {
Some(vec!["--background"]),
));

#[cfg(target_os = "macos")]
{
builder = builder.plugin(tauri_plugin_apple_calendar::init());
}

if let Some(client) = sentry_client.as_ref() {
builder = builder.plugin(tauri_plugin_sentry::init_with_no_injection(client));
}
Expand Down
65 changes: 64 additions & 1 deletion apps/desktop/src/components/task-manager.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
import { Channel } from "@tauri-apps/api/core";
import { platform } from "@tauri-apps/plugin-os";
import { useScheduleTaskRun, useSetTask } from "tinytick/ui-react";

import { commands as localSttCommands } from "@hypr/plugin-local-stt";
import type { SupportedSttModel } from "@hypr/plugin-local-stt";

import { checkForUpdate } from "./main/sidebar/profile/ota/task";

let cachedIsMacos: boolean | null = null;

async function isMacOS(): Promise<boolean> {
if (cachedIsMacos !== null) return cachedIsMacos;

try {
const p = await platform();
const isMac = p === "macos";
cachedIsMacos = isMac;
return isMac;
} catch (err) {
console.error("Failed to detect platform via @tauri-apps/plugin-os", err);
return false;
}
}

const UPDATE_CHECK_TASK_ID = "checkForUpdate";
const UPDATE_CHECK_INTERVAL = 30 * 1000;

export const DOWNLOAD_MODEL_TASK_ID = "downloadModel";

const SYNC_CALENDARS_TASK_ID = "syncCalendars";
const SYNC_CALENDARS_INTERVAL = 10 * 60 * 1000;

const SYNC_EVENTS_TASK_ID = "syncEvents";
const SYNC_EVENTS_INTERVAL = 5 * 60 * 1000;

const downloadProgressCallbacks = new Map<string, (progress: number) => void>();

export function registerDownloadProgressCallback(
Expand Down Expand Up @@ -43,13 +66,53 @@ export function TaskManager() {
const progressCallback = downloadProgressCallbacks.get(model);

if (progressCallback) {
channel.onmessage = (progress) => {
channel.onmessage = (progress: number) => {
progressCallback(progress);
};
}

await localSttCommands.downloadModel(model, channel);
});

useSetTask(SYNC_CALENDARS_TASK_ID, async () => {
if (!(await isMacOS())) {
return;
}

try {
const { commands } = await import("@hypr/plugin-apple-calendar");
const result = await commands.syncCalendars();
if (result.status === "error") {
console.error("Failed to sync calendars:", result.error);
}
} catch (error) {
console.error("Failed to sync calendars:", error);
}
});

useScheduleTaskRun(SYNC_CALENDARS_TASK_ID, undefined, 0, {
repeatDelay: SYNC_CALENDARS_INTERVAL,
});

useSetTask(SYNC_EVENTS_TASK_ID, async () => {
if (!(await isMacOS())) {
return;
}

try {
const { commands } = await import("@hypr/plugin-apple-calendar");
const result = await commands.syncEvents();
if (result.status === "error") {
console.error("Failed to sync events:", result.error);
}
} catch (error) {
console.error("Failed to sync events:", error);
}
});

useScheduleTaskRun(SYNC_EVENTS_TASK_ID, undefined, 0, {
repeatDelay: SYNC_EVENTS_INTERVAL,
});

return null;
}
57 changes: 54 additions & 3 deletions apps/desktop/src/store/tinybase/schema-external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,44 @@ export const eventSchema = baseEventSchema.omit({ id: true }).extend({
meeting_link: z.preprocess((val) => val ?? undefined, z.string().optional()),
description: z.preprocess((val) => val ?? undefined, z.string().optional()),
note: z.preprocess((val) => val ?? undefined, z.string().optional()),
tracking_id: z.preprocess((val) => val ?? undefined, z.string().optional()),
provider: z.preprocess(
(val) => val ?? undefined,
z.enum(["apple", "google", "outlook"]).optional(),
),
participants: z.preprocess((val) => val ?? undefined, z.string().optional()),
is_recurring: z.preprocess((val) => val ?? undefined, z.boolean().optional()),
recurrence_rule: z.preprocess(
(val) => val ?? undefined,
z.string().optional(),
),
all_day: z.preprocess((val) => val ?? undefined, z.boolean().optional()),
timezone: z.preprocess((val) => val ?? undefined, z.string().optional()),
status: z.preprocess((val) => val ?? undefined, z.string().optional()),
visibility: z.preprocess((val) => val ?? undefined, z.string().optional()),
organizer_name: z.preprocess(
(val) => val ?? undefined,
z.string().optional(),
),
organizer_email: z.preprocess(
(val) => val ?? undefined,
z.string().optional(),
),
provider_url: z.preprocess((val) => val ?? undefined, z.string().optional()),
});

export const calendarSchema = baseCalendarSchema
.omit({ id: true })
.extend({ created_at: z.string() });
export const calendarSchema = baseCalendarSchema.omit({ id: true }).extend({
created_at: z.string(),
tracking_id: z.preprocess((val) => val ?? undefined, z.string().optional()),
provider: z.preprocess(
(val) => val ?? undefined,
z.enum(["apple", "google", "outlook"]).optional(),
),
selected: z.preprocess((val) => val ?? undefined, z.boolean().optional()),
source: z.preprocess((val) => val ?? undefined, z.string().optional()),
color: z.preprocess((val) => val ?? undefined, z.string().optional()),
timezone: z.preprocess((val) => val ?? undefined, z.string().optional()),
});

export const organizationSchema = baseOrganizationSchema
.omit({ id: true })
Expand Down Expand Up @@ -239,6 +272,12 @@ export const externalTableSchemaForTinybase = {
user_id: { type: "string" },
created_at: { type: "string" },
name: { type: "string" },
tracking_id: { type: "string" },
provider: { type: "string" },
selected: { type: "boolean" },
source: { type: "string" },
color: { type: "string" },
timezone: { type: "string" },
} satisfies InferTinyBaseSchema<typeof calendarSchema>,
events: {
user_id: { type: "string" },
Expand All @@ -251,6 +290,18 @@ export const externalTableSchemaForTinybase = {
meeting_link: { type: "string" },
description: { type: "string" },
note: { type: "string" },
tracking_id: { type: "string" },
provider: { type: "string" },
participants: { type: "string" },
is_recurring: { type: "boolean" },
recurrence_rule: { type: "string" },
all_day: { type: "boolean" },
timezone: { type: "string" },
status: { type: "string" },
visibility: { type: "string" },
organizer_name: { type: "string" },
organizer_email: { type: "string" },
provider_url: { type: "string" },
} satisfies InferTinyBaseSchema<typeof eventSchema>,
mapping_session_participant: {
user_id: { type: "string" },
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading