mirror of
https://github.com/NoCrypt/migu.git
synced 2026-04-14 05:20:22 +00:00
feat: capacitor notifications
fix: capacitor version in settings
This commit is contained in:
parent
14f33029c3
commit
41d85a15a9
9 changed files with 135 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,7 +4,6 @@
|
|||
# Build output
|
||||
**/dist/
|
||||
**/build/
|
||||
**/android/
|
||||
|
||||
# Dependencies
|
||||
node_modules
|
||||
|
|
|
|||
2
capacitor/.gitignore
vendored
2
capacitor/.gitignore
vendored
|
|
@ -1,7 +1,9 @@
|
|||
/node_modules/
|
||||
android/*
|
||||
!android/variables.gradle
|
||||
!android/app
|
||||
android/app/*
|
||||
!android/app/build.gradle
|
||||
!android/app/src
|
||||
android/app/src/*
|
||||
!android/app/src/main
|
||||
|
|
|
|||
65
capacitor/android/app/build.gradle
Normal file
65
capacitor/android/app/build.gradle
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
def verCode = 0
|
||||
|
||||
def jsonFile = file('../../../electron/package.json')
|
||||
def parsedJson = new groovy.json.JsonSlurper().parseText(jsonFile.text)
|
||||
def verName = parsedJson.version
|
||||
def versions = verName.tokenize('.')
|
||||
|
||||
versions.each (code) -> {
|
||||
verCode = (verCode*100) + Integer.parseInt(code)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "watch.miru"
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
defaultConfig {
|
||||
applicationId "watch.miru"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode verCode
|
||||
versionName verName
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
aaptOptions {
|
||||
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
||||
// Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
|
||||
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
flatDir{
|
||||
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
||||
implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
|
||||
implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
|
||||
implementation project(':capacitor-android')
|
||||
testImplementation "junit:junit:$junitVersion"
|
||||
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
||||
implementation project(':capacitor-cordova-android-plugins')
|
||||
}
|
||||
|
||||
apply from: 'capacitor.build.gradle'
|
||||
|
||||
try {
|
||||
def servicesJSON = file('google-services.json')
|
||||
if (servicesJSON.text) {
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
}
|
||||
} catch(Exception e) {
|
||||
logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
|
||||
}
|
||||
16
capacitor/android/variables.gradle
Normal file
16
capacitor/android/variables.gradle
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
ext {
|
||||
minSdkVersion = 22
|
||||
compileSdkVersion = 33
|
||||
targetSdkVersion = 33
|
||||
androidxActivityVersion = '1.7.0'
|
||||
androidxAppCompatVersion = '1.6.1'
|
||||
androidxCoordinatorLayoutVersion = '1.2.0'
|
||||
androidxCoreVersion = '1.10.0'
|
||||
androidxFragmentVersion = '1.5.6'
|
||||
coreSplashScreenVersion = '1.0.0'
|
||||
androidxWebkitVersion = '1.6.1'
|
||||
junitVersion = '4.13.2'
|
||||
androidxJunitVersion = '1.1.5'
|
||||
androidxEspressoCoreVersion = '3.5.1'
|
||||
cordovaAndroidVersion = '10.1.1'
|
||||
}
|
||||
|
|
@ -31,6 +31,7 @@
|
|||
"@capacitor/cli": "^5.5.1",
|
||||
"@capacitor/core": "^5.5.1",
|
||||
"@capacitor/ios": "^5.5.1",
|
||||
"@capacitor/local-notifications": "5.0.8",
|
||||
"@capacitor/status-bar": "^5.0.6",
|
||||
"capacitor-nodejs": "https://github.com/funniray/Capacitor-NodeJS/releases/download/nodejs-18/capacitor-nodejs-1.0.0-beta.6.tgz",
|
||||
"capacitor-plugin-safe-area": "^2.0.5",
|
||||
|
|
|
|||
|
|
@ -3,12 +3,43 @@ import { StatusBar, Style } from '@capacitor/status-bar'
|
|||
import { SafeArea } from 'capacitor-plugin-safe-area'
|
||||
import { App } from '@capacitor/app'
|
||||
import { Browser } from '@capacitor/browser'
|
||||
import { LocalNotifications } from '@capacitor/local-notifications'
|
||||
import IPC from './ipc.js'
|
||||
|
||||
IPC.on('open', url => Browser.open({ url }))
|
||||
|
||||
App.addListener('appUrlOpen', ({ url }) => handleProtocol(url))
|
||||
|
||||
let canShowNotifications = false
|
||||
|
||||
LocalNotifications.checkPermissions().then(async value => {
|
||||
if (value) {
|
||||
try {
|
||||
await LocalNotifications.requestPermissions()
|
||||
canShowNotifications = true
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
let id = 0
|
||||
IPC.on('notification', noti => {
|
||||
/** @type {import('@capacitor/local-notifications').LocalNotificationSchema} */
|
||||
const notification = {
|
||||
title: noti.title,
|
||||
body: noti.body,
|
||||
id: id++,
|
||||
attachments: [
|
||||
{
|
||||
id: '' + id++,
|
||||
url: noti.icon
|
||||
}
|
||||
]
|
||||
}
|
||||
if (canShowNotifications) LocalNotifications.schedule({ notifications: [notification] })
|
||||
})
|
||||
|
||||
// schema: miru://key/value
|
||||
const protocolMap = {
|
||||
auth: token => sendToken(token),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { App } from '@capacitor/app'
|
||||
import { NodeJS } from 'capacitor-nodejs'
|
||||
import EventEmitter from 'events'
|
||||
|
||||
|
|
@ -25,6 +26,10 @@ const [_platform, arch] = navigator.platform.split(' ')
|
|||
|
||||
globalThis.version = {
|
||||
platform: globalThis.cordova?.platformId,
|
||||
arch,
|
||||
version: globalThis.cordova?.version
|
||||
arch
|
||||
}
|
||||
|
||||
main.once('version', async () => {
|
||||
const { version } = await App.getInfo()
|
||||
main.emit('version', version)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@
|
|||
|
||||
<div class='w-full z-101 navbar bg-transparent border-0 p-0 d-flex'>
|
||||
<div class='d-flex h-full draggable align-items-center text-center'>
|
||||
{#if window.version.platform !== 'darwin'}
|
||||
{#if window.version?.platform !== 'darwin'}
|
||||
<img src='./logo_filled.png' class='position-absolute w-50 h-50 m-10 pointer d-md-block d-none p-5' alt='ico' use:click={close} />
|
||||
{/if}
|
||||
</div>
|
||||
<div class='h-full bg-dark flex-grow-1'>
|
||||
{#if window.version.platform === 'linux'}
|
||||
{#if window.version?.platform === 'linux'}
|
||||
<div class='d-flex align-items-center close h-full' use:click={() => IPC.emit('close')}>
|
||||
<svg viewBox='0 0 24 24'>
|
||||
<path d='M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z' />
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@ importers:
|
|||
'@capacitor/ios':
|
||||
specifier: ^5.5.1
|
||||
version: 5.5.1(@capacitor/core@5.5.1)
|
||||
'@capacitor/local-notifications':
|
||||
specifier: 5.0.8
|
||||
version: 5.0.8(@capacitor/core@5.5.1)
|
||||
'@capacitor/status-bar':
|
||||
specifier: ^5.0.6
|
||||
version: 5.0.6(@capacitor/core@5.5.1)
|
||||
|
|
@ -374,6 +377,14 @@ packages:
|
|||
'@capacitor/core': 5.5.1
|
||||
dev: false
|
||||
|
||||
/@capacitor/local-notifications@5.0.8(@capacitor/core@5.5.1):
|
||||
resolution: {integrity: sha512-rNmEF1OntokzcKtb4H9hAF//4Z6svWxRlzlNHP3Am7Q9WdNScmq/KjolX4Z9tLGHapF6JfBytdADih5KHjB45A==}
|
||||
peerDependencies:
|
||||
'@capacitor/core': ^5.0.0
|
||||
dependencies:
|
||||
'@capacitor/core': 5.5.1
|
||||
dev: false
|
||||
|
||||
/@capacitor/status-bar@5.0.6(@capacitor/core@5.5.1):
|
||||
resolution: {integrity: sha512-7od8CxsBnot1XMK3IeOkproFL4hgoKoWAc3pwUvmDOkQsXoxwQm4SR9mLwQavv1XfxtHbFV9Ukd7FwMxOPSViw==}
|
||||
peerDependencies:
|
||||
|
|
|
|||
Loading…
Reference in a new issue