From a0291b40b20ee60f7791992708a1688ffee6ce8a Mon Sep 17 00:00:00 2001 From: cutestnekoaqua Date: Tue, 4 Apr 2023 22:15:56 +0200 Subject: [PATCH] app work --- packages/client/android/.idea/.gitignore | 3 + packages/client/android/.idea/compiler.xml | 6 + .../client/android/.idea/jarRepositories.xml | 30 +++++ packages/client/android/.idea/misc.xml | 10 ++ .../client/android/app/capacitor.build.gradle | 11 +- .../java/org/calckey/app/MainActivity.java | 18 ++- .../client/android/capacitor.settings.gradle | 18 +++ packages/client/ios/App/App/Info.plist | 4 + packages/client/ios/App/Podfile | 8 +- packages/client/package.json | 1 + packages/client/src/account.ts | 79 ++++++++----- packages/client/src/components/MkMention.vue | 8 ++ packages/client/src/components/MkMenu.vue | 3 + packages/client/src/components/MkSignin.vue | 99 +++++++++++++++- .../client/src/components/global/MkEmoji.vue | 12 +- packages/client/src/config.ts | 13 ++- packages/client/src/init.ts | 107 ++++++++++++++++-- packages/client/src/os.ts | 4 + packages/client/src/pages/timeline.vue | 10 ++ .../client/src/pages/welcome.entrance.a.vue | 80 ++++++++++++- .../client/src/pages/welcome.entrance.c.vue | 4 + packages/client/src/pages/welcome.vue | 10 +- packages/client/src/scripts/theme.ts | 10 ++ packages/client/src/stream.ts | 4 + packages/client/src/ui/visitor/b.vue | 5 - pnpm-lock.yaml | 11 ++ 26 files changed, 505 insertions(+), 63 deletions(-) create mode 100644 packages/client/android/.idea/.gitignore create mode 100644 packages/client/android/.idea/compiler.xml create mode 100644 packages/client/android/.idea/jarRepositories.xml create mode 100644 packages/client/android/.idea/misc.xml diff --git a/packages/client/android/.idea/.gitignore b/packages/client/android/.idea/.gitignore new file mode 100644 index 0000000000..26d33521af --- /dev/null +++ b/packages/client/android/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/packages/client/android/.idea/compiler.xml b/packages/client/android/.idea/compiler.xml new file mode 100644 index 0000000000..fb7f4a8a46 --- /dev/null +++ b/packages/client/android/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/packages/client/android/.idea/jarRepositories.xml b/packages/client/android/.idea/jarRepositories.xml new file mode 100644 index 0000000000..ea098ab876 --- /dev/null +++ b/packages/client/android/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/client/android/.idea/misc.xml b/packages/client/android/.idea/misc.xml new file mode 100644 index 0000000000..bdd92780c2 --- /dev/null +++ b/packages/client/android/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/packages/client/android/app/capacitor.build.gradle b/packages/client/android/app/capacitor.build.gradle index f7b6b917ee..1f93fdde42 100644 --- a/packages/client/android/app/capacitor.build.gradle +++ b/packages/client/android/app/capacitor.build.gradle @@ -9,10 +9,15 @@ android { apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle" dependencies { - - + implementation project(':capacitor-app') + implementation project(':capacitor-camera') + implementation project(':capacitor-device') + implementation project(':capacitor-preferences') + implementation project(':capacitor-push-notifications') + implementation project(':capacitor-status-bar') + implementation "com.onesignal:OneSignal:4.8.5" } - +apply from: "../../../../node_modules/.pnpm/onesignal-cordova-plugin@3.3.1/node_modules/onesignal-cordova-plugin/build-extras-onesignal.gradle" if (hasProperty('postBuildExtras')) { postBuildExtras() diff --git a/packages/client/android/app/src/main/java/org/calckey/app/MainActivity.java b/packages/client/android/app/src/main/java/org/calckey/app/MainActivity.java index 80ff2dc2a0..b54348eab3 100644 --- a/packages/client/android/app/src/main/java/org/calckey/app/MainActivity.java +++ b/packages/client/android/app/src/main/java/org/calckey/app/MainActivity.java @@ -1,6 +1,13 @@ package org.calckey.app; +import android.content.res.Configuration; +import android.os.Bundle; +import android.webkit.WebSettings; + import com.getcapacitor.BridgeActivity; +import com.getcapacitor.Plugin; + +import java.util.ArrayList; public class MainActivity extends BridgeActivity { void setDarkMode() { @@ -34,15 +41,4 @@ public class MainActivity extends BridgeActivity { super.onResume(); setDarkMode(); } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Initializes the Bridge - this.init(savedInstanceState, new ArrayList>() {{ - // Additional plugins you've installed go here - // Ex: add(TotallyAwesomePlugin.class); - }}); - } } diff --git a/packages/client/android/capacitor.settings.gradle b/packages/client/android/capacitor.settings.gradle index fc4d32baf8..f48010eff3 100644 --- a/packages/client/android/capacitor.settings.gradle +++ b/packages/client/android/capacitor.settings.gradle @@ -1,3 +1,21 @@ // DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN include ':capacitor-android' project(':capacitor-android').projectDir = new File('../../../node_modules/.pnpm/@capacitor+android@4.7.3_@capacitor+core@4.7.3/node_modules/@capacitor/android/capacitor') + +include ':capacitor-app' +project(':capacitor-app').projectDir = new File('../../../node_modules/.pnpm/@capacitor+app@4.1.1_@capacitor+core@4.7.3/node_modules/@capacitor/app/android') + +include ':capacitor-camera' +project(':capacitor-camera').projectDir = new File('../../../node_modules/.pnpm/@capacitor+camera@4.1.4_@capacitor+core@4.7.3/node_modules/@capacitor/camera/android') + +include ':capacitor-device' +project(':capacitor-device').projectDir = new File('../../../node_modules/.pnpm/@capacitor+device@4.1.0_@capacitor+core@4.7.3/node_modules/@capacitor/device/android') + +include ':capacitor-preferences' +project(':capacitor-preferences').projectDir = new File('../../../node_modules/.pnpm/@capacitor+preferences@4.0.2_@capacitor+core@4.7.3/node_modules/@capacitor/preferences/android') + +include ':capacitor-push-notifications' +project(':capacitor-push-notifications').projectDir = new File('../../../node_modules/.pnpm/@capacitor+push-notifications@4.1.2_@capacitor+core@4.7.3/node_modules/@capacitor/push-notifications/android') + +include ':capacitor-status-bar' +project(':capacitor-status-bar').projectDir = new File('../../../node_modules/.pnpm/@capacitor+status-bar@4.1.1_@capacitor+core@4.7.3/node_modules/@capacitor/status-bar/android') diff --git a/packages/client/ios/App/App/Info.plist b/packages/client/ios/App/App/Info.plist index 833cbf1137..0120fe1fcc 100644 --- a/packages/client/ios/App/App/Info.plist +++ b/packages/client/ios/App/App/Info.plist @@ -16,6 +16,10 @@ $(PRODUCT_NAME) CFBundlePackageType APPL + UIBackgroundModes + + remote-notification + CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion diff --git a/packages/client/ios/App/Podfile b/packages/client/ios/App/Podfile index 99ddee0773..e6a47de3c7 100644 --- a/packages/client/ios/App/Podfile +++ b/packages/client/ios/App/Podfile @@ -11,7 +11,13 @@ install! 'cocoapods', :disable_input_output_paths => true def capacitor_pods pod 'Capacitor', :path => '../../../../node_modules/.pnpm/@capacitor+ios@4.7.3_@capacitor+core@4.7.3/node_modules/@capacitor/ios' pod 'CapacitorCordova', :path => '../../../../node_modules/.pnpm/@capacitor+ios@4.7.3_@capacitor+core@4.7.3/node_modules/@capacitor/ios' - + pod 'CapacitorApp', :path => '../../../../node_modules/.pnpm/@capacitor+app@4.1.1_@capacitor+core@4.7.3/node_modules/@capacitor/app' + pod 'CapacitorCamera', :path => '../../../../node_modules/.pnpm/@capacitor+camera@4.1.4_@capacitor+core@4.7.3/node_modules/@capacitor/camera' + pod 'CapacitorDevice', :path => '../../../../node_modules/.pnpm/@capacitor+device@4.1.0_@capacitor+core@4.7.3/node_modules/@capacitor/device' + pod 'CapacitorPreferences', :path => '../../../../node_modules/.pnpm/@capacitor+preferences@4.0.2_@capacitor+core@4.7.3/node_modules/@capacitor/preferences' + pod 'CapacitorPushNotifications', :path => '../../../../node_modules/.pnpm/@capacitor+push-notifications@4.1.2_@capacitor+core@4.7.3/node_modules/@capacitor/push-notifications' + pod 'CapacitorStatusBar', :path => '../../../../node_modules/.pnpm/@capacitor+status-bar@4.1.1_@capacitor+core@4.7.3/node_modules/@capacitor/status-bar' + pod 'CordovaPluginsStatic', :path => '../capacitor-cordova-ios-plugins' end target 'App' do diff --git a/packages/client/package.json b/packages/client/package.json index c22f74c2b0..01b10d5114 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -95,6 +95,7 @@ "dependencies": { "@capacitor/android": "^4.7.3", "@capacitor/app": "^4.1.1", + "@capacitor/camera": "^4.1.4", "@capacitor/core": "^4.7.3", "@capacitor/device": "^4.1.0", "@capacitor/ios": "^4.7.3", diff --git a/packages/client/src/account.ts b/packages/client/src/account.ts index 9a423b4cb6..6543ee7f3f 100644 --- a/packages/client/src/account.ts +++ b/packages/client/src/account.ts @@ -4,6 +4,7 @@ import { showSuspendedDialog } from "./scripts/show-suspended-dialog"; import { i18n } from "./i18n"; import { del, get, set } from "@/scripts/idb-proxy"; // #v-ifdef VITE_CAPACITOR +//... // #v-else import { apiUrl } from "@/config"; // #v-endif @@ -44,6 +45,7 @@ export async function signout() { const accounts = await getAccounts(); // #v-ifdef VITE_CAPACITOR +//... // #v-else //#region Remove service worker registration try { @@ -117,7 +119,32 @@ export async function removeAccount(id: Account["id"]) { if (accounts.length > 0) await set("accounts", accounts); else await del("accounts"); } - +// #v-ifdef VITE_CAPACITOR +function fetchAccount( + token: string, + instanceUrl: string +): Promise { + return new misskey.api.APIClient({ origin: instanceUrl, credential: token }) + .request("i") + .then((res) => { + return { ...(res as Account), token, instanceUrl }; + }) + .catch((res) => { + if (res.error.id === "a8c724b3-6e9c-4b46-b1a8-bc3ed6258370") { + showSuspendedDialog().then(() => { + signout(); + }); + } else { + alert({ + type: "error", + title: i18n.ts.failedToFetchAccountInformation, + text: JSON.stringify(res.error), + }); + } + return Promise.reject(res); + }); +} +// #v-else function fetchAccount(token: string): Promise { return new Promise((done, fail) => { // Fetch user @@ -149,32 +176,7 @@ function fetchAccount(token: string): Promise { .catch(fail); }); } - -function fetchAccount( - token: string, - instanceUrl: string -): Promise { - return new misskey.api.APIClient({ origin: instanceUrl, credential: token }) - .request("i") - .then((res) => { - return { ...(res as Account), token, instanceUrl }; - }) - .catch((res) => { - if (res.error.id === "a8c724b3-6e9c-4b46-b1a8-bc3ed6258370") { - showSuspendedDialog().then(() => { - signout(); - }); - } else { - alert({ - type: "error", - title: i18n.ts.failedToFetchAccountInformation, - text: JSON.stringify(res.error), - }); - } - return Promise.reject(res); - }); -} - +// #v-endif export function updateAccount(accountData: Object) { for (const [key, value] of Object.entries(accountData)) { $i[key] = value; @@ -325,11 +327,30 @@ export async function openAccountMenu( const accountItemPromises = storedAccounts.map( (a) => new Promise((res) => { + // #v-ifdef VITE_CAPACITOR + const client = new misskey.api.APIClient({ + origin: a.instanceUrl, + credential: a.token, + }); + client + .request("users/show", { + userIds: [a.id], + }) + .then((accounts) => { + const account = accounts.find((x) => x.id === a.id); + if (account == null) return res(null); + + client.request("meta").then((meta) => { + res(createItem({ ...account, host: meta.name })); + }); + }); + // #v-else accountsPromise.then((accounts) => { const account = accounts.find((x) => x.id === a.id); if (account == null) return res(null); res(createItem(account)); }); + // #v-endif }), ); @@ -357,12 +378,16 @@ export async function openAccountMenu( showSigninDialog(); }, }, + // #v-ifdef VITE_CAPACITOR + //... + // #v-else { text: i18n.ts.createAccount, action: () => { createAccount(); }, }, + // #v-endif ], }, { diff --git a/packages/client/src/components/MkMention.vue b/packages/client/src/components/MkMention.vue index 2a73404214..b8563510d6 100644 --- a/packages/client/src/components/MkMention.vue +++ b/packages/client/src/components/MkMention.vue @@ -1,6 +1,14 @@