Skip to content

Commit

Permalink
fixed back bug. fixed camera flipped bug.
Browse files Browse the repository at this point in the history
* back button works on android now.
  * haven't tested ios.
* camera flipped using capacitor by using html5 capture input.
  * ionic-team/pwa-elements#11 (comment)
  • Loading branch information
wraiford committed Feb 16, 2022
1 parent 2a1c585 commit bbc9f10
Show file tree
Hide file tree
Showing 14 changed files with 378 additions and 154 deletions.
12 changes: 7 additions & 5 deletions ionic-gib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
"sync:android": "ionic capacitor sync android",
"sync:ios": "ionic capacitor sync ios",

"man:ff:createprofiles": "echo 'creates test profiles for ff. each profile retains data between sessions. you can delete profiles in ff at url \"about:profiles\"'",
"ff:createprofiles": "/Applications/Firefox.app/Contents/MacOS/firefox -CreateProfile \"ibgibtest1\" && /Applications/Firefox.app/Contents/MacOS/firefox -CreateProfile \"ibgibtest2\" && /Applications/Firefox.app/Contents/MacOS/firefox -CreateProfile \"ibgibtest3\"",
"ff": "npm run ff:profile:1",
"man:ff": "echo 'ff starts firefox with web-ext. the numbers after are the test profiles, for simultaneous users. the \"none\" is no profile, which does not retain data between sessions.'",
"ff": "npm run ff:1",
"ff:chrome": "web-ext run -s './www' -t firefox-desktop -t chromium --firefox-profile=ibgibtest1 --keep-profile-changes --browser-console",
"ff:profile:none": "web-ext run -s './www' -t firefox-desktop --browser-console",
"ff:profile:1": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest1 --keep-profile-changes --browser-console",
"ff:profile:2": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest2 --keep-profile-changes --browser-console",
"ff:profile:3": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest3 --keep-profile-changes --browser-console",
"ff:none": "web-ext run -s './www' -t firefox-desktop --browser-console",
"ff:1": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest1 --keep-profile-changes --browser-console",
"ff:2": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest2 --keep-profile-changes --browser-console",
"ff:3": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest3 --keep-profile-changes --browser-console",
"chrome": "web-ext run -s './www' -t chromium --keep-profile-changes --browser-console",
"test": "ng test",
"lint": "ng lint",
Expand Down
12 changes: 11 additions & 1 deletion ionic-gib/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ export class AppComponent extends IbgibComponentBase
}

// navToAddr = this.tagsAddr;
this.platform.backButton.subscribeWithPriority(10, async () => {
if (this.common?.nav) { await this.common.nav.back(); }
});

} catch (error) {
console.error(`${lc} ${error.message}`);
console.error(`${lc} debug create here`);
Expand All @@ -204,9 +208,15 @@ export class AppComponent extends IbgibComponentBase
} finally {
this.initializing = false;
this.splashScreen.hide();
if (navToAddr) { await this.navTo({addr: navToAddr}); }
if (navToAddr) {
await this.go({
toAddr: navToAddr,
fromAddr: h.getIbGibAddr({ibGib: this.ibGib_Context}),
});
}
}
});

if (logalot) { console.log(`${lc} complete. waiting for platform.ready...`); }
}

Expand Down
8 changes: 8 additions & 0 deletions ionic-gib/src/app/common/action-bar/action-bar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
<ion-button *ngIf='item.type === "inputfile"' color="primary" shape="round"
(click)='inputyo.click()'>
<ion-icon slot="start" [name]="item.icon"></ion-icon>
<ion-spinner *ngIf="item.busy" name="circles" color="tertiary"></ion-spinner>
<input #inputyo type="file" hidden (change)='item.filepicked($event)'/>
</ion-button>

<ion-button *ngIf='item.type === "inputfile-camera"' color="primary" shape="round"
(click)='inputyo.click()'>
<ion-icon slot="start" [name]="item.icon"></ion-icon>
<ion-spinner *ngIf="item.busy" name="circles" color="tertiary"></ion-spinner>
<input #inputyo type="file" hidden (change)='item.filepicked($event)' accept="image/*" capture/>
</ion-button>

