Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function create($container, $toggler) {
return;
}

defaultAvatar.classList.add("loading");
defaultAvatar.classList.add("avatar-loading");

const img = <img alt="User avatar" className="avatar" />;
const avatarFile = await getUserAvatar(user);
Expand Down
22 changes: 22 additions & 0 deletions src/components/sidebar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ body.no-animation {
&.active {
opacity: 1;
}

&.avatar-loading {
opacity: 0.45;
background-color: rgba(255, 255, 255, 0.08);
animation: sidebar-avatar-loading 1.2s ease-in-out infinite;

&:hover {
opacity: 0.45;
background-color: rgba(255, 255, 255, 0.08);
}
}
}
}

Expand Down Expand Up @@ -340,6 +351,17 @@ body.no-animation {
}
}

@keyframes sidebar-avatar-loading {
0%,
100% {
transform: scale(1);
}

50% {
transform: scale(0.94);
}
}

.user-menu {
position: absolute;
bottom: 55px;
Expand Down
4 changes: 4 additions & 0 deletions src/handlers/intent.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export default async function HandleIntent(intent = {}) {
const path = url.replace("acode://", "");
const [module, action, value] = path.split("/");

if (module === "auth" && action === "callback") {
return;
}

let defaultPrevented = false;
const event = new IntentEvent(module, action, value);
for (const handler of handlers) {
Expand Down
48 changes: 18 additions & 30 deletions src/lib/auth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import toast from "components/toast";
import { addIntentHandler } from "handlers/intent";
import config from "./config";
import customTab from "./customTab";

/**
* @typedef {object} User
Expand Down Expand Up @@ -29,6 +26,7 @@ let loggedInUser = null;
let cacheTimeout = null;

const CACHE_USER_KEY = "cached-logged-in-user";
const LOGIN_RESUME_TIMEOUT_MS = 60_000;

const loginEvents = {
listeners: new Set(),
Expand All @@ -50,7 +48,6 @@ class AuthService {
#loginTimeout = null;

constructor() {
addIntentHandler(this.onIntentReceiver.bind(this));
loginEvents.addListener(() => {
clearTimeout(this.#loginTimeout);
for (const callback of this.#loginCallbacks) {
Expand All @@ -66,29 +63,10 @@ class AuthService {
}

this.#loginCallbacks.clear();
}, 1000);
}, LOGIN_RESUME_TIMEOUT_MS);
});
}

async onIntentReceiver(event) {
try {
if (event?.module === "user" && event?.action === "login") {
if (event?.value) {
this.#exec("saveToken", [event.value]);
toast("Logged in successfully");

setTimeout(() => {
loginEvents.emit();
}, 500);
}
}
return null;
} catch (error) {
console.error("Failed to parse intent token.", error);
return null;
}
}

/**
* Helper to wrap cordova.exec in a Promise
*/
Expand Down Expand Up @@ -159,12 +137,22 @@ class AuthService {

async login() {
return new Promise((resolve, reject) => {
customTab(`${config.BASE_URL}/login?redirect=app`).catch((err) => {
console.error("Custom tab error", err);
reject("Failed to open browser");
});

this.#loginCallbacks.add({ resolve, reject });
const callback = { resolve, reject };
this.#loginCallbacks.add(callback);
this.#exec("login", [
{
baseUrl: config.BASE_URL,
appVersionCode: window.BuildInfo?.versionCode || 0,
},
])
.then(() => {
loginEvents.emit();
})
.catch((err) => {
console.error("Native login error", err);
this.#loginCallbacks.delete(callback);
reject("Failed to login");
});
});
}
}
Expand Down
22 changes: 21 additions & 1 deletion src/lib/checkPluginsUpdate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fsOperation from "fileSystem";
import Url from "utils/Url";
import { isVersionGreater } from "utils/version";
import config from "./config";

export default async function checkPluginsUpdate() {
Expand All @@ -20,7 +21,26 @@ export default async function checkPluginsUpdate() {

if (res.ok) {
const json = await res.json();
if (json.update) {
if (!json.update) return;

if (json.version) {
if (isVersionGreater(json.version, plugin.version)) {
updates.push(plugin.id);
}
return;
}

const remotePlugin = await fsOperation(
config.API_BASE,
`plugin/${plugin.id}`,
)
.readFile("json")
.catch(() => null);

if (
!remotePlugin?.version ||
isVersionGreater(remotePlugin.version, plugin.version)
) {
updates.push(plugin.id);
Comment thread
greptile-apps[bot] marked this conversation as resolved.
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/installPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import purchaseListener from "handlers/purchase";
import JSZip from "jszip";
import helpers from "utils/helpers";
import Url from "utils/Url";
import { isVersionGreater } from "utils/version";
import config from "./config";
import InstallState from "./installState";
import { loadPluginWithTimeout } from "./loadPlugins";
Expand Down Expand Up @@ -406,7 +407,8 @@ async function resolveDepsManifest(deps) {
throw new Error(`Unknown plugin dependency: ${dependency}`);

const version = await getInstalledPluginVersion(remoteDependency.id);
if (remoteDependency?.version === version) continue;
if (version && !isVersionGreater(remoteDependency?.version, version))
continue;

if (remoteDependency.dependencies) {
const manifests = await resolveDepsManifest(
Expand Down
6 changes: 5 additions & 1 deletion src/pages/plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import markdownItTaskLists from "markdown-it-task-lists";
import { highlightCodeBlock, initHighlighting } from "utils/codeHighlight";
import helpers from "utils/helpers";
import Url from "utils/Url";
import { isVersionGreater } from "utils/version";
import view, { cleanups } from "./plugin.view.js";

let $lastPluginPage;
Expand Down Expand Up @@ -160,7 +161,10 @@ export default async function PluginInclude(

if (cancelled || !remotePlugin) return;

if (installed && remotePlugin?.version !== plugin.version) {
if (
installed &&
isVersionGreater(remotePlugin?.version, plugin.version)
) {
currentVersion = plugin.version;
update = true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/auth/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
</config-file>

<framework src="androidx.security:security-crypto:1.1.0" />
<framework src="androidx.browser:browser:1.5.0" />

<source-file src="src/android/Authenticator.java" target-dir="src/com/foxdebug/acode/rk/auth" />
<source-file src="src/android/EncryptedPreferenceManager.java" target-dir="src/com/foxdebug/acode/rk/auth" />


</platform>
</plugin>
</plugin>
Loading