Skip to content

Commit

Permalink
fix: replace cordova-inappbrowser with capacitor/browser
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed Jul 21, 2024
1 parent 191358a commit f8ad240
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 73 deletions.
1 change: 1 addition & 0 deletions android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
implementation project(':byteowls-capacitor-oauth2')
implementation project(':capacitor-app')
implementation project(':capacitor-browser')
implementation project(':capacitor-device')
implementation project(':capacitor-filesystem')
implementation project(':capacitor-network')
Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/assets/capacitor.plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"pkg": "@capacitor/app",
"classpath": "com.capacitorjs.plugins.app.AppPlugin"
},
{
"pkg": "@capacitor/browser",
"classpath": "com.capacitorjs.plugins.browser.BrowserPlugin"
},
{
"pkg": "@capacitor/device",
"classpath": "com.capacitorjs.plugins.device.DevicePlugin"
Expand Down
8 changes: 0 additions & 8 deletions android/app/src/main/res/xml/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,5 @@
<widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<access origin="*" />

<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device"/>
</feature>

<feature name="InAppBrowser">
<param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser"/>
</feature>


</widget>
3 changes: 3 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ project(':byteowls-capacitor-oauth2').projectDir = new File('../node_modules/@by
include ':capacitor-app'
project(':capacitor-app').projectDir = new File('../node_modules/@capacitor/app/android')

include ':capacitor-browser'
project(':capacitor-browser').projectDir = new File('../node_modules/@capacitor/browser/android')

include ':capacitor-device'
project(':capacitor-device').projectDir = new File('../node_modules/@capacitor/device/android')

Expand Down
4 changes: 2 additions & 2 deletions ios/App/App/capacitor.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"packageClassList": [
"OAuth2ClientPlugin",
"AppPlugin",
"CAPBrowserPlugin",
"DevicePlugin",
"FilesystemPlugin",
"CAPNetworkPlugin",
"PreferencesPlugin",
"SharePlugin",
"SplashScreenPlugin",
"SendIntent",
"CDVPlugin"
"SendIntent"
]
}
9 changes: 0 additions & 9 deletions ios/App/App/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,5 @@
<widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<access origin="*" />

<feature name="Device">
<param name="ios-package" value="CDVDevice"/>
</feature>

<feature name="InAppBrowser">
<param name="ios-package" value="CDVWKInAppBrowser"/>
<param name="onload" value="true"/>
</feature>


</widget>
2 changes: 1 addition & 1 deletion ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def capacitor_pods
pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
pod 'ByteowlsCapacitorOauth2', :path => '../../node_modules/@byteowls/capacitor-oauth2'
pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app'
pod 'CapacitorBrowser', :path => '../../node_modules/@capacitor/browser'
pod 'CapacitorDevice', :path => '../../node_modules/@capacitor/device'
pod 'CapacitorFilesystem', :path => '../../node_modules/@capacitor/filesystem'
pod 'CapacitorNetwork', :path => '../../node_modules/@capacitor/network'
pod 'CapacitorPreferences', :path => '../../node_modules/@capacitor/preferences'
pod 'CapacitorShare', :path => '../../node_modules/@capacitor/share'
pod 'CapacitorSplashScreen', :path => '../../node_modules/@capacitor/splash-screen'
pod 'SendIntent', :path => '../../node_modules/send-intent'
pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'
end

target 'Floccus' do
Expand Down
51 changes: 10 additions & 41 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"@byteowls/capacitor-oauth2": "5.x",
"@capacitor/android": "6.x",
"@capacitor/app": "6.x",
"@capacitor/browser": "^6.0.1",
"@capacitor/core": "6.x",
"@capacitor/device": "6.x",
"@capacitor/filesystem": "6.x",
Expand All @@ -94,8 +95,6 @@
"batching-toposort": "^1.2.0",
"buffer": "^6.0.3",
"cheerio": "^1.0.0-rc.12",
"cordova-plugin-device": "^2.1.0",
"cordova-plugin-inappbrowser": "^5.0.0",
"core-js": "3.x",
"fast-xml-parser": "^4.2.7",
"humanize-duration": "^3.25.1",
Expand Down
5 changes: 0 additions & 5 deletions src/ui/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import '@mdi/font/css/materialdesignicons.css'
Vue.mixin(i18nPlugin)
Vue.mixin(capacitor)

document.addEventListener('deviceready', function() {
// eslint-disable-next-line no-undef
window.open = cordova.InAppBrowser.open
}, false)

const app = () => {
i18n.setLocales(navigator.languages)
i18n.load().then(() => {
Expand Down
9 changes: 4 additions & 5 deletions src/ui/store/native/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import Logger from '../../../lib/Logger'
import AdapterFactory from '../../../lib/AdapterFactory'
import Controller from '../../../lib/Controller'
import { i18n } from '../../../lib/native/I18n'
import { Capacitor, CapacitorHttp as Http } from '@capacitor/core'
import { CapacitorHttp as Http } from '@capacitor/core'
import { Share } from '@capacitor/share'
import Html from '../../../lib/serializers/Html'
import { Bookmark, Folder } from '../../../lib/Tree'
import { Browser } from '@capacitor/browser'

export const actionsDefinition = {
async [actions.LOAD_ACCOUNTS]({ commit, dispatch, state }) {
Expand Down Expand Up @@ -211,9 +212,7 @@ export const actionsDefinition = {
throw new Error(i18n.getMessage('LabelLoginFlowError'))
}
let json = res.data
// iOS browser doesn't allow 3rd party cookies, so we have to open a standalone browser
const target = Capacitor.getPlatform() === 'ios' ? '_system' : '_blank'
const browserWindow = await window.open(json.login, target, 'toolbar=no,presentationstyle=pagesheet')
await Browser.open({ url: json.login, presentationStyle: 'popover' })
do {
await new Promise(resolve => setTimeout(resolve, 1000))
try {
Expand All @@ -230,10 +229,10 @@ export const actionsDefinition = {
}
} while ((res.status === 404 || !res.data.appPassword) && state.loginFlow.isRunning)
commit(mutations.SET_LOGIN_FLOW_STATE, false)
await Browser.close()
if (res.status !== 200) {
throw new Error(i18n.getMessage('LabelLoginFlowError'))
}
browserWindow.close()
json = res.data
return {username: json.loginName, password: json.appPassword}
},
Expand Down

0 comments on commit f8ad240

Please sign in to comment.