-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init Signed-off-by: Innei <i@innei.in> * feat: offline Signed-off-by: Innei <i@innei.in> * fix: update Signed-off-by: Innei <i@innei.in> * fix: chain Signed-off-by: Innei <i@innei.in> * update Signed-off-by: Innei <i@innei.in> * update Signed-off-by: Innei <i@innei.in> * update Signed-off-by: Innei <i@innei.in> * update Signed-off-by: Innei <i@innei.in> * feat: render social media with full text --------- Signed-off-by: Innei <i@innei.in> Co-authored-by: DIYgod <i@diygod.me>
- Loading branch information
Showing
19 changed files
with
1,111 additions
and
507 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { SVGProps } from "react" | ||
|
||
export function PhCloudCheck(props: SVGProps<SVGSVGElement>) { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="1em" | ||
height="1em" | ||
viewBox="0 0 256 256" | ||
{...props} | ||
> | ||
<path | ||
fill="currentColor" | ||
d="M160 40a88.09 88.09 0 0 0-78.71 48.67A64 64 0 1 0 72 216h88a88 88 0 0 0 0-176m0 160H72a48 48 0 0 1 0-96c1.1 0 2.2 0 3.29.11A88 88 0 0 0 72 128a8 8 0 0 0 16 0a72 72 0 1 1 72 72m37.66-93.66a8 8 0 0 1 0 11.32l-48 48a8 8 0 0 1-11.32 0l-24-24a8 8 0 0 1 11.32-11.32L144 148.69l42.34-42.35a8 8 0 0 1 11.32 0" | ||
/> | ||
</svg> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { SVGProps } from "react" | ||
|
||
export function PhCloudX(props: SVGProps<SVGSVGElement>) { | ||
return ( | ||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256" {...props}><path fill="currentColor" d="M160 40a88.09 88.09 0 0 0-78.71 48.67A64 64 0 1 0 72 216h88a88 88 0 0 0 0-176m0 160H72a48 48 0 0 1 0-96c1.1 0 2.2 0 3.29.11A88 88 0 0 0 72 128a8 8 0 0 0 16 0a72 72 0 1 1 72 72m29.66-82.34L171.31 136l18.35 18.34a8 8 0 0 1-11.32 11.32L160 147.31l-18.34 18.35a8 8 0 0 1-11.32-11.32L148.69 136l-18.35-18.34a8 8 0 0 1 11.32-11.32L160 124.69l18.34-18.35a8 8 0 0 1 11.32 11.32" /></svg> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { repository } from "@pkg" | ||
import { appLog } from "@renderer/lib/log" | ||
import { getStorageNS } from "@renderer/lib/ns" | ||
import { createElement } from "react" | ||
import { toast } from "sonner" | ||
|
||
import { waitAppReady } from "../queue" | ||
|
||
const appVersionKey = getStorageNS("app_version") | ||
|
||
export const doMigration = () => { | ||
const lastVersion = localStorage.getItem(appVersionKey) | ||
|
||
if (lastVersion && lastVersion !== APP_VERSION) { | ||
appLog(`Upgrade from ${lastVersion} to ${APP_VERSION}`) | ||
|
||
waitAppReady(() => { | ||
toast.success( | ||
// `App is upgraded to ${APP_VERSION}, enjoy the new features! 🎉`, | ||
createElement("div", { | ||
children: [ | ||
"App is upgraded to ", | ||
createElement( | ||
"a", | ||
{ | ||
href: `${repository.url}/releases/tag/${APP_VERSION}`, | ||
target: "_blank", | ||
className: "underline", | ||
}, | ||
createElement("strong", { | ||
children: APP_VERSION, | ||
}), | ||
), | ||
", enjoy the new features! 🎉", | ||
], | ||
}), | ||
) | ||
}, 1000) | ||
|
||
// NOTE: Add migration logic here | ||
} | ||
localStorage.setItem(appVersionKey, APP_VERSION) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type | ||
export interface CustomEvent {} | ||
export interface EventBusMap extends CustomEvent {} | ||
|
||
class EventBusEvent extends Event { | ||
static type = "EventBusEvent" | ||
constructor(public _type: string, public data: any) { | ||
super(EventBusEvent.type) | ||
} | ||
} | ||
class EventBusStatic { | ||
dispatch<T extends keyof EventBusMap>(event: T, data: EventBusMap[T]) { | ||
window.dispatchEvent(new EventBusEvent(event, data)) | ||
} | ||
|
||
subscribe<T extends keyof EventBusMap>( | ||
event: T, | ||
callback: (data: EventBusMap[T]) => void, | ||
) { | ||
const handler = (e: any) => { | ||
if (e instanceof EventBusEvent && e._type === event) { | ||
callback(e.data) | ||
} | ||
} | ||
window.addEventListener(EventBusEvent.type, handler) | ||
|
||
return this.unsubscribe.bind(this, event, handler) | ||
} | ||
|
||
unsubscribe(event: string, handler: (e: any) => void) { | ||
window.removeEventListener(EventBusEvent.type, handler) | ||
} | ||
} | ||
|
||
export const EventBus = new EventBusStatic() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/renderer/src/modules/settings/helper/SyncIndicator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { PhCloudCheck } from "@renderer/components/icons/PhCloudCheck" | ||
import { PhCloudX } from "@renderer/components/icons/PhCloudX" | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipTrigger, | ||
} from "@renderer/components/ui/tooltip" | ||
import { useAuthQuery, useIsOnline } from "@renderer/hooks/common" | ||
import { settings } from "@renderer/queries/settings" | ||
import { useEffect, useRef } from "react" | ||
|
||
import { settingSyncQueue } from "./sync-queue" | ||
|
||
export const SyncIndicator = () => { | ||
const { data: remoteSettings, isLoading } = useAuthQuery(settings.get(), {}) | ||
|
||
const isOnline = useIsOnline() | ||
const onceRef = useRef(false) | ||
useEffect(() => { | ||
if (!isLoading && remoteSettings && !onceRef.current) { | ||
const hasSetting = JSON.stringify(remoteSettings.settings) !== "{}" | ||
onceRef.current = true | ||
if (hasSetting) { | ||
return | ||
} | ||
// Replace local to remote | ||
settingSyncQueue.replaceRemote() | ||
} | ||
}, [remoteSettings, isLoading]) | ||
|
||
return ( | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<div className="center absolute right-2 size-5"> | ||
{isOnline ? ( | ||
<PhCloudCheck className="size-4" /> | ||
) : ( | ||
<PhCloudX className="size-4" /> | ||
)} | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent> | ||
<div className="text-center text-xs"> | ||
{isOnline ? "Synced with server" : "Offline"} | ||
</div> | ||
</TooltipContent> | ||
</Tooltip> | ||
) | ||
} |
Oops, something went wrong.