</div>
19 changes: 15 additions & 4 deletions ionic-gib/src/app/common/action-bar/action-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ export class ActionBarComponent extends IbgibComponentBase
},
{
name: 'camera',
type: 'button',
type: 'inputfile-camera',
text: 'camera',
icon: 'camera-outline',
handler: async (event) => await this.actionAddPic(event),
filepicked: async (event) => await this.actionAddImage(event),
// filepicked: async (event) => await this.handleHtml5PicButton(event),
},
{
name: 'file',
Expand Down Expand Up @@ -203,7 +204,10 @@ export class ActionBarComponent extends IbgibComponentBase
} else {
navToAddr = getIbGibAddr({ibGib: newComment});
}
await this.navTo({addr: navToAddr});
// await this.go({
// toAddr: navToAddr,
// fromAddr: h.getIbGibAddr({ibGib: this.ibGib_Context}),
// });

} catch (error) {
console.error(`${lc} ${error.message}`)
Expand Down Expand Up @@ -336,7 +340,10 @@ export class ActionBarComponent extends IbgibComponentBase
const navToAddr = this.isMeta ?
getIbGibAddr({ibGib: ibGibToRel8}) :
getIbGibAddr({ibGib: newContext});
await this.navTo({addr: navToAddr});
await this.go({
toAddr: navToAddr,
fromAddr: h.getIbGibAddr({ibGib: this.ibGib_Context}),
});
}
} catch (error) {
console.error(`${lc} ${error.message}`);
Expand Down Expand Up @@ -379,6 +386,10 @@ export class ActionBarComponent extends IbgibComponentBase
}
}

async handleHtml5PicButton(event: any): Promise<void> {
await this.actionAddImage(event);
}

async actionShowInfo(event: MouseEvent): Promise<void> {
const lc = `${this.lc}[${this.actionShowInfo.name}]`;
try {
Expand Down
43 changes: 32 additions & 11 deletions ionic-gib/src/app/common/bases/ibgib-component-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { IbGibAddr, Ib, Gib, V1, TransformResult } from "ts-gib";
import { Injectable } from "@angular/core";
// import { FilesService } from 'src/app/services/files.service';
import { IbgibItem, PicData, CommentData, LatestEventInfo } from '../types';
import { CommonService } from 'src/app/services/common.service';
import { CommonService, NavInfo } from 'src/app/services/common.service';
import { DEFAULT_META_IB_STARTS } from '../constants';
import { Subscription } from 'rxjs';
import * as h from 'ts-gib/dist/helper';
import * as c from '../../common/constants';
import { getGibInfo } from 'ts-gib/dist/V1/transforms/transform-helper';


const logalot = c.GLOBAL_LOG_A_LOT || false;
Expand Down Expand Up @@ -299,17 +300,37 @@ export abstract class IbgibComponentBase<TItem extends IbgibItem = IbgibItem>
}
}

async navTo({
addr,
queryParamsHandling = 'preserve',
async go({
toAddr,
fromAddr,
queryParams,
}: {
addr: string,
queryParamsHandling?: 'merge' | 'preserve',
queryParams?: { [key: string]: any },
}): Promise<void> {
if (logalot) { console.log(`navigating to addr: ${addr}`); }
this.common.nav.navTo({addr, queryParamsHandling, queryParams});
queryParamsHandling = 'preserve',
isModal,
}: NavInfo): Promise<void> {
let lc: string = '[invalid lc] (E: 9048c65ff92e4a08b840cf15d0a2867c)';
try {
lc = `${this.lc}[${this.go.name}(${toAddr || 'falsy'}) from (${fromAddr || 'falsy'})]`;
if (logalot) { console.log(`starting`); }

if (!toAddr) { throw new Error(`toAddr required. (E: 963988b52c9047a6bfd3adc87db8d99b)`); }
const toAddr_TjpGib = getGibInfo({ibGibAddr: toAddr}).tjpGib;

fromAddr = fromAddr ?? this.addr ?? undefined;
const fromAddr_TjpGib = this.addr ? getGibInfo({ibGibAddr: this.addr}).tjpGib : undefined;

await this.common.nav.go({
toAddr, toAddr_TjpGib,
fromAddr, fromAddr_TjpGib,
queryParamsHandling,
queryParams,
isModal,
});

console.log(`${lc} complete.`)
} catch (error) {
console.error(`${lc} ${error.message}`);
}

// await this.common.nav.navigateRoot(['ibgib', addr], {
// queryParamsHandling: 'preserve',
// animated: true,
Expand Down
1 change: 1 addition & 0 deletions ionic-gib/src/app/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ export const HEXADECIMAL_HASH_STRING_REGEXP_32 = /^[0-9a-fA-F]{32}$/;
*/
export const HEXADECIMAL_HASH_STRING_REGEXP_64 = /^[0-9a-fA-F]{64}$/;

export const QUERY_PARAM_PAUSED = 'paused';

// #region AWS Amazon

Expand Down
2 changes: 1 addition & 1 deletion ionic-gib/src/app/common/types/ux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const ActionItemName = {
}
export interface ActionItem {
name: ActionItemName;
type: 'button' | 'inputfile';
type: 'button' | 'inputfile' | 'inputfile-camera';
text: string;
icon: string;
handler?: (event: MouseEvent) => Promise<void>;
Expand Down
93 changes: 28 additions & 65 deletions ionic-gib/src/app/ibgib/ibgib.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import * as h from 'ts-gib';
import { IbGibAddr, } from 'ts-gib';
import { getIbGibAddr, pretty } from 'ts-gib/dist/helper';
import { IbGib_V1 } from 'ts-gib/dist/V1';
import { encrypt, decrypt, SaltStrategy } from 'encrypt-gib';

import * as c from '../common/constants';
import { IbgibComponentBase } from '../common/bases/ibgib-component-base';
import { CommonService } from '../services/common.service';
import { SPECIAL_URLS } from '../common/constants';
import { LatestEventInfo, } from '../common/types';
import * as c from '../common/constants';
import { IbgibFullscreenModalComponent } from '../common/ibgib-fullscreen-modal/ibgib-fullscreen-modal.component';
import { getFnAlert, } from '../common/helper';

Expand Down Expand Up @@ -60,63 +59,13 @@ export class IbGibPage extends IbgibComponentBase
async ngOnInit() {
const lc = `${this.lc}[${this.ngOnInit.name}]`;
if (logalot) { console.log(`${lc} called.`) }
// this.folder = this.activatedRoute.snapshot.paramMap.get('addr');
this.subscribeParamMap();
super.ngOnInit();

// await this.testEncryptGib();
}

async testEncryptGib(): Promise<void> {
const lc = `${this.lc}[${this.testEncryptGib.name}]`;
// debug test enc-gib
let initialData = 'here is some text';
// let hexString = await encGib.encodeStringToHexString(data);
// let data2 = await encGib.decodeHexStringToString(hexString);
// console.log(`${lc} data: ${data}`);
// console.log(`${lc} hexString: ${hexString}`);
// console.log(`${lc} data2: ${data2}`);
const salt = await h.getUUID();
const secret = `great p4SSw0rd?`;
let {encryptedData, errors} = await encrypt({
dataToEncrypt: initialData,
initialRecursions: 100,
recursionsPerHash: 10,
salt,
saltStrategy: SaltStrategy.appendPerHash,
secret,
confirm: true,
});

if (logalot) { console.log(`${lc} initialData: ${initialData}`); }
if (encryptedData) {
if (logalot) { console.log(`${lc} encryptedData: ${encryptedData}`); }

let { decryptedData, errors: errorsDecrypt } = await decrypt({
encryptedData,
initialRecursions: 100,
recursionsPerHash: 10,
salt,
saltStrategy: SaltStrategy.appendPerHash,
secret,
});

if (decryptedData) {
if (logalot) { console.log(`${lc} decryptedData: ${decryptedData}`); }
if (decryptedData === initialData) {
if (logalot) { console.log(`${lc} initialData equals decryptedData`); }
}
} else {
console.error(`${lc} decryptedData falsy!`);
}
} else if (errors?.length > 0) {
console.error(`${lc} errored!!! here they are...`);
for (let error in errors) { console.error(`${lc} ${error}`); }
console.error(`${lc} end of errors.`)
} else {
if (logalot) { console.log(`${lc} no encryptedData and no errors?`); }
try {
// this.folder = this.activatedRoute.snapshot.paramMap.get('addr');
this.subscribeParamMap();
super.ngOnInit();
} catch (error) {
console.error(`${lc} ${error.message}`);
}

}

ngOnDestroy() {
Expand Down Expand Up @@ -153,7 +102,7 @@ export class IbGibPage extends IbgibComponentBase
}

updatePaused(): void {
this.paused = (this.activatedRoute.snapshot.queryParams['paused'] || 'false') === 'true';
this.paused = (this.activatedRoute.snapshot.queryParams[c.QUERY_PARAM_PAUSED] || 'false') === 'true';
}

subscribeParamMap() {
Expand All @@ -175,10 +124,10 @@ export class IbGibPage extends IbgibComponentBase
}
} else {
// default special non-ibgib handler, go to the tags ibGib
if (logalot) { console.log(`${lc} special url entered, navTo to tags ibGib`); }
const tagsIbGib = await this.common.ibgibs.getSpecialIbgib({type: "tags"});
addr = getIbGibAddr({ibGib: tagsIbGib});
await this.navTo({addr});
let tagsAddr = getIbGibAddr({ibGib: tagsIbGib});
console.warn(`${lc} special url entered, so defaulting nav to tags ibGib (tagsAddr: ${tagsAddr}) (W: bcc8a669f4f44cbb837080615c3db51a)`);
await this.go({ toAddr: tagsAddr, fromAddr: this.addr });
}

});
Expand Down Expand Up @@ -292,7 +241,13 @@ export class IbGibPage extends IbgibComponentBase

if (this.paused) {
this.paused = false;
await this.navTo({addr: this.addr, queryParams: { paused: null }, queryParamsHandling: 'merge'})
await this.go({
toAddr: this.addr,
fromAddr: this.addr,
queryParams: { [c.QUERY_PARAM_PAUSED]: null },
queryParamsHandling: 'merge',
force: true,
});
}
if (this.item) { this.item.refreshing = true; }
await this.common.ibgibs.pingLatest_Local({ibGib: this.ibGib, tjp: this.tjp});
Expand All @@ -308,7 +263,12 @@ export class IbGibPage extends IbgibComponentBase
if (!this.tjp) { await this.loadTjp(); }

this.paused = true;
await this.navTo({addr: this.addr, queryParams: { paused: true }, queryParamsHandling: 'merge'})
await this.go({
toAddr: this.addr,
fromAddr: h.getIbGibAddr({ibGib: this.ibGib_Context}),
queryParams: { [c.QUERY_PARAM_PAUSED]: true },
queryParamsHandling: 'merge'
});
} catch (error) {
console.error(`${lc} ${error.message}`);
}
Expand All @@ -325,7 +285,10 @@ export class IbGibPage extends IbgibComponentBase
if (!this.tjpAddr) { await this.loadTjp(); }
if (info.tjpAddr !== this.tjpAddr) { return; }
if (this.addr !== info.latestAddr) {
await this.navTo({addr: info.latestAddr}); // hack
await this.go({
toAddr: info.latestAddr,
fromAddr: this.addr,
});
}
} catch (error) {
console.error(`${lc} ${error.message}`);
Expand Down
Loading

0 comments on commit bbc9f10

Please sign in to comment